@optique/temporal 0.10.7 → 1.0.0-dev.1109

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 CHANGED
@@ -1,9 +1,6 @@
1
1
  @optique/temporal
2
2
  =================
3
3
 
4
- > [!WARNING]
5
- > The API is stabilizing, but may change before the 1.0 release.
6
-
7
4
  Value parsers for [`Temporal`] date/time types. This package provides
8
5
  `ValueParser` functions that can be used with *@optique/core* to parse
9
6
  command-line arguments into `Temporal` objects like [`Temporal.Instant`],
@@ -39,12 +36,15 @@ The following example uses the `plainDate()` value parser to accept a date in
39
36
 
40
37
  ~~~~ typescript
41
38
  import { run } from "@optique/run";
42
- import { option } from "@optique/core/parser";
39
+ import { object } from "@optique/core/constructs";
40
+ import { option } from "@optique/core/primitives";
43
41
  import { plainDate } from "@optique/temporal";
44
42
 
45
- const cli = run({
46
- birthday: option("--birthday", plainDate()),
47
- });
43
+ const cli = run(
44
+ object({
45
+ birthday: option("--birthday", plainDate()),
46
+ }),
47
+ );
48
48
 
49
49
  if (cli.birthday) {
50
50
  console.log(`Your next birthday is on ${cli.birthday.toLocaleString()}.`);
package/dist/index.cjs CHANGED
@@ -26,6 +26,9 @@ const __optique_core_message = __toESM(require("@optique/core/message"));
26
26
  const __optique_core_nonempty = __toESM(require("@optique/core/nonempty"));
27
27
 
28
28
  //#region src/index.ts
29
+ function ensureTemporal() {
30
+ if (typeof globalThis.Temporal === "undefined") throw new TypeError("Temporal API is not available. Use a runtime with Temporal support or install a polyfill like @js-temporal/polyfill.");
31
+ }
29
32
  /**
30
33
  * Creates a ValueParser for parsing Temporal.Instant from ISO 8601 strings.
31
34
  *
@@ -36,6 +39,8 @@ const __optique_core_nonempty = __toESM(require("@optique/core/nonempty"));
36
39
  *
37
40
  * @param options Configuration options for the instant parser.
38
41
  * @returns A ValueParser that parses strings into Temporal.Instant values.
42
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
43
+ * at runtime.
39
44
  */
40
45
  function instant(options = {}) {
41
46
  const metavar = options.metavar ?? "TIMESTAMP";
@@ -44,6 +49,7 @@ function instant(options = {}) {
44
49
  $mode: "sync",
45
50
  metavar,
46
51
  parse(input) {
52
+ ensureTemporal();
47
53
  try {
48
54
  const value = Temporal.Instant.from(input);
49
55
  return {
@@ -73,6 +79,8 @@ function instant(options = {}) {
73
79
  *
74
80
  * @param options Configuration options for the duration parser.
75
81
  * @returns A ValueParser that parses strings into Temporal.Duration values.
82
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
83
+ * at runtime.
76
84
  */
77
85
  function duration(options = {}) {
78
86
  const metavar = options.metavar ?? "DURATION";
@@ -81,6 +89,7 @@ function duration(options = {}) {
81
89
  $mode: "sync",
82
90
  metavar,
83
91
  parse(input) {
92
+ ensureTemporal();
84
93
  try {
85
94
  const value = Temporal.Duration.from(input);
86
95
  return {
@@ -109,6 +118,8 @@ function duration(options = {}) {
109
118
  *
110
119
  * @param options Configuration options for the zoned datetime parser.
111
120
  * @returns A ValueParser that parses strings into Temporal.ZonedDateTime values.
121
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
122
+ * at runtime.
112
123
  */
113
124
  function zonedDateTime(options = {}) {
114
125
  const metavar = options.metavar ?? "ZONED_DATETIME";
@@ -117,6 +128,7 @@ function zonedDateTime(options = {}) {
117
128
  $mode: "sync",
118
129
  metavar,
119
130
  parse(input) {
131
+ ensureTemporal();
120
132
  try {
121
133
  const value = Temporal.ZonedDateTime.from(input);
122
134
  return {
@@ -145,6 +157,8 @@ function zonedDateTime(options = {}) {
145
157
  *
146
158
  * @param options Configuration options for the plain date parser.
147
159
  * @returns A ValueParser that parses strings into Temporal.PlainDate values.
160
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
161
+ * at runtime.
148
162
  */
149
163
  function plainDate(options = {}) {
150
164
  const metavar = options.metavar ?? "DATE";
@@ -153,6 +167,7 @@ function plainDate(options = {}) {
153
167
  $mode: "sync",
154
168
  metavar,
155
169
  parse(input) {
170
+ ensureTemporal();
156
171
  try {
157
172
  const value = Temporal.PlainDate.from(input);
158
173
  return {
@@ -181,6 +196,8 @@ function plainDate(options = {}) {
181
196
  *
182
197
  * @param options Configuration options for the plain time parser.
183
198
  * @returns A ValueParser that parses strings into Temporal.PlainTime values.
199
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
200
+ * at runtime.
184
201
  */
185
202
  function plainTime(options = {}) {
186
203
  const metavar = options.metavar ?? "TIME";
@@ -189,6 +206,7 @@ function plainTime(options = {}) {
189
206
  $mode: "sync",
190
207
  metavar,
191
208
  parse(input) {
209
+ ensureTemporal();
192
210
  try {
193
211
  const value = Temporal.PlainTime.from(input);
194
212
  return {
@@ -217,6 +235,8 @@ function plainTime(options = {}) {
217
235
  *
218
236
  * @param options Configuration options for the plain datetime parser.
219
237
  * @returns A ValueParser that parses strings into Temporal.PlainDateTime values.
238
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
239
+ * at runtime.
220
240
  */
221
241
  function plainDateTime(options = {}) {
222
242
  const metavar = options.metavar ?? "DATETIME";
@@ -225,6 +245,7 @@ function plainDateTime(options = {}) {
225
245
  $mode: "sync",
226
246
  metavar,
227
247
  parse(input) {
248
+ ensureTemporal();
228
249
  try {
229
250
  const value = Temporal.PlainDateTime.from(input);
230
251
  return {
@@ -253,6 +274,8 @@ function plainDateTime(options = {}) {
253
274
  *
254
275
  * @param options Configuration options for the plain year-month parser.
255
276
  * @returns A ValueParser that parses strings into Temporal.PlainYearMonth values.
277
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
278
+ * at runtime.
256
279
  */
257
280
  function plainYearMonth(options = {}) {
258
281
  const metavar = options.metavar ?? "YEAR-MONTH";
@@ -261,6 +284,7 @@ function plainYearMonth(options = {}) {
261
284
  $mode: "sync",
262
285
  metavar,
263
286
  parse(input) {
287
+ ensureTemporal();
264
288
  try {
265
289
  const value = Temporal.PlainYearMonth.from(input);
266
290
  return {
@@ -289,6 +313,8 @@ function plainYearMonth(options = {}) {
289
313
  *
290
314
  * @param options Configuration options for the plain month-day parser.
291
315
  * @returns A ValueParser that parses strings into Temporal.PlainMonthDay values.
316
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
317
+ * at runtime.
292
318
  */
293
319
  function plainMonthDay(options = {}) {
294
320
  const metavar = options.metavar ?? "--MONTH-DAY";
@@ -297,6 +323,7 @@ function plainMonthDay(options = {}) {
297
323
  $mode: "sync",
298
324
  metavar,
299
325
  parse(input) {
326
+ ensureTemporal();
300
327
  try {
301
328
  const value = Temporal.PlainMonthDay.from(input);
302
329
  return {
@@ -316,6 +343,59 @@ function plainMonthDay(options = {}) {
316
343
  };
317
344
  }
318
345
  /**
346
+ * Single-segment IANA timezone identifiers accepted across all supported
347
+ * runtimes (Deno, Node.js, Bun). This tuple is the single source of truth:
348
+ * {@link SingleSegmentTimeZone} is derived from it, and the runtime lookup
349
+ * {@link singleSegmentTimeZoneLookup} is built from it.
350
+ */
351
+ const singleSegmentTimeZoneList = [
352
+ "UTC",
353
+ "GMT",
354
+ "GMT0",
355
+ "GMT+0",
356
+ "GMT-0",
357
+ "UCT",
358
+ "Universal",
359
+ "Greenwich",
360
+ "Zulu",
361
+ "EST",
362
+ "MST",
363
+ "HST",
364
+ "CET",
365
+ "MET",
366
+ "WET",
367
+ "EET",
368
+ "EST5EDT",
369
+ "CST6CDT",
370
+ "MST7MDT",
371
+ "PST8PDT",
372
+ "Cuba",
373
+ "Egypt",
374
+ "Eire",
375
+ "GB",
376
+ "GB-Eire",
377
+ "Hongkong",
378
+ "Iceland",
379
+ "Iran",
380
+ "Israel",
381
+ "Jamaica",
382
+ "Japan",
383
+ "Kwajalein",
384
+ "Libya",
385
+ "Navajo",
386
+ "NZ",
387
+ "NZ-CHAT",
388
+ "Poland",
389
+ "Portugal",
390
+ "PRC",
391
+ "ROC",
392
+ "ROK",
393
+ "Singapore",
394
+ "Turkey",
395
+ "W-SU"
396
+ ];
397
+ const singleSegmentTimeZoneLookup = new Map(singleSegmentTimeZoneList.map((timeZone$1) => [timeZone$1.toLowerCase(), timeZone$1]));
398
+ /**
319
399
  * Creates a ValueParser for parsing IANA Time Zone Database identifiers.
320
400
  *
321
401
  * Accepts strings like:
@@ -324,9 +404,13 @@ function plainMonthDay(options = {}) {
324
404
  * - `"America/New_York"`
325
405
  * - `"Europe/London"`
326
406
  * - `"UTC"`
407
+ * - `"GMT"`
408
+ * - `"EST"`
327
409
  *
328
410
  * @param options Configuration options for the timezone parser.
329
411
  * @returns A ValueParser that parses and validates timezone identifiers.
412
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
413
+ * at runtime.
330
414
  */
331
415
  function timeZone(options = {}) {
332
416
  const metavar = options.metavar ?? "TIMEZONE";
@@ -335,6 +419,7 @@ function timeZone(options = {}) {
335
419
  $mode: "sync",
336
420
  metavar,
337
421
  parse(input) {
422
+ ensureTemporal();
338
423
  try {
339
424
  Temporal.ZonedDateTime.from({
340
425
  year: 2020,
@@ -342,6 +427,14 @@ function timeZone(options = {}) {
342
427
  day: 1,
343
428
  timeZone: input
344
429
  });
430
+ if (!input.includes("/")) {
431
+ const canonical = singleSegmentTimeZoneLookup.get(input.toLowerCase());
432
+ if (canonical == null) throw new RangeError();
433
+ return {
434
+ success: true,
435
+ value: canonical
436
+ };
437
+ }
345
438
  return {
346
439
  success: true,
347
440
  value: input
package/dist/index.d.cts CHANGED
@@ -11,17 +11,21 @@ import { NonEmptyString } from "@optique/core/nonempty";
11
11
  * convention:
12
12
  *
13
13
  * - Two-level: `"Asia/Seoul"`, `"America/New_York"`, `"Europe/London"`
14
- * - Three-level: `"America/Argentina/Buenos_Aires"`, `"America/Kentucky/Louisville"`
15
- * - Special case: `"UTC"`
14
+ * - Three-level: `"America/Argentina/Buenos_Aires"`,
15
+ * `"America/Kentucky/Louisville"`
16
+ * - Standard single-segment: `"UTC"`, `"GMT"`, `"Universal"`
17
+ * - POSIX abbreviations: `"EST"`, `"CET"`, `"EST5EDT"`
18
+ * - Deprecated aliases: `"Japan"`, `"Singapore"`, `"Cuba"`
16
19
  *
17
20
  * @example
18
21
  * ```typescript
19
22
  * const seoul: TimeZone = "Asia/Seoul";
20
23
  * const utc: TimeZone = "UTC";
24
+ * const gmt: TimeZone = "GMT";
21
25
  * const buenosAires: TimeZone = "America/Argentina/Buenos_Aires";
22
26
  * ```
23
27
  */
24
- type TimeZone = `${string}/${string}/${string}` | `${string}/${string}` | "UTC";
28
+ type TimeZone = `${string}/${string}/${string}` | `${string}/${string}` | SingleSegmentTimeZone;
25
29
  /**
26
30
  * Options for creating an instant parser.
27
31
  */
@@ -248,6 +252,8 @@ interface TimeZoneOptions {
248
252
  *
249
253
  * @param options Configuration options for the instant parser.
250
254
  * @returns A ValueParser that parses strings into Temporal.Instant values.
255
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
256
+ * at runtime.
251
257
  */
252
258
  declare function instant(options?: InstantOptions): ValueParser<"sync", Temporal.Instant>;
253
259
  /**
@@ -261,6 +267,8 @@ declare function instant(options?: InstantOptions): ValueParser<"sync", Temporal
261
267
  *
262
268
  * @param options Configuration options for the duration parser.
263
269
  * @returns A ValueParser that parses strings into Temporal.Duration values.
270
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
271
+ * at runtime.
264
272
  */
265
273
  declare function duration(options?: DurationOptions): ValueParser<"sync", Temporal.Duration>;
266
274
  /**
@@ -273,6 +281,8 @@ declare function duration(options?: DurationOptions): ValueParser<"sync", Tempor
273
281
  *
274
282
  * @param options Configuration options for the zoned datetime parser.
275
283
  * @returns A ValueParser that parses strings into Temporal.ZonedDateTime values.
284
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
285
+ * at runtime.
276
286
  */
277
287
  declare function zonedDateTime(options?: ZonedDateTimeOptions): ValueParser<"sync", Temporal.ZonedDateTime>;
278
288
  /**
@@ -285,6 +295,8 @@ declare function zonedDateTime(options?: ZonedDateTimeOptions): ValueParser<"syn
285
295
  *
286
296
  * @param options Configuration options for the plain date parser.
287
297
  * @returns A ValueParser that parses strings into Temporal.PlainDate values.
298
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
299
+ * at runtime.
288
300
  */
289
301
  declare function plainDate(options?: PlainDateOptions): ValueParser<"sync", Temporal.PlainDate>;
290
302
  /**
@@ -297,6 +309,8 @@ declare function plainDate(options?: PlainDateOptions): ValueParser<"sync", Temp
297
309
  *
298
310
  * @param options Configuration options for the plain time parser.
299
311
  * @returns A ValueParser that parses strings into Temporal.PlainTime values.
312
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
313
+ * at runtime.
300
314
  */
301
315
  declare function plainTime(options?: PlainTimeOptions): ValueParser<"sync", Temporal.PlainTime>;
302
316
  /**
@@ -309,6 +323,8 @@ declare function plainTime(options?: PlainTimeOptions): ValueParser<"sync", Temp
309
323
  *
310
324
  * @param options Configuration options for the plain datetime parser.
311
325
  * @returns A ValueParser that parses strings into Temporal.PlainDateTime values.
326
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
327
+ * at runtime.
312
328
  */
313
329
  declare function plainDateTime(options?: PlainDateTimeOptions): ValueParser<"sync", Temporal.PlainDateTime>;
314
330
  /**
@@ -321,6 +337,8 @@ declare function plainDateTime(options?: PlainDateTimeOptions): ValueParser<"syn
321
337
  *
322
338
  * @param options Configuration options for the plain year-month parser.
323
339
  * @returns A ValueParser that parses strings into Temporal.PlainYearMonth values.
340
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
341
+ * at runtime.
324
342
  */
325
343
  declare function plainYearMonth(options?: PlainYearMonthOptions): ValueParser<"sync", Temporal.PlainYearMonth>;
326
344
  /**
@@ -333,8 +351,18 @@ declare function plainYearMonth(options?: PlainYearMonthOptions): ValueParser<"s
333
351
  *
334
352
  * @param options Configuration options for the plain month-day parser.
335
353
  * @returns A ValueParser that parses strings into Temporal.PlainMonthDay values.
354
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
355
+ * at runtime.
336
356
  */
337
357
  declare function plainMonthDay(options?: PlainMonthDayOptions): ValueParser<"sync", Temporal.PlainMonthDay>;
358
+ /**
359
+ * Single-segment IANA timezone identifiers accepted across all supported
360
+ * runtimes (Deno, Node.js, Bun). This tuple is the single source of truth:
361
+ * {@link SingleSegmentTimeZone} is derived from it, and the runtime lookup
362
+ * {@link singleSegmentTimeZoneLookup} is built from it.
363
+ */
364
+ declare const singleSegmentTimeZoneList: readonly ["UTC", "GMT", "GMT0", "GMT+0", "GMT-0", "UCT", "Universal", "Greenwich", "Zulu", "EST", "MST", "HST", "CET", "MET", "WET", "EET", "EST5EDT", "CST6CDT", "MST7MDT", "PST8PDT", "Cuba", "Egypt", "Eire", "GB", "GB-Eire", "Hongkong", "Iceland", "Iran", "Israel", "Jamaica", "Japan", "Kwajalein", "Libya", "Navajo", "NZ", "NZ-CHAT", "Poland", "Portugal", "PRC", "ROC", "ROK", "Singapore", "Turkey", "W-SU"];
365
+ type SingleSegmentTimeZone = typeof singleSegmentTimeZoneList[number];
338
366
  /**
339
367
  * Creates a ValueParser for parsing IANA Time Zone Database identifiers.
340
368
  *
@@ -344,9 +372,13 @@ declare function plainMonthDay(options?: PlainMonthDayOptions): ValueParser<"syn
344
372
  * - `"America/New_York"`
345
373
  * - `"Europe/London"`
346
374
  * - `"UTC"`
375
+ * - `"GMT"`
376
+ * - `"EST"`
347
377
  *
348
378
  * @param options Configuration options for the timezone parser.
349
379
  * @returns A ValueParser that parses and validates timezone identifiers.
380
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
381
+ * at runtime.
350
382
  */
351
383
  declare function timeZone(options?: TimeZoneOptions): ValueParser<"sync", TimeZone>;
352
384
  //#endregion
package/dist/index.d.ts CHANGED
@@ -12,17 +12,21 @@ import { ValueParser } from "@optique/core/valueparser";
12
12
  * convention:
13
13
  *
14
14
  * - Two-level: `"Asia/Seoul"`, `"America/New_York"`, `"Europe/London"`
15
- * - Three-level: `"America/Argentina/Buenos_Aires"`, `"America/Kentucky/Louisville"`
16
- * - Special case: `"UTC"`
15
+ * - Three-level: `"America/Argentina/Buenos_Aires"`,
16
+ * `"America/Kentucky/Louisville"`
17
+ * - Standard single-segment: `"UTC"`, `"GMT"`, `"Universal"`
18
+ * - POSIX abbreviations: `"EST"`, `"CET"`, `"EST5EDT"`
19
+ * - Deprecated aliases: `"Japan"`, `"Singapore"`, `"Cuba"`
17
20
  *
18
21
  * @example
19
22
  * ```typescript
20
23
  * const seoul: TimeZone = "Asia/Seoul";
21
24
  * const utc: TimeZone = "UTC";
25
+ * const gmt: TimeZone = "GMT";
22
26
  * const buenosAires: TimeZone = "America/Argentina/Buenos_Aires";
23
27
  * ```
24
28
  */
25
- type TimeZone = `${string}/${string}/${string}` | `${string}/${string}` | "UTC";
29
+ type TimeZone = `${string}/${string}/${string}` | `${string}/${string}` | SingleSegmentTimeZone;
26
30
  /**
27
31
  * Options for creating an instant parser.
28
32
  */
@@ -249,6 +253,8 @@ interface TimeZoneOptions {
249
253
  *
250
254
  * @param options Configuration options for the instant parser.
251
255
  * @returns A ValueParser that parses strings into Temporal.Instant values.
256
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
257
+ * at runtime.
252
258
  */
253
259
  declare function instant(options?: InstantOptions): ValueParser<"sync", Temporal.Instant>;
254
260
  /**
@@ -262,6 +268,8 @@ declare function instant(options?: InstantOptions): ValueParser<"sync", Temporal
262
268
  *
263
269
  * @param options Configuration options for the duration parser.
264
270
  * @returns A ValueParser that parses strings into Temporal.Duration values.
271
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
272
+ * at runtime.
265
273
  */
266
274
  declare function duration(options?: DurationOptions): ValueParser<"sync", Temporal.Duration>;
267
275
  /**
@@ -274,6 +282,8 @@ declare function duration(options?: DurationOptions): ValueParser<"sync", Tempor
274
282
  *
275
283
  * @param options Configuration options for the zoned datetime parser.
276
284
  * @returns A ValueParser that parses strings into Temporal.ZonedDateTime values.
285
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
286
+ * at runtime.
277
287
  */
278
288
  declare function zonedDateTime(options?: ZonedDateTimeOptions): ValueParser<"sync", Temporal.ZonedDateTime>;
279
289
  /**
@@ -286,6 +296,8 @@ declare function zonedDateTime(options?: ZonedDateTimeOptions): ValueParser<"syn
286
296
  *
287
297
  * @param options Configuration options for the plain date parser.
288
298
  * @returns A ValueParser that parses strings into Temporal.PlainDate values.
299
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
300
+ * at runtime.
289
301
  */
290
302
  declare function plainDate(options?: PlainDateOptions): ValueParser<"sync", Temporal.PlainDate>;
291
303
  /**
@@ -298,6 +310,8 @@ declare function plainDate(options?: PlainDateOptions): ValueParser<"sync", Temp
298
310
  *
299
311
  * @param options Configuration options for the plain time parser.
300
312
  * @returns A ValueParser that parses strings into Temporal.PlainTime values.
313
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
314
+ * at runtime.
301
315
  */
302
316
  declare function plainTime(options?: PlainTimeOptions): ValueParser<"sync", Temporal.PlainTime>;
303
317
  /**
@@ -310,6 +324,8 @@ declare function plainTime(options?: PlainTimeOptions): ValueParser<"sync", Temp
310
324
  *
311
325
  * @param options Configuration options for the plain datetime parser.
312
326
  * @returns A ValueParser that parses strings into Temporal.PlainDateTime values.
327
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
328
+ * at runtime.
313
329
  */
314
330
  declare function plainDateTime(options?: PlainDateTimeOptions): ValueParser<"sync", Temporal.PlainDateTime>;
315
331
  /**
@@ -322,6 +338,8 @@ declare function plainDateTime(options?: PlainDateTimeOptions): ValueParser<"syn
322
338
  *
323
339
  * @param options Configuration options for the plain year-month parser.
324
340
  * @returns A ValueParser that parses strings into Temporal.PlainYearMonth values.
341
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
342
+ * at runtime.
325
343
  */
326
344
  declare function plainYearMonth(options?: PlainYearMonthOptions): ValueParser<"sync", Temporal.PlainYearMonth>;
327
345
  /**
@@ -334,8 +352,18 @@ declare function plainYearMonth(options?: PlainYearMonthOptions): ValueParser<"s
334
352
  *
335
353
  * @param options Configuration options for the plain month-day parser.
336
354
  * @returns A ValueParser that parses strings into Temporal.PlainMonthDay values.
355
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
356
+ * at runtime.
337
357
  */
338
358
  declare function plainMonthDay(options?: PlainMonthDayOptions): ValueParser<"sync", Temporal.PlainMonthDay>;
359
+ /**
360
+ * Single-segment IANA timezone identifiers accepted across all supported
361
+ * runtimes (Deno, Node.js, Bun). This tuple is the single source of truth:
362
+ * {@link SingleSegmentTimeZone} is derived from it, and the runtime lookup
363
+ * {@link singleSegmentTimeZoneLookup} is built from it.
364
+ */
365
+ declare const singleSegmentTimeZoneList: readonly ["UTC", "GMT", "GMT0", "GMT+0", "GMT-0", "UCT", "Universal", "Greenwich", "Zulu", "EST", "MST", "HST", "CET", "MET", "WET", "EET", "EST5EDT", "CST6CDT", "MST7MDT", "PST8PDT", "Cuba", "Egypt", "Eire", "GB", "GB-Eire", "Hongkong", "Iceland", "Iran", "Israel", "Jamaica", "Japan", "Kwajalein", "Libya", "Navajo", "NZ", "NZ-CHAT", "Poland", "Portugal", "PRC", "ROC", "ROK", "Singapore", "Turkey", "W-SU"];
366
+ type SingleSegmentTimeZone = typeof singleSegmentTimeZoneList[number];
339
367
  /**
340
368
  * Creates a ValueParser for parsing IANA Time Zone Database identifiers.
341
369
  *
@@ -345,9 +373,13 @@ declare function plainMonthDay(options?: PlainMonthDayOptions): ValueParser<"syn
345
373
  * - `"America/New_York"`
346
374
  * - `"Europe/London"`
347
375
  * - `"UTC"`
376
+ * - `"GMT"`
377
+ * - `"EST"`
348
378
  *
349
379
  * @param options Configuration options for the timezone parser.
350
380
  * @returns A ValueParser that parses and validates timezone identifiers.
381
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
382
+ * at runtime.
351
383
  */
352
384
  declare function timeZone(options?: TimeZoneOptions): ValueParser<"sync", TimeZone>;
353
385
  //#endregion
package/dist/index.js CHANGED
@@ -3,6 +3,9 @@ import { message } from "@optique/core/message";
3
3
  import { ensureNonEmptyString } from "@optique/core/nonempty";
4
4
 
5
5
  //#region src/index.ts
6
+ function ensureTemporal() {
7
+ if (typeof globalThis.Temporal === "undefined") throw new TypeError("Temporal API is not available. Use a runtime with Temporal support or install a polyfill like @js-temporal/polyfill.");
8
+ }
6
9
  /**
7
10
  * Creates a ValueParser for parsing Temporal.Instant from ISO 8601 strings.
8
11
  *
@@ -13,6 +16,8 @@ import { ensureNonEmptyString } from "@optique/core/nonempty";
13
16
  *
14
17
  * @param options Configuration options for the instant parser.
15
18
  * @returns A ValueParser that parses strings into Temporal.Instant values.
19
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
20
+ * at runtime.
16
21
  */
17
22
  function instant(options = {}) {
18
23
  const metavar = options.metavar ?? "TIMESTAMP";
@@ -21,6 +26,7 @@ function instant(options = {}) {
21
26
  $mode: "sync",
22
27
  metavar,
23
28
  parse(input) {
29
+ ensureTemporal();
24
30
  try {
25
31
  const value = Temporal.Instant.from(input);
26
32
  return {
@@ -50,6 +56,8 @@ function instant(options = {}) {
50
56
  *
51
57
  * @param options Configuration options for the duration parser.
52
58
  * @returns A ValueParser that parses strings into Temporal.Duration values.
59
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
60
+ * at runtime.
53
61
  */
54
62
  function duration(options = {}) {
55
63
  const metavar = options.metavar ?? "DURATION";
@@ -58,6 +66,7 @@ function duration(options = {}) {
58
66
  $mode: "sync",
59
67
  metavar,
60
68
  parse(input) {
69
+ ensureTemporal();
61
70
  try {
62
71
  const value = Temporal.Duration.from(input);
63
72
  return {
@@ -86,6 +95,8 @@ function duration(options = {}) {
86
95
  *
87
96
  * @param options Configuration options for the zoned datetime parser.
88
97
  * @returns A ValueParser that parses strings into Temporal.ZonedDateTime values.
98
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
99
+ * at runtime.
89
100
  */
90
101
  function zonedDateTime(options = {}) {
91
102
  const metavar = options.metavar ?? "ZONED_DATETIME";
@@ -94,6 +105,7 @@ function zonedDateTime(options = {}) {
94
105
  $mode: "sync",
95
106
  metavar,
96
107
  parse(input) {
108
+ ensureTemporal();
97
109
  try {
98
110
  const value = Temporal.ZonedDateTime.from(input);
99
111
  return {
@@ -122,6 +134,8 @@ function zonedDateTime(options = {}) {
122
134
  *
123
135
  * @param options Configuration options for the plain date parser.
124
136
  * @returns A ValueParser that parses strings into Temporal.PlainDate values.
137
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
138
+ * at runtime.
125
139
  */
126
140
  function plainDate(options = {}) {
127
141
  const metavar = options.metavar ?? "DATE";
@@ -130,6 +144,7 @@ function plainDate(options = {}) {
130
144
  $mode: "sync",
131
145
  metavar,
132
146
  parse(input) {
147
+ ensureTemporal();
133
148
  try {
134
149
  const value = Temporal.PlainDate.from(input);
135
150
  return {
@@ -158,6 +173,8 @@ function plainDate(options = {}) {
158
173
  *
159
174
  * @param options Configuration options for the plain time parser.
160
175
  * @returns A ValueParser that parses strings into Temporal.PlainTime values.
176
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
177
+ * at runtime.
161
178
  */
162
179
  function plainTime(options = {}) {
163
180
  const metavar = options.metavar ?? "TIME";
@@ -166,6 +183,7 @@ function plainTime(options = {}) {
166
183
  $mode: "sync",
167
184
  metavar,
168
185
  parse(input) {
186
+ ensureTemporal();
169
187
  try {
170
188
  const value = Temporal.PlainTime.from(input);
171
189
  return {
@@ -194,6 +212,8 @@ function plainTime(options = {}) {
194
212
  *
195
213
  * @param options Configuration options for the plain datetime parser.
196
214
  * @returns A ValueParser that parses strings into Temporal.PlainDateTime values.
215
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
216
+ * at runtime.
197
217
  */
198
218
  function plainDateTime(options = {}) {
199
219
  const metavar = options.metavar ?? "DATETIME";
@@ -202,6 +222,7 @@ function plainDateTime(options = {}) {
202
222
  $mode: "sync",
203
223
  metavar,
204
224
  parse(input) {
225
+ ensureTemporal();
205
226
  try {
206
227
  const value = Temporal.PlainDateTime.from(input);
207
228
  return {
@@ -230,6 +251,8 @@ function plainDateTime(options = {}) {
230
251
  *
231
252
  * @param options Configuration options for the plain year-month parser.
232
253
  * @returns A ValueParser that parses strings into Temporal.PlainYearMonth values.
254
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
255
+ * at runtime.
233
256
  */
234
257
  function plainYearMonth(options = {}) {
235
258
  const metavar = options.metavar ?? "YEAR-MONTH";
@@ -238,6 +261,7 @@ function plainYearMonth(options = {}) {
238
261
  $mode: "sync",
239
262
  metavar,
240
263
  parse(input) {
264
+ ensureTemporal();
241
265
  try {
242
266
  const value = Temporal.PlainYearMonth.from(input);
243
267
  return {
@@ -266,6 +290,8 @@ function plainYearMonth(options = {}) {
266
290
  *
267
291
  * @param options Configuration options for the plain month-day parser.
268
292
  * @returns A ValueParser that parses strings into Temporal.PlainMonthDay values.
293
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
294
+ * at runtime.
269
295
  */
270
296
  function plainMonthDay(options = {}) {
271
297
  const metavar = options.metavar ?? "--MONTH-DAY";
@@ -274,6 +300,7 @@ function plainMonthDay(options = {}) {
274
300
  $mode: "sync",
275
301
  metavar,
276
302
  parse(input) {
303
+ ensureTemporal();
277
304
  try {
278
305
  const value = Temporal.PlainMonthDay.from(input);
279
306
  return {
@@ -293,6 +320,59 @@ function plainMonthDay(options = {}) {
293
320
  };
294
321
  }
295
322
  /**
323
+ * Single-segment IANA timezone identifiers accepted across all supported
324
+ * runtimes (Deno, Node.js, Bun). This tuple is the single source of truth:
325
+ * {@link SingleSegmentTimeZone} is derived from it, and the runtime lookup
326
+ * {@link singleSegmentTimeZoneLookup} is built from it.
327
+ */
328
+ const singleSegmentTimeZoneList = [
329
+ "UTC",
330
+ "GMT",
331
+ "GMT0",
332
+ "GMT+0",
333
+ "GMT-0",
334
+ "UCT",
335
+ "Universal",
336
+ "Greenwich",
337
+ "Zulu",
338
+ "EST",
339
+ "MST",
340
+ "HST",
341
+ "CET",
342
+ "MET",
343
+ "WET",
344
+ "EET",
345
+ "EST5EDT",
346
+ "CST6CDT",
347
+ "MST7MDT",
348
+ "PST8PDT",
349
+ "Cuba",
350
+ "Egypt",
351
+ "Eire",
352
+ "GB",
353
+ "GB-Eire",
354
+ "Hongkong",
355
+ "Iceland",
356
+ "Iran",
357
+ "Israel",
358
+ "Jamaica",
359
+ "Japan",
360
+ "Kwajalein",
361
+ "Libya",
362
+ "Navajo",
363
+ "NZ",
364
+ "NZ-CHAT",
365
+ "Poland",
366
+ "Portugal",
367
+ "PRC",
368
+ "ROC",
369
+ "ROK",
370
+ "Singapore",
371
+ "Turkey",
372
+ "W-SU"
373
+ ];
374
+ const singleSegmentTimeZoneLookup = new Map(singleSegmentTimeZoneList.map((timeZone$1) => [timeZone$1.toLowerCase(), timeZone$1]));
375
+ /**
296
376
  * Creates a ValueParser for parsing IANA Time Zone Database identifiers.
297
377
  *
298
378
  * Accepts strings like:
@@ -301,9 +381,13 @@ function plainMonthDay(options = {}) {
301
381
  * - `"America/New_York"`
302
382
  * - `"Europe/London"`
303
383
  * - `"UTC"`
384
+ * - `"GMT"`
385
+ * - `"EST"`
304
386
  *
305
387
  * @param options Configuration options for the timezone parser.
306
388
  * @returns A ValueParser that parses and validates timezone identifiers.
389
+ * @throws {TypeError} (from `parse()`) If the Temporal API is not available
390
+ * at runtime.
307
391
  */
308
392
  function timeZone(options = {}) {
309
393
  const metavar = options.metavar ?? "TIMEZONE";
@@ -312,6 +396,7 @@ function timeZone(options = {}) {
312
396
  $mode: "sync",
313
397
  metavar,
314
398
  parse(input) {
399
+ ensureTemporal();
315
400
  try {
316
401
  Temporal.ZonedDateTime.from({
317
402
  year: 2020,
@@ -319,6 +404,14 @@ function timeZone(options = {}) {
319
404
  day: 1,
320
405
  timeZone: input
321
406
  });
407
+ if (!input.includes("/")) {
408
+ const canonical = singleSegmentTimeZoneLookup.get(input.toLowerCase());
409
+ if (canonical == null) throw new RangeError();
410
+ return {
411
+ success: true,
412
+ value: canonical
413
+ };
414
+ }
322
415
  return {
323
416
  success: true,
324
417
  value: input
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/temporal",
3
- "version": "0.10.7",
3
+ "version": "1.0.0-dev.1109+fa132665",
4
4
  "description": "Temporal value parsers for Optique",
5
5
  "keywords": [
6
6
  "CLI",
@@ -56,7 +56,7 @@
56
56
  "sideEffects": false,
57
57
  "dependencies": {
58
58
  "@js-temporal/polyfill": "^0.5.1",
59
- "@optique/core": "0.10.7"
59
+ "@optique/core": "1.0.0-dev.1109+fa132665"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/node": "^20.19.9",