Licence
MIT
Version
1.1.1
Deps
2
Size
64 kB
Vulns
0
Weekly
5.9K
@optique/temporal
Value parsers for Temporal date/time types. This package provides
ValueParser functions that can be used with @optique/core to parse
command-line arguments into Temporal objects like Temporal.Instant,
Temporal.Duration, Temporal.ZonedDateTime, Temporal.PlainDate,
and more.
This package requires that the Temporal global object is available. You may
need to use a polyfill like @js-temporal/polyfill.
Installation
deno add jsr:@optique/temporal jsr:@optique/run jsr:@optique/core
npm add @optique/temporal @optique/run @optique/core
pnpm add @optique/temporal @optique/run @optique/core
yarn add @optique/temporal @optique/run @optique/coreQuick example
The following example uses the plainDate() value parser to accept a date in
YYYY-MM-DD format.
import { run } from "@optique/run";
import { object } from "@optique/core/constructs";
import { option } from "@optique/core/primitives";
import { plainDate } from "@optique/temporal";
const cli = run(
object({
birthday: option("--birthday", plainDate()),
}),
);
if (cli.birthday) {
console.log(`Your next birthday is on ${cli.birthday.toLocaleString()}.`);
}Run it:
$ node cli.js --birthday 2024-12-25
Your next birthday is on 12/25/2024.For more resources, see the docs and the examples directory.