@optique/temporal 0.4.0-dev.49 → 0.4.0-dev.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
@optique/temporal
|
|
2
|
+
================
|
|
3
|
+
|
|
4
|
+
> [!CAUTION]
|
|
5
|
+
> Optique is currently in early development and may change significantly.
|
|
6
|
+
> Expect breaking changes as we refine the API and features.
|
|
7
|
+
|
|
8
|
+
Value parsers for [`Temporal`] date/time types. This package provides
|
|
9
|
+
`ValueParser` functions that can be used with *@optique/core* to parse
|
|
10
|
+
command-line arguments into `Temporal` objects like [`Temporal.Instant`],
|
|
11
|
+
[`Temporal.Duration`], [`Temporal.ZonedDateTime`], [`Temporal.PlainDate`],
|
|
12
|
+
and more.
|
|
13
|
+
|
|
14
|
+
This package requires that the `Temporal` global object is available. You may
|
|
15
|
+
need to use a polyfill like `@js-temporal/polyfill`.
|
|
16
|
+
|
|
17
|
+
[`Temporal`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal
|
|
18
|
+
[`Temporal.Instant`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant
|
|
19
|
+
[`Temporal.Duration`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration
|
|
20
|
+
[`Temporal.ZonedDateTime`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime
|
|
21
|
+
[`Temporal.PlainDate`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Installation
|
|
25
|
+
------------
|
|
26
|
+
|
|
27
|
+
~~~~ bash
|
|
28
|
+
deno add jsr:@optique/temporal jsr:@optique/run jsr:@optique/core
|
|
29
|
+
npm add @optique/temporal @optique/run @optique/core
|
|
30
|
+
pnpm add @optique/temporal @optique/run @optique/core
|
|
31
|
+
yarn add @optique/temporal @optique/run @optique/core
|
|
32
|
+
~~~~
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
Quick example
|
|
36
|
+
-------------
|
|
37
|
+
|
|
38
|
+
The following example uses the `plainDate()` value parser to accept a date in
|
|
39
|
+
`YYYY-MM-DD` format.
|
|
40
|
+
|
|
41
|
+
~~~~ typescript
|
|
42
|
+
import { run } from "@optique/run";
|
|
43
|
+
import { option } from "@optique/core/parser";
|
|
44
|
+
import { plainDate } from "@optique/temporal";
|
|
45
|
+
|
|
46
|
+
const cli = run({
|
|
47
|
+
birthday: option("--birthday", plainDate()),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (cli.birthday) {
|
|
51
|
+
console.log(`Your next birthday is on ${cli.birthday.toLocaleString()}.`);
|
|
52
|
+
}
|
|
53
|
+
~~~~
|
|
54
|
+
|
|
55
|
+
Run it:
|
|
56
|
+
|
|
57
|
+
~~~~ bash
|
|
58
|
+
$ node cli.js --birthday 2024-12-25
|
|
59
|
+
Your next birthday is on 12/25/2024.
|
|
60
|
+
~~~~
|
|
61
|
+
|
|
62
|
+
For more resources, see the [docs] and the [*examples*](/examples/) directory.
|
|
63
|
+
|
|
64
|
+
[docs]: https://optique.dev/
|