Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2916246
real-world.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
real-world.js
View Options
import
{
printTable
}
from
'../formatter.js'
;
import
Ajv
from
'ajv'
;
import
Handlebars
from
'handlebars'
;
import
{
format
,
addDays
,
differenceInDays
,
formatDistance
}
from
'date-fns'
;
const
now
=
new
Date
(
'2026-02-27T12:00:00Z'
);
const
later
=
addDays
(
now
,
10
);
const
formatted
=
format
(
now
,
'yyyy-MM-dd'
);
const
distance
=
formatDistance
(
now
,
later
);
const
daysDiff
=
differenceInDays
(
later
,
now
);
const
ajv
=
new
Ajv
();
const
schema
=
{
type
:
'object'
,
properties
:
{
name
:
{
type
:
'string'
},
age
:
{
type
:
'integer'
,
minimum
:
0
}
},
required
:
[
'name'
,
'age'
]
};
const
validate
=
ajv
.
compile
(
schema
);
const
valid
=
validate
({
name
:
'alice'
,
age
:
30
});
const
invalid
=
validate
({
name
:
'bob'
,
age
:
-
1
});
const
template
=
Handlebars
.
compile
(
'Hello {{name}}, you have {{count}} messages'
);
const
rendered
=
template
({
name
:
'Alice'
,
count
:
5
});
const
rows
=
[
[
'Real world tools'
,
'output'
],
[
'date-fns format'
,
formatted
],
[
'date-fns addDays'
,
format
(
later
,
'yyyy-MM-dd'
)],
[
'date-fns distance'
,
distance
],
[
'date-fns diffDays'
,
daysDiff
],
[
'ajv valid'
,
valid
],
[
'ajv invalid'
,
`
${
invalid
}
—
${
validate
.
errors
?
.[
0
]
?
.
message
}
`
],
[
'handlebars'
,
rendered
]
];
printTable
(
rows
);
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Thu, Mar 26, 4:45 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
511959
Default Alt Text
real-world.js (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment