temporal-fmt 0.9.0 → 0.9.2

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.
Files changed (105) hide show
  1. package/dist/calendarUtils.cjs +4 -259
  2. package/dist/calendarUtils.cjs.map +1 -1
  3. package/dist/calendarUtils.js +1 -33
  4. package/dist/chunk-2JHEV7ZF.js +7 -0
  5. package/dist/chunk-2JHEV7ZF.js.map +1 -0
  6. package/dist/chunk-3MZLTVP3.js +2 -0
  7. package/dist/{chunk-MXXYIMFJ.js.map → chunk-3MZLTVP3.js.map} +1 -1
  8. package/dist/chunk-4JWGUR4O.js +11 -0
  9. package/dist/{chunk-AXQLUIDY.js.map → chunk-4JWGUR4O.js.map} +1 -1
  10. package/dist/chunk-5U5WJ465.js +36 -0
  11. package/dist/chunk-5U5WJ465.js.map +1 -0
  12. package/dist/chunk-C5YESWFT.js +2 -0
  13. package/dist/chunk-C5YESWFT.js.map +1 -0
  14. package/dist/chunk-C6ZZ62ET.js +2 -0
  15. package/dist/{chunk-YS52LOMJ.js.map → chunk-C6ZZ62ET.js.map} +1 -1
  16. package/dist/chunk-EHLRZULM.js +5 -0
  17. package/dist/{chunk-4ZBGVYLR.js.map → chunk-EHLRZULM.js.map} +1 -1
  18. package/dist/chunk-F4RGUDA3.js +2 -0
  19. package/dist/chunk-F4RGUDA3.js.map +1 -0
  20. package/dist/chunk-J2AQNXF2.js +2 -0
  21. package/dist/{chunk-GRJQHQLW.js.map → chunk-J2AQNXF2.js.map} +1 -1
  22. package/dist/chunk-NBXF7V5B.js +2 -0
  23. package/dist/chunk-NBXF7V5B.js.map +1 -0
  24. package/dist/chunk-R52YOKI3.js +7 -0
  25. package/dist/{chunk-M33NSC4E.js.map → chunk-R52YOKI3.js.map} +1 -1
  26. package/dist/chunk-UJR6DHXY.js +2 -0
  27. package/dist/chunk-UJR6DHXY.js.map +1 -0
  28. package/dist/chunk-VQXUMFB2.js +21 -0
  29. package/dist/{chunk-VHSZL3P3.js.map → chunk-VQXUMFB2.js.map} +1 -1
  30. package/dist/chunk-XH46JNPK.js +2 -0
  31. package/dist/chunk-XH46JNPK.js.map +1 -0
  32. package/dist/chunk-YB6YAG7E.js +35 -0
  33. package/dist/chunk-YB6YAG7E.js.map +1 -0
  34. package/dist/chunk-ZGMTY52O.js +2 -0
  35. package/dist/chunk-ZGMTY52O.js.map +1 -0
  36. package/dist/duration.cjs +9 -624
  37. package/dist/duration.cjs.map +1 -1
  38. package/dist/duration.js +1 -29
  39. package/dist/format.cjs +18 -769
  40. package/dist/format.cjs.map +1 -1
  41. package/dist/format.js +1 -20
  42. package/dist/formatDuration.d.cts +6 -0
  43. package/dist/formatDuration.d.ts +6 -0
  44. package/dist/index.cjs +146 -6672
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/index.js +58 -3004
  47. package/dist/index.js.map +1 -1
  48. package/dist/interval.cjs +18 -952
  49. package/dist/interval.cjs.map +1 -1
  50. package/dist/interval.js +1 -41
  51. package/dist/localeRegistry.cjs +15 -328
  52. package/dist/localeRegistry.cjs.map +1 -1
  53. package/dist/localeRegistry.js +1 -11
  54. package/dist/localeVocab.d.cts +3 -0
  55. package/dist/localeVocab.d.ts +3 -0
  56. package/dist/parse.cjs +53 -1637
  57. package/dist/parse.cjs.map +1 -1
  58. package/dist/parse.js +1 -20
  59. package/dist/parsePattern.d.cts +1 -0
  60. package/dist/parsePattern.d.ts +1 -0
  61. package/dist/pattern.d.cts +1 -0
  62. package/dist/pattern.d.ts +1 -0
  63. package/dist/recurrence.cjs +20 -450
  64. package/dist/recurrence.cjs.map +1 -1
  65. package/dist/recurrence.js +1 -20
  66. package/dist/relativeTime.cjs +24 -177
  67. package/dist/relativeTime.cjs.map +1 -1
  68. package/dist/relativeTime.js +1 -14
  69. package/dist/rounding.d.cts +1 -0
  70. package/dist/rounding.d.ts +1 -0
  71. package/dist/serialization.d.cts +1 -1
  72. package/dist/serialization.d.ts +1 -1
  73. package/dist/timezone.cjs +20 -387
  74. package/dist/timezone.cjs.map +1 -1
  75. package/dist/timezone.js +1 -26
  76. package/dist/typeGuards.d.cts +9 -9
  77. package/dist/typeGuards.d.ts +9 -9
  78. package/package.json +4 -2
  79. package/dist/chunk-4ZBGVYLR.js +0 -182
  80. package/dist/chunk-AXQLUIDY.js +0 -183
  81. package/dist/chunk-CKVHXFX7.js +0 -902
  82. package/dist/chunk-CKVHXFX7.js.map +0 -1
  83. package/dist/chunk-CSUIKL73.js +0 -215
  84. package/dist/chunk-CSUIKL73.js.map +0 -1
  85. package/dist/chunk-EDUFSRWJ.js +0 -9
  86. package/dist/chunk-EDUFSRWJ.js.map +0 -1
  87. package/dist/chunk-FQA4XJME.js +0 -57
  88. package/dist/chunk-FQA4XJME.js.map +0 -1
  89. package/dist/chunk-FTMLZ4EN.js +0 -196
  90. package/dist/chunk-FTMLZ4EN.js.map +0 -1
  91. package/dist/chunk-GRJQHQLW.js +0 -170
  92. package/dist/chunk-JCIMP43G.js +0 -602
  93. package/dist/chunk-JCIMP43G.js.map +0 -1
  94. package/dist/chunk-KDYK72Z2.js +0 -75
  95. package/dist/chunk-KDYK72Z2.js.map +0 -1
  96. package/dist/chunk-M33NSC4E.js +0 -169
  97. package/dist/chunk-MXXYIMFJ.js +0 -29
  98. package/dist/chunk-NFKQ3EXC.js +0 -188
  99. package/dist/chunk-NFKQ3EXC.js.map +0 -1
  100. package/dist/chunk-O6GVMBLW.js +0 -403
  101. package/dist/chunk-O6GVMBLW.js.map +0 -1
  102. package/dist/chunk-VHSZL3P3.js +0 -242
  103. package/dist/chunk-VSUCBUTC.js +0 -295
  104. package/dist/chunk-VSUCBUTC.js.map +0 -1
  105. package/dist/chunk-YS52LOMJ.js +0 -51
package/dist/interval.js CHANGED
@@ -1,42 +1,2 @@
1
- import {
2
- contains,
3
- difference,
4
- formatRange,
5
- formatRangeToParts,
6
- intersection,
7
- intersects,
8
- interval,
9
- isAfter,
10
- isBefore,
11
- mergeIntervals,
12
- overlaps,
13
- splitInterval,
14
- subtract,
15
- union
16
- } from "./chunk-FTMLZ4EN.js";
17
- import "./chunk-AXQLUIDY.js";
18
- import "./chunk-M33NSC4E.js";
19
- import "./chunk-VSUCBUTC.js";
20
- import "./chunk-EDUFSRWJ.js";
21
- import "./chunk-MXXYIMFJ.js";
22
- import "./chunk-O6GVMBLW.js";
23
- import "./chunk-NFKQ3EXC.js";
24
- import "./chunk-4ZBGVYLR.js";
25
- import "./chunk-YS52LOMJ.js";
26
- export {
27
- contains,
28
- difference,
29
- formatRange,
30
- formatRangeToParts,
31
- intersection,
32
- intersects,
33
- interval,
34
- isAfter,
35
- isBefore,
36
- mergeIntervals,
37
- overlaps,
38
- splitInterval,
39
- subtract,
40
- union
41
- };
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n}from"./chunk-F4RGUDA3.js";import"./chunk-4JWGUR4O.js";import"./chunk-R52YOKI3.js";import"./chunk-C5YESWFT.js";import"./chunk-3MZLTVP3.js";import"./chunk-5U5WJ465.js";import"./chunk-UJR6DHXY.js";import"./chunk-EHLRZULM.js";import"./chunk-C6ZZ62ET.js";export{b as contains,i as difference,m as formatRange,n as formatRangeToParts,g as intersection,d as intersects,a as interval,f as isAfter,e as isBefore,k as mergeIntervals,c as overlaps,l as splitInterval,j as subtract,h as union};
42
2
  //# sourceMappingURL=interval.js.map
@@ -1,75 +1,4 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/localeRegistry.ts
21
- var localeRegistry_exports = {};
22
- __export(localeRegistry_exports, {
23
- getLocale: () => getLocale,
24
- hasLocale: () => hasLocale,
25
- registerLocale: () => registerLocale
26
- });
27
- module.exports = __toCommonJS(localeRegistry_exports);
28
-
29
- // src/errors.ts
30
- var TemporalFmtError = class extends Error {
31
- code;
32
- input;
33
- format;
34
- token;
35
- position;
36
- expected;
37
- actual;
38
- reason;
39
- constructor(message, fields) {
40
- super(message);
41
- this.name = "TemporalFmtError";
42
- this.code = fields.code;
43
- this.input = fields.input;
44
- this.format = fields.format;
45
- this.token = fields.token;
46
- this.position = fields.position;
47
- this.expected = fields.expected;
48
- this.actual = fields.actual;
49
- this.reason = fields.reason;
50
- const capture = Error.captureStackTrace;
51
- if (typeof capture === "function") {
52
- capture(this, this.constructor);
53
- }
54
- }
55
- // Lets callers do `err.toJSON()` for logging. Plain `Error` doesn't
56
- // serialize its non-enumerable fields; this picks them up explicitly.
57
- toJSON() {
58
- return {
59
- name: this.name,
60
- message: this.message,
61
- code: this.code,
62
- input: this.input,
63
- format: this.format,
64
- token: this.token,
65
- position: this.position,
66
- expected: this.expected,
67
- actual: this.actual,
68
- reason: this.reason
69
- };
70
- }
71
- };
72
- /* c8 ignore start @preserve -- InvalidTimeError is part of the public
1
+ "use strict";var L=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var r in e)L(t,r,{get:e[r],enumerable:!0})},z=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of K(e))!q.call(t,n)&&n!==r&&L(t,n,{get:()=>e[n],enumerable:!(o=R(e,n))||o.enumerable});return t};var B=t=>z(L({},"__esModule",{value:!0}),t);var tt={};v(tt,{getLocale:()=>J,hasLocale:()=>Q,registerLocale:()=>W});module.exports=B(tt);var E=class extends Error{code;input;format;token;position;expected;actual;reason;constructor(e,r){super(e),this.name="TemporalFmtError",this.code=r.code,this.input=r.input,this.format=r.format,this.token=r.token,this.position=r.position,this.expected=r.expected,this.actual=r.actual,this.reason=r.reason;let o=Error.captureStackTrace;typeof o=="function"&&o(this,this.constructor)}toJSON(){return{name:this.name,message:this.message,code:this.code,input:this.input,format:this.format,token:this.token,position:this.position,expected:this.expected,actual:this.actual,reason:this.reason}}};/* c8 ignore start @preserve -- InvalidTimeError is part of the public
73
2
  error-class surface (exported from index.ts, code 'INVALID_TIME')
74
3
  but nothing in this package constructs one. Investigated wiring it
75
4
  in the same way InvalidTimeZoneError was just wired (see parse.ts's
@@ -81,9 +10,7 @@ var TemporalFmtError = class extends Error {
81
10
  is rejected as a plain shape mismatch before any semantic check
82
11
  could run. There's no live gap to hook this into without inventing a
83
12
  redundant check purely to give this class a body. Left unconstructed
84
- until the library actually has a real invalid-time case to report. */
85
- /* c8 ignore stop @preserve */
86
- /* c8 ignore start @preserve -- InvalidCalendarError is part of the
13
+ until the library actually has a real invalid-time case to report. *//* c8 ignore stop @preserve *//* c8 ignore start @preserve -- InvalidCalendarError is part of the
87
14
  public error-class surface (exported from index.ts, code
88
15
  'INVALID_CALENDAR') but nothing in this package constructs one.
89
16
  Checked for a wiring opportunity the same way InvalidTimeZoneError
@@ -93,257 +20,17 @@ var TemporalFmtError = class extends Error {
93
20
  of the locale string — it's never handed an arbitrary "calendar"
94
21
  value a caller could get wrong. There's no live input to reject.
95
22
  Left unconstructed until the library actually accepts a calendar
96
- parameter that could be invalid. */
97
- /* c8 ignore stop @preserve */
98
- var InvalidLocaleError = class extends TemporalFmtError {
99
- constructor(fields) {
100
- const { message, ...rest } = fields;
101
- super(
102
- message ?? `locale "${fields.actual ?? ""}" is not a valid BCP-47 tag${fields.reason ? `: ${fields.reason}` : ""}.`,
103
- { code: "INVALID_LOCALE", ...rest }
104
- );
105
- this.name = "InvalidLocaleError";
106
- }
107
- };
108
- /* c8 ignore start @preserve -- unreachable from the current test suite,
109
- see rationale above */
110
- /* c8 ignore stop @preserve */
111
-
112
- // src/localeVocab.ts
113
- var customVocabs = /* @__PURE__ */ new Map();
114
- var MAX_CUSTOM_VOCABS = 500;
115
- var MAX_LOCALE_TAG_LENGTH = 256;
116
- var MAX_VOCAB_ENTRY_LENGTH = 256;
117
- function assertValidVocab(vocab, locale) {
118
- const required = [
119
- { key: "monthLong", length: 12, label: "long month names" },
120
- { key: "monthShort", length: 12, label: "short month names" },
121
- { key: "weekdayLong", length: 7, label: "long weekday names" },
122
- { key: "weekdayShort", length: 7, label: "short weekday names" },
123
- { key: "dayPeriod", length: 2, label: "day period markers (AM/PM-equivalent)" }
124
- ];
125
- for (const { key, length, label } of required) {
126
- const value = vocab[key];
127
- if (value === void 0) {
128
- throw new Error(
129
- `temporal-fmt: registerLocaleVocab for locale "${locale}" is missing required field "${key}" (${label}).`
130
- );
131
- }
132
- if (!Array.isArray(value)) {
133
- throw new Error(
134
- `temporal-fmt: registerLocaleVocab for locale "${locale}": "${key}" must be an array, got ${typeof value}.`
135
- );
136
- }
137
- if (value.length !== length) {
138
- throw new Error(
139
- `temporal-fmt: registerLocaleVocab for locale "${locale}": "${key}" must have exactly ${length} entries (got ${value.length}) \u2014 ${label}.`
140
- );
141
- }
142
- value.forEach((entry, i) => {
143
- if (typeof entry !== "string" || entry.length === 0) {
144
- throw new Error(
145
- `temporal-fmt: registerLocaleVocab for locale "${locale}": "${key}[${i}]" must be a non-empty string, got ${String(entry)}.`
146
- );
147
- }
148
- if (entry.length > MAX_VOCAB_ENTRY_LENGTH) {
149
- throw new RangeError(
150
- `temporal-fmt: registerLocaleVocab for locale "${locale}": "${key}[${i}]" is too long (maximum ${MAX_VOCAB_ENTRY_LENGTH} characters).`
151
- );
152
- }
153
- });
154
- }
155
- assertNoCollision(vocab.monthLong, "MMMM month", locale);
156
- assertNoCollision(vocab.monthShort, "MMM month", locale);
157
- assertNoCollision(vocab.weekdayLong, "EEEE weekday", locale);
158
- assertNoCollision(vocab.weekdayShort, "EEE weekday", locale);
159
- if (vocab.dayPeriod[0] === vocab.dayPeriod[1]) {
160
- throw new Error(
161
- `temporal-fmt: registerLocaleVocab for locale "${locale}": dayPeriod entries must differ (both are "${vocab.dayPeriod[0]}"); otherwise parse() can't tell AM from PM.`
162
- );
163
- }
164
- }
165
- function registerLocaleVocab(locale, vocab) {
166
- if (typeof locale !== "string" || locale.length === 0) {
167
- throw new Error(`temporal-fmt: registerLocaleVocab requires a non-empty locale string, got ${String(locale)}.`);
168
- }
169
- if (locale.length > MAX_LOCALE_TAG_LENGTH) {
170
- throw new RangeError(`temporal-fmt: registerLocaleVocab locale is too long (maximum ${MAX_LOCALE_TAG_LENGTH} characters).`);
171
- }
172
- assertValidVocab(vocab, locale);
173
- const cacheKey = canonicalCacheKey(locale);
174
- if (!customVocabs.has(cacheKey) && customVocabs.size >= MAX_CUSTOM_VOCABS) {
175
- throw new RangeError(`temporal-fmt: registerLocaleVocab reached the ${MAX_CUSTOM_VOCABS}-locale limit.`);
176
- }
177
- customVocabs.set(cacheKey, {
178
- monthLong: [...vocab.monthLong],
179
- monthShort: [...vocab.monthShort],
180
- weekdayLong: [...vocab.weekdayLong],
181
- weekdayShort: [...vocab.weekdayShort],
182
- dayPeriod: [...vocab.dayPeriod]
183
- });
184
- vocabCache.delete(cacheKey);
185
- }
186
- function canonicalCacheKey(locale) {
187
- try {
188
- return new Intl.Locale(locale.replace(/_/g, "-")).toString().toLowerCase();
189
- } catch {
190
- return locale;
191
- }
192
- }
193
- var vocabCache = /* @__PURE__ */ new Map();
194
- var MAX_VOCAB_CACHE_SIZE = 500;
195
- function partValue(formatter, date, type) {
196
- const parts = formatter.formatToParts(date);
197
- const index = parts.findIndex((p) => p.type === type);
198
- /* c8 ignore start @preserve -- defensive guard against a real but
199
- unreproducible failure mode: an Intl implementation that omits the
200
- requested part type entirely for some locale. Checked every locale
201
- with unusual dayPeriod/weekday/month rendering available in this
202
- runtime's ICU data (ja-JP, zh-CN, th-TH, he-IL, ar-SA, ko-KR, fa-IR)
203
- against the exact formatter options getLocaleVocab uses (notably
204
- hour12: true for the dayPeriod formatter, which is what makes every
205
- locale here actually emit a dayPeriod part — omitting it is what
206
- produced a false "gap" during investigation). None omit their part
207
- on this runtime. A different ICU version or a non-Node Intl
208
- implementation could plausibly behave differently, so this stays a
209
- real check rather than an assertion. */
210
- /* c8 ignore start @preserve */
211
- if (index === -1) {
212
- throw new InvalidLocaleError({
213
- message: `temporal-fmt: locale produced no "${type}" part while building match vocabulary.`
214
- });
215
- }
216
- /* c8 ignore stop @preserve */
217
- let value = parts[index].value;
218
- const prev = parts[index - 1];
219
- const next = parts[index + 1];
220
- if (prev?.type === "literal" && !/\s/.test(prev.value)) value = prev.value + value;
221
- if (next?.type === "literal" && !/\s/.test(next.value)) value = value + next.value;
222
- return value;
223
- }
224
- function assertNoCollision(names, label, locale) {
225
- const seen = /* @__PURE__ */ new Map();
226
- for (let i = 0; i < names.length; i++) {
227
- const prior = seen.get(names[i]);
228
- if (prior !== void 0) {
229
- throw new Error(
230
- `temporal-fmt: locale "${locale}" renders ${label} index ${prior} and ${i} identically ("${names[i]}"). parse() can't reliably tell these apart for this locale/token, so this combination isn't supported.`
231
- );
232
- }
233
- seen.set(names[i], i);
234
- }
235
- }
236
- function getLocaleVocab(locale) {
237
- const cacheKey = canonicalCacheKey(locale);
238
- const custom = customVocabs.get(cacheKey);
239
- if (custom) {
240
- return custom;
241
- }
242
- const cached = vocabCache.get(cacheKey);
243
- if (cached) {
244
- return cached;
245
- }
246
- const monthLongFmt = new Intl.DateTimeFormat(locale, { month: "long", timeZone: "UTC" });
247
- const monthShortFmt = new Intl.DateTimeFormat(locale, { month: "short", timeZone: "UTC" });
248
- const monthLong = [];
249
- const monthShort = [];
250
- for (let m = 0; m < 12; m++) {
251
- const date = new Date(Date.UTC(2020, m, 1));
252
- monthLong.push(partValue(monthLongFmt, date, "month"));
253
- monthShort.push(partValue(monthShortFmt, date, "month"));
254
- }
255
- assertNoCollision(monthLong, "MMMM month", locale);
256
- assertNoCollision(monthShort, "MMM month", locale);
257
- const weekdayLongFmt = new Intl.DateTimeFormat(locale, { weekday: "long", timeZone: "UTC" });
258
- const weekdayShortFmt = new Intl.DateTimeFormat(locale, { weekday: "short", timeZone: "UTC" });
259
- const weekdayLong = [];
260
- const weekdayShort = [];
261
- for (let d = 0; d < 7; d++) {
262
- const date = new Date(Date.UTC(2024, 0, 1 + d));
263
- weekdayLong.push(partValue(weekdayLongFmt, date, "weekday"));
264
- weekdayShort.push(partValue(weekdayShortFmt, date, "weekday"));
265
- }
266
- assertNoCollision(weekdayLong, "EEEE weekday", locale);
267
- assertNoCollision(weekdayShort, "EEE weekday", locale);
268
- const dayPeriodFmt = new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: true, timeZone: "UTC" });
269
- const am = partValue(dayPeriodFmt, new Date(Date.UTC(2020, 0, 1, 1)), "dayPeriod");
270
- const pm = partValue(dayPeriodFmt, new Date(Date.UTC(2020, 0, 1, 13)), "dayPeriod");
271
- const dayPeriod = [.../* @__PURE__ */ new Set([am, pm])];
272
- const vocab = { monthLong, monthShort, weekdayLong, weekdayShort, dayPeriod };
273
- if (vocabCache.size >= MAX_VOCAB_CACHE_SIZE) {
274
- const oldestKey = vocabCache.keys().next().value;
275
- if (oldestKey !== void 0) vocabCache.delete(oldestKey);
276
- }
277
- vocabCache.set(cacheKey, vocab);
278
- return vocab;
279
- }
280
-
281
- // src/localeRegistry.ts
282
- var extendedVocabs = /* @__PURE__ */ new Map();
283
- var MAX_LOCALE_TAG_LENGTH2 = 256;
284
- var MAX_VOCAB_STRING_LENGTH = 256;
285
- function canonicalKey(locale) {
286
- try {
287
- return new Intl.Locale(locale.replace(/_/g, "-")).toString().toLowerCase();
288
- } catch {
289
- return locale;
290
- }
291
- }
292
- function registerLocale(locale, vocab) {
293
- if (typeof locale !== "string" || locale.length === 0) {
294
- throw new InvalidLocaleError({ actual: String(locale), reason: "locale string must be non-empty" });
295
- }
296
- if (locale.length > MAX_LOCALE_TAG_LENGTH2) {
297
- throw new InvalidLocaleError({ actual: String(locale.length), reason: `locale tag must be at most ${MAX_LOCALE_TAG_LENGTH2} characters` });
298
- }
299
- registerLocaleVocab(locale, vocab);
300
- validateExtended(vocab, locale);
301
- const key = canonicalKey(locale);
302
- extendedVocabs.set(key, { ...vocab });
303
- }
304
- function validateExtended(vocab, locale) {
305
- const checkArray = (val, key, length) => {
306
- if (val === void 0) return;
307
- if (!Array.isArray(val)) {
308
- throw new InvalidLocaleError({ actual: String(val), reason: `locale "${locale}": "${key}" must be an array` });
309
- }
310
- if (val.length !== length) {
311
- throw new InvalidLocaleError({ actual: String(val.length), reason: `locale "${locale}": "${key}" must have ${length} entries (got ${val.length})` });
312
- }
313
- for (let i = 0; i < val.length; i++) {
314
- if (typeof val[i] !== "string" || val[i].length === 0) {
315
- throw new InvalidLocaleError({ actual: String(val[i]), reason: `locale "${locale}": "${key}[${i}]" must be a non-empty string` });
316
- }
317
- if (val[i].length > MAX_VOCAB_STRING_LENGTH) {
318
- throw new InvalidLocaleError({ actual: String(val[i].length), reason: `locale "${locale}": "${key}[${i}]" must be at most ${MAX_VOCAB_STRING_LENGTH} characters` });
319
- }
320
- }
321
- };
322
- checkArray(vocab.quartersLong, "quartersLong", 4);
323
- checkArray(vocab.quartersShort, "quartersShort", 4);
324
- checkArray(vocab.erasLong, "erasLong", 2);
325
- checkArray(vocab.erasShort, "erasShort", 2);
326
- checkArray(vocab.ordinals, "ordinals", 4);
327
- }
328
- function getLocale(locale) {
329
- const key = canonicalKey(locale);
330
- const ext = extendedVocabs.get(key);
331
- if (ext) return ext;
332
- try {
333
- const base = getLocaleVocab(locale);
334
- return { ...base };
335
- } catch {
336
- return void 0;
337
- }
338
- }
339
- function hasLocale(locale) {
340
- const key = canonicalKey(locale);
341
- return extendedVocabs.has(key);
342
- }
343
- // Annotate the CommonJS export names for ESM import in node:
344
- 0 && (module.exports = {
345
- getLocale,
346
- hasLocale,
347
- registerLocale
348
- });
23
+ parameter that could be invalid. *//* c8 ignore stop @preserve */var c=class extends E{constructor(e){let{message:r,...o}=e;super(r??`locale "${e.actual??""}" is not a valid BCP-47 tag${e.reason?`: ${e.reason}`:""}.`,{code:"INVALID_LOCALE",...o}),this.name="InvalidLocaleError"}};/* c8 ignore start @preserve -- unreachable from the current test suite,
24
+ see rationale above *//* c8 ignore stop @preserve */var f=new Map,V=500,b=256,I=256;function G(t,e){let r=[{key:"monthLong",length:12,label:"long month names"},{key:"monthShort",length:12,label:"short month names"},{key:"weekdayLong",length:7,label:"long weekday names"},{key:"weekdayShort",length:7,label:"short weekday names"},{key:"dayPeriod",length:2,label:"day period markers (AM/PM-equivalent)"}];for(let{key:o,length:n,label:a}of r){let s=t[o];if(s===void 0)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${e}" is missing required field "${o}" (${a}).`);if(!Array.isArray(s))throw new Error(`temporal-fmt: registerLocaleVocab for locale "${e}": "${o}" must be an array, got ${typeof s}.`);if(s.length!==n)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${e}": "${o}" must have exactly ${n} entries (got ${s.length}) \u2014 ${a}.`);s.forEach((i,g)=>{if(typeof i!="string"||i.length===0)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${e}": "${o}[${g}]" must be a non-empty string, got ${String(i)}.`);if(i.length>I)throw new RangeError(`temporal-fmt: registerLocaleVocab for locale "${e}": "${o}[${g}]" is too long (maximum ${I} characters).`)})}if(u(t.monthLong,"MMMM month",e),u(t.monthShort,"MMM month",e),u(t.weekdayLong,"EEEE weekday",e),u(t.weekdayShort,"EEE weekday",e),t.dayPeriod[0]===t.dayPeriod[1])throw new Error(`temporal-fmt: registerLocaleVocab for locale "${e}": dayPeriod entries must differ (both are "${t.dayPeriod[0]}"); otherwise parse() can't tell AM from PM.`)}var X=[];function x(t,e){if(typeof t!="string"||t.length===0)throw new Error(`temporal-fmt: registerLocaleVocab requires a non-empty locale string, got ${String(t)}.`);if(t.length>b)throw new RangeError(`temporal-fmt: registerLocaleVocab locale is too long (maximum ${b} characters).`);G(e,t);let r=_(t);if(!f.has(r)&&f.size>=V)throw new RangeError(`temporal-fmt: registerLocaleVocab reached the ${V}-locale limit.`);f.set(r,{monthLong:[...e.monthLong],monthShort:[...e.monthShort],weekdayLong:[...e.weekdayLong],weekdayShort:[...e.weekdayShort],dayPeriod:[...e.dayPeriod]}),l.delete(r);for(let o of X)o()}function F(t){return t.replace(/_/g,"-")}var p=new Map,H=500;function _(t){let e=p.get(t);if(e!==void 0)return e;let r;try{r=new Intl.Locale(t.replace(/_/g,"-")).toString().toLowerCase()}catch{r=t}if(p.size>=H){let o=p.keys().next().value;o!==void 0&&p.delete(o)}return p.set(t,r),r}function Z(t){try{new Intl.Locale(F(t))}catch{throw new c({actual:t,reason:"not a valid BCP-47 locale tag"})}}var l=new Map,Y=500;function d(t,e,r){let o=t.formatToParts(e),n=o.findIndex(g=>g.type===r);/* c8 ignore start @preserve -- defensive guard against a real but
25
+ unreproducible failure mode: an Intl implementation that omits the
26
+ requested part type entirely for some locale. Checked every locale
27
+ with unusual dayPeriod/weekday/month rendering available in this
28
+ runtime's ICU data (ja-JP, zh-CN, th-TH, he-IL, ar-SA, ko-KR, fa-IR)
29
+ against the exact formatter options getLocaleVocab uses (notably
30
+ hour12: true for the dayPeriod formatter, which is what makes every
31
+ locale here actually emit a dayPeriod part — omitting it is what
32
+ produced a false "gap" during investigation). None omit their part
33
+ on this runtime. A different ICU version or a non-Node Intl
34
+ implementation could plausibly behave differently, so this stays a
35
+ real check rather than an assertion. *//* c8 ignore start @preserve */if(n===-1)throw new c({message:`temporal-fmt: locale produced no "${r}" part while building match vocabulary.`});/* c8 ignore stop @preserve */let a=o[n].value,s=o[n-1],i=o[n+1];return s?.type==="literal"&&!/\s/.test(s.value)&&(a=s.value+a),i?.type==="literal"&&!/\s/.test(i.value)&&(a=a+i.value),a}function u(t,e,r){let o=new Map;for(let n=0;n<t.length;n++){let a=o.get(t[n]);if(a!==void 0)throw new Error(`temporal-fmt: locale "${r}" renders ${e} index ${a} and ${n} identically ("${t[n]}"). parse() can't reliably tell these apart for this locale/token, so this combination isn't supported.`);o.set(t[n],n)}}function S(t){Z(t);let e=_(t),r=f.get(e);if(r)return r;let o=l.get(e);if(o)return o;let n=F(t),a=new Intl.DateTimeFormat(n,{month:"long",timeZone:"UTC"}),s=new Intl.DateTimeFormat(n,{month:"short",timeZone:"UTC"}),i=[],g=[];for(let m=0;m<12;m++){let h=new Date(Date.UTC(2020,m,1));i.push(d(a,h,"month")),g.push(d(s,h,"month"))}u(i,"MMMM month",t),u(g,"MMM month",t);let N=new Intl.DateTimeFormat(n,{weekday:"long",timeZone:"UTC"}),O=new Intl.DateTimeFormat(n,{weekday:"short",timeZone:"UTC"}),w=[],y=[];for(let m=0;m<7;m++){let h=new Date(Date.UTC(2024,0,1+m));w.push(d(N,h,"weekday")),y.push(d(O,h,"weekday"))}u(w,"EEEE weekday",t),u(y,"EEE weekday",t);let A=new Intl.DateTimeFormat(n,{hour:"numeric",hour12:!0,timeZone:"UTC"}),D=d(A,new Date(Date.UTC(2020,0,1,1)),"dayPeriod"),P=d(A,new Date(Date.UTC(2020,0,1,13)),"dayPeriod"),U=[...new Set([D,P])],k={monthLong:i,monthShort:g,weekdayLong:w,weekdayShort:y,dayPeriod:U};if(l.size>=Y){let m=l.keys().next().value;m!==void 0&&l.delete(m)}return l.set(e,k),k}var $=new Map,M=256,C=256;function T(t){try{return new Intl.Locale(t.replace(/_/g,"-")).toString().toLowerCase()}catch{return t}}function W(t,e){if(typeof t!="string"||t.length===0)throw new c({actual:String(t),reason:"locale string must be non-empty"});if(t.length>M)throw new c({actual:String(t.length),reason:`locale tag must be at most ${M} characters`});x(t,e),j(e,t);let r=T(t);$.set(r,{...e})}function j(t,e){let r=(o,n,a)=>{if(o!==void 0){if(!Array.isArray(o))throw new c({actual:String(o),reason:`locale "${e}": "${n}" must be an array`});if(o.length!==a)throw new c({actual:String(o.length),reason:`locale "${e}": "${n}" must have ${a} entries (got ${o.length})`});for(let s=0;s<o.length;s++){if(typeof o[s]!="string"||o[s].length===0)throw new c({actual:String(o[s]),reason:`locale "${e}": "${n}[${s}]" must be a non-empty string`});if(o[s].length>C)throw new c({actual:String(o[s].length),reason:`locale "${e}": "${n}[${s}]" must be at most ${C} characters`})}}};r(t.quartersLong,"quartersLong",4),r(t.quartersShort,"quartersShort",4),r(t.erasLong,"erasLong",2),r(t.erasShort,"erasShort",2),r(t.ordinals,"ordinals",4)}function J(t){let e=T(t),r=$.get(e);if(r)return r;try{return{...S(t)}}catch{return}}function Q(t){let e=T(t);return $.has(e)}0&&(module.exports={getLocale,hasLocale,registerLocale});
349
36
  //# sourceMappingURL=localeRegistry.cjs.map