temporal-fmt 0.9.2 → 0.9.4
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 +480 -9
- package/dist/calendarUtils.cjs +259 -4
- package/dist/calendarUtils.cjs.map +1 -1
- package/dist/calendarUtils.js +33 -1
- package/dist/chunk-4N3WCGEY.js +183 -0
- package/dist/{chunk-4JWGUR4O.js.map → chunk-4N3WCGEY.js.map} +1 -1
- package/dist/chunk-5UTV5VP6.js +984 -0
- package/dist/chunk-5UTV5VP6.js.map +1 -0
- package/dist/chunk-ACKKWH5Z.js +578 -0
- package/dist/{chunk-2JHEV7ZF.js.map → chunk-ACKKWH5Z.js.map} +1 -1
- package/dist/chunk-EGUUO6LE.js +439 -0
- package/dist/chunk-EGUUO6LE.js.map +1 -0
- package/dist/chunk-FBPHNRVW.js +2939 -0
- package/dist/chunk-FBPHNRVW.js.map +1 -0
- package/dist/chunk-GPB4JHGI.js +65 -0
- package/dist/chunk-GPB4JHGI.js.map +1 -0
- package/dist/chunk-H7YQX25T.js +170 -0
- package/dist/{chunk-J2AQNXF2.js.map → chunk-H7YQX25T.js.map} +1 -1
- package/dist/chunk-HXY2GUUM.js +182 -0
- package/dist/{chunk-EHLRZULM.js.map → chunk-HXY2GUUM.js.map} +1 -1
- package/dist/chunk-L24NPTAJ.js +328 -0
- package/dist/chunk-L24NPTAJ.js.map +1 -0
- package/dist/chunk-M3GDTHMT.js +169 -0
- package/dist/chunk-M3GDTHMT.js.map +1 -0
- package/dist/chunk-MKPDLQKD.js +51 -0
- package/dist/chunk-MKPDLQKD.js.map +1 -0
- package/dist/chunk-TSLPIURC.js +242 -0
- package/dist/{chunk-VQXUMFB2.js.map → chunk-TSLPIURC.js.map} +1 -1
- package/dist/chunk-UOPAV3WX.js +75 -0
- package/dist/chunk-UOPAV3WX.js.map +1 -0
- package/dist/chunk-VNIUIQA4.js +398 -0
- package/dist/chunk-VNIUIQA4.js.map +1 -0
- package/dist/chunk-YEUASGDK.js +9 -0
- package/dist/chunk-YEUASGDK.js.map +1 -0
- package/dist/chunk-ZQZF5EXW.js +29 -0
- package/dist/chunk-ZQZF5EXW.js.map +1 -0
- package/dist/config.d.cts +4 -2
- package/dist/config.d.ts +4 -2
- package/dist/duration.cjs +638 -26
- package/dist/duration.cjs.map +1 -1
- package/dist/duration.js +28 -1
- package/dist/format.cjs +833 -35
- package/dist/format.cjs.map +1 -1
- package/dist/format.js +20 -1
- package/dist/index.cjs +7698 -163
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +108 -24
- package/dist/index.d.ts +108 -24
- package/dist/index.js +1536 -58
- package/dist/index.js.map +1 -1
- package/dist/interval.cjs +5480 -35
- package/dist/interval.cjs.map +1 -1
- package/dist/interval.js +46 -1
- package/dist/localeRegistry.cjs +375 -32
- package/dist/localeRegistry.cjs.map +1 -1
- package/dist/localeRegistry.js +11 -1
- package/dist/modApi.d.cts +131 -0
- package/dist/modApi.d.ts +131 -0
- package/dist/parse.cjs +1797 -70
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.js +20 -1
- package/dist/pattern.d.cts +1 -0
- package/dist/pattern.d.ts +1 -0
- package/dist/recurrence.cjs +452 -20
- package/dist/recurrence.cjs.map +1 -1
- package/dist/recurrence.js +19 -1
- package/dist/relativeTime.cjs +268 -21
- package/dist/relativeTime.cjs.map +1 -1
- package/dist/relativeTime.js +14 -1
- package/dist/runtime.d.cts +201 -0
- package/dist/runtime.d.ts +201 -0
- package/dist/timezone.cjs +387 -20
- package/dist/timezone.cjs.map +1 -1
- package/dist/timezone.js +26 -1
- package/package.json +4 -6
- package/scripts/cli.mjs +27 -5
- package/dist/chunk-2JHEV7ZF.js +0 -7
- package/dist/chunk-3MZLTVP3.js +0 -2
- package/dist/chunk-3MZLTVP3.js.map +0 -1
- package/dist/chunk-4JWGUR4O.js +0 -11
- package/dist/chunk-5U5WJ465.js +0 -36
- package/dist/chunk-5U5WJ465.js.map +0 -1
- package/dist/chunk-C5YESWFT.js +0 -2
- package/dist/chunk-C5YESWFT.js.map +0 -1
- package/dist/chunk-C6ZZ62ET.js +0 -2
- package/dist/chunk-C6ZZ62ET.js.map +0 -1
- package/dist/chunk-EHLRZULM.js +0 -5
- package/dist/chunk-F4RGUDA3.js +0 -2
- package/dist/chunk-F4RGUDA3.js.map +0 -1
- package/dist/chunk-J2AQNXF2.js +0 -2
- package/dist/chunk-NBXF7V5B.js +0 -2
- package/dist/chunk-NBXF7V5B.js.map +0 -1
- package/dist/chunk-R52YOKI3.js +0 -7
- package/dist/chunk-R52YOKI3.js.map +0 -1
- package/dist/chunk-UJR6DHXY.js +0 -2
- package/dist/chunk-UJR6DHXY.js.map +0 -1
- package/dist/chunk-VQXUMFB2.js +0 -21
- package/dist/chunk-XH46JNPK.js +0 -2
- package/dist/chunk-XH46JNPK.js.map +0 -1
- package/dist/chunk-YB6YAG7E.js +0 -35
- package/dist/chunk-YB6YAG7E.js.map +0 -1
- package/dist/chunk-ZGMTY52O.js +0 -2
- package/dist/chunk-ZGMTY52O.js.map +0 -1
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getTemporal,
|
|
3
|
+
subscribeToTemporalChanges
|
|
4
|
+
} from "./chunk-ZQZF5EXW.js";
|
|
5
|
+
import {
|
|
6
|
+
InvalidLocaleError,
|
|
7
|
+
canonicalCacheKey,
|
|
8
|
+
getCustomVocab,
|
|
9
|
+
normalizeLocaleTag
|
|
10
|
+
} from "./chunk-EGUUO6LE.js";
|
|
11
|
+
import {
|
|
12
|
+
dayOfYear,
|
|
13
|
+
isoWeekYearAndWeek
|
|
14
|
+
} from "./chunk-MKPDLQKD.js";
|
|
15
|
+
|
|
16
|
+
// src/tokens.ts
|
|
17
|
+
function pad(n, len) {
|
|
18
|
+
const negative = n < 0;
|
|
19
|
+
const digits = String(Math.abs(n)).padStart(len, "0");
|
|
20
|
+
return negative ? "-" + digits : digits;
|
|
21
|
+
}
|
|
22
|
+
pad.fraction = function formatFraction(t, width) {
|
|
23
|
+
const nanoOfSecond = t.millisecond * 1e6 + (t.microsecond ?? 0) * 1e3 + (t.nanosecond ?? 0);
|
|
24
|
+
return pad(nanoOfSecond, 9).slice(0, width);
|
|
25
|
+
};
|
|
26
|
+
var DEFAULT_LOCALE = "en-US";
|
|
27
|
+
var formatterCache = /* @__PURE__ */ new Map();
|
|
28
|
+
var MAX_CACHE_SIZE = 500;
|
|
29
|
+
function getFormatter(locale, options) {
|
|
30
|
+
const key = JSON.stringify([canonicalCacheKey(locale), options]);
|
|
31
|
+
let formatter = formatterCache.get(key);
|
|
32
|
+
if (formatter) {
|
|
33
|
+
return formatter;
|
|
34
|
+
}
|
|
35
|
+
if (formatterCache.size >= MAX_CACHE_SIZE) {
|
|
36
|
+
const oldestKey = formatterCache.keys().next().value;
|
|
37
|
+
if (oldestKey !== void 0) formatterCache.delete(oldestKey);
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
formatter = new Intl.DateTimeFormat(normalizeLocaleTag(locale), options);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
throw new InvalidLocaleError({ actual: locale, reason: err.message });
|
|
43
|
+
}
|
|
44
|
+
formatterCache.set(key, formatter);
|
|
45
|
+
return formatter;
|
|
46
|
+
}
|
|
47
|
+
var nativeSupport;
|
|
48
|
+
subscribeToTemporalChanges(() => {
|
|
49
|
+
nativeSupport = void 0;
|
|
50
|
+
});
|
|
51
|
+
function intlSupportsNativeTemporal() {
|
|
52
|
+
if (nativeSupport === void 0) {
|
|
53
|
+
nativeSupport = false;
|
|
54
|
+
try {
|
|
55
|
+
const temporal = getTemporal();
|
|
56
|
+
new Intl.DateTimeFormat("en-US", { day: "numeric" }).formatToParts(temporal.PlainDate.from({ year: 1970, month: 1, day: 1 }));
|
|
57
|
+
nativeSupport = true;
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return nativeSupport;
|
|
62
|
+
}
|
|
63
|
+
function intlPart(temporal, locale, options, partType) {
|
|
64
|
+
const calendar = temporal?.calendarId;
|
|
65
|
+
const formatterOptions = {
|
|
66
|
+
...options,
|
|
67
|
+
calendar: calendar && calendar !== "iso8601" ? calendar : "gregory"
|
|
68
|
+
};
|
|
69
|
+
const ls = temporal.toLocaleString;
|
|
70
|
+
if (typeof ls !== "function" || ls === Object.prototype.toLocaleString) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`temporal-fmt: locale-aware part "${partType}" needs a value that implements toLocaleString (a real Temporal object). A plain field bag cannot render locale-aware names \u2014 pass a Temporal.PlainDate/PlainDateTime/ZonedDateTime.`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (!intlSupportsNativeTemporal()) {
|
|
76
|
+
try {
|
|
77
|
+
return ls.call(temporal, normalizeLocaleTag(locale), formatterOptions);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
if (err instanceof RangeError) {
|
|
80
|
+
throw new InvalidLocaleError({ actual: locale, reason: err.message });
|
|
81
|
+
}
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const { toInstant, timeZoneId } = temporal;
|
|
86
|
+
const isZoned = typeof toInstant === "function" && typeof timeZoneId === "string";
|
|
87
|
+
const intlSafeTemporal = isZoned ? temporal.toInstant() : temporal;
|
|
88
|
+
const nativeOptions = {
|
|
89
|
+
...formatterOptions,
|
|
90
|
+
...isZoned ? { timeZone: timeZoneId } : {}
|
|
91
|
+
};
|
|
92
|
+
const formatter = getFormatter(locale, nativeOptions);
|
|
93
|
+
const parts = formatter.formatToParts(intlSafeTemporal);
|
|
94
|
+
const index = parts.findIndex((p) => p.type === partType);
|
|
95
|
+
if (index === -1) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`temporal-fmt: locale "${locale}" produced no "${partType}" part for this token. This usually means the Temporal object is missing the field the token needs.`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
let value = parts[index].value;
|
|
101
|
+
const prev = parts[index - 1];
|
|
102
|
+
const next = parts[index + 1];
|
|
103
|
+
if (prev?.type === "literal" && !/\s/.test(prev.value)) value = prev.value + value;
|
|
104
|
+
if (next?.type === "literal" && !/\s/.test(next.value)) value = value + next.value;
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
function dayPeriodPart(hour, locale) {
|
|
108
|
+
const custom = getCustomVocab(locale);
|
|
109
|
+
if (custom) {
|
|
110
|
+
return hour < 12 ? custom.dayPeriod[0] : custom.dayPeriod[1];
|
|
111
|
+
}
|
|
112
|
+
const date = new Date(Date.UTC(1970, 0, 1, hour));
|
|
113
|
+
const formatter = getFormatter(locale, { hour: "numeric", hour12: true, timeZone: "UTC" });
|
|
114
|
+
const part = formatter.formatToParts(date).find((p) => p.type === "dayPeriod");
|
|
115
|
+
if (!part) {
|
|
116
|
+
throw new Error(`temporal-fmt: locale "${locale}" produced no "dayPeriod" part for token "a".`);
|
|
117
|
+
}
|
|
118
|
+
return part.value;
|
|
119
|
+
}
|
|
120
|
+
function localeAwareName(temporal, locale, options, partType, customArray, customIndex) {
|
|
121
|
+
if (customArray && customIndex !== void 0 && customIndex >= 0 && customIndex < customArray.length) {
|
|
122
|
+
return customArray[customIndex];
|
|
123
|
+
}
|
|
124
|
+
return intlPart(temporal, locale, options, partType);
|
|
125
|
+
}
|
|
126
|
+
function formatOffset(offset, variant) {
|
|
127
|
+
if (offset === "+00:00" && (variant === "X" || variant === "XX" || variant === "XXX")) {
|
|
128
|
+
return "Z";
|
|
129
|
+
}
|
|
130
|
+
if (offset.length > 6) {
|
|
131
|
+
if (variant === "xxx") {
|
|
132
|
+
return offset;
|
|
133
|
+
}
|
|
134
|
+
throw new Error(
|
|
135
|
+
`temporal-fmt: token "${variant}" cannot represent the offset "${offset}", which has a seconds component. None of the X/XX/XXX/x/xx tokens support offset seconds; use "xxx" instead, which formats the full offset unchanged.`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const sign = offset[0];
|
|
139
|
+
const hours = offset.slice(1, 3);
|
|
140
|
+
const minutes = offset.slice(4, 6);
|
|
141
|
+
switch (variant) {
|
|
142
|
+
case "X":
|
|
143
|
+
case "x":
|
|
144
|
+
return minutes === "00" ? `${sign}${hours}` : `${sign}${hours}${minutes}`;
|
|
145
|
+
case "XX":
|
|
146
|
+
case "xx":
|
|
147
|
+
return `${sign}${hours}${minutes}`;
|
|
148
|
+
case "XXX":
|
|
149
|
+
case "xxx":
|
|
150
|
+
return `${sign}${hours}:${minutes}`;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
var TOKENS = [
|
|
154
|
+
["yyyy", (t) => pad(t.year, 4), "year"],
|
|
155
|
+
["yy", (t) => {
|
|
156
|
+
if (t.year < 0) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`temporal-fmt: token "yy" doesn't support negative years (got ${t.year}), since truncating to 2 digits would make it indistinguishable from a positive year. Use "yyyy" instead.`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
return pad(t.year % 100, 2);
|
|
162
|
+
}, "year"],
|
|
163
|
+
// Unpadded year — no minimum width, unlike yyyy's fixed 4 digits.
|
|
164
|
+
// pad(n, 0) still does the right thing here: Math.abs(n) with no
|
|
165
|
+
// padStart floor just yields the plain digit string, and the sign
|
|
166
|
+
// handling (split off before padding) already covers negative years,
|
|
167
|
+
// so this doesn't need its own sign branch the way "yy" does.
|
|
168
|
+
["y", (t) => pad(t.year, 0), "year"],
|
|
169
|
+
["MMMM", (t, locale) => {
|
|
170
|
+
const custom = getCustomVocab(locale);
|
|
171
|
+
return localeAwareName(t, locale, { month: "long" }, "month", custom?.monthLong, t.month - 1);
|
|
172
|
+
}, "month"],
|
|
173
|
+
["MMM", (t, locale) => {
|
|
174
|
+
const custom = getCustomVocab(locale);
|
|
175
|
+
return localeAwareName(t, locale, { month: "short" }, "month", custom?.monthShort, t.month - 1);
|
|
176
|
+
}, "month"],
|
|
177
|
+
["MM", (t) => pad(t.month, 2), "month"],
|
|
178
|
+
["M", (t) => String(t.month), "month"],
|
|
179
|
+
["dd", (t) => pad(t.day, 2), "day"],
|
|
180
|
+
["d", (t) => String(t.day), "day"],
|
|
181
|
+
["EEEE", (t, locale) => {
|
|
182
|
+
const custom = getCustomVocab(locale);
|
|
183
|
+
return localeAwareName(t, locale, { weekday: "long" }, "weekday", custom?.weekdayLong, t.dayOfWeek - 1);
|
|
184
|
+
}, "dayOfWeek"],
|
|
185
|
+
["EEE", (t, locale) => {
|
|
186
|
+
const custom = getCustomVocab(locale);
|
|
187
|
+
return localeAwareName(t, locale, { weekday: "short" }, "weekday", custom?.weekdayShort, t.dayOfWeek - 1);
|
|
188
|
+
}, "dayOfWeek"],
|
|
189
|
+
["HH", (t) => pad(t.hour, 2), "hour"],
|
|
190
|
+
["H", (t) => String(t.hour), "hour"],
|
|
191
|
+
["hh", (t) => pad(t.hour % 12 || 12, 2), "hour"],
|
|
192
|
+
["h", (t) => String(t.hour % 12 || 12), "hour"],
|
|
193
|
+
["mm", (t) => pad(t.minute, 2), "minute"],
|
|
194
|
+
["m", (t) => String(t.minute), "minute"],
|
|
195
|
+
["ss", (t) => pad(t.second, 2), "second"],
|
|
196
|
+
["s", (t) => String(t.second), "second"],
|
|
197
|
+
// Fractional-second tokens, S through SSSSSSSSS (1-9 digits). Each token
|
|
198
|
+
// formats a slice of the same underlying nanosecond-of-second value —
|
|
199
|
+
// combining millisecond/microsecond/nanosecond into one 9-digit number
|
|
200
|
+
// and truncating to the token's width — so "SSS" keeps meaning exactly
|
|
201
|
+
// what it always meant (3-digit milliseconds) while wider tokens expose
|
|
202
|
+
// the precision Temporal actually carries. formatFraction below is the
|
|
203
|
+
// shared implementation; see its comment for the truncate-not-round
|
|
204
|
+
// rule and why.
|
|
205
|
+
["SSSSSSSSS", (t) => pad.fraction(t, 9), "millisecond"],
|
|
206
|
+
["SSSSSSSS", (t) => pad.fraction(t, 8), "millisecond"],
|
|
207
|
+
["SSSSSSS", (t) => pad.fraction(t, 7), "millisecond"],
|
|
208
|
+
["SSSSSS", (t) => pad.fraction(t, 6), "millisecond"],
|
|
209
|
+
["SSSSS", (t) => pad.fraction(t, 5), "millisecond"],
|
|
210
|
+
["SSSS", (t) => pad.fraction(t, 4), "millisecond"],
|
|
211
|
+
["SSS", (t) => pad.fraction(t, 3), "millisecond"],
|
|
212
|
+
["SS", (t) => pad.fraction(t, 2), "millisecond"],
|
|
213
|
+
["S", (t) => pad.fraction(t, 1), "millisecond"],
|
|
214
|
+
// dayPeriod text is locale-specific (AM/PM in en-US, م/ص in ar-EG) but
|
|
215
|
+
// still needs .hour on the input to compute which period it is
|
|
216
|
+
["a", (t, locale) => dayPeriodPart(t.hour, locale), "hour"],
|
|
217
|
+
["zzz", (t) => t.timeZoneId, "timeZoneId"],
|
|
218
|
+
// Numeric UTC offset tokens (date-fns/Unicode-LDML family). Only
|
|
219
|
+
// ZonedDateTime carries an offset, so the field check in format() throws
|
|
220
|
+
// the same "requires offset, which this Temporal object doesn't have"
|
|
221
|
+
// error zzz throws on PlainDate/PlainTime/PlainDateTime — same
|
|
222
|
+
// validation path, just a different field name. See formatOffset above
|
|
223
|
+
// for the per-variant width and Z/numeric distinction.
|
|
224
|
+
["xxx", (t) => formatOffset(t.offset, "xxx"), "offset"],
|
|
225
|
+
["xx", (t) => formatOffset(t.offset, "xx"), "offset"],
|
|
226
|
+
["X", (t) => formatOffset(t.offset, "X"), "offset"],
|
|
227
|
+
["XX", (t) => formatOffset(t.offset, "XX"), "offset"],
|
|
228
|
+
["XXX", (t) => formatOffset(t.offset, "XXX"), "offset"],
|
|
229
|
+
["x", (t) => formatOffset(t.offset, "x"), "offset"],
|
|
230
|
+
// Ordinal day (1st, 2nd, 3rd, ... 21st). English suffix rules only —
|
|
231
|
+
// locale-aware ordinals ("2." in de-DE, "2日" in ja-JP) are out of scope,
|
|
232
|
+
// since the rest of this library routes locale-specific names through
|
|
233
|
+
// Intl.DateTimeFormat, and Intl has no part type for ordinals. Format-only:
|
|
234
|
+
// the suffix isn't structurally distinguishable from a literal in a parse
|
|
235
|
+
// context (a "st"/"nd"/"rd"/"th" suffix isn't a digit and would collide
|
|
236
|
+
// with any adjacent literal text), so there's no good way to read it back.
|
|
237
|
+
["do", (t) => {
|
|
238
|
+
const day = t.day;
|
|
239
|
+
const lastDigit = day % 10;
|
|
240
|
+
const lastTwoDigits = day % 100;
|
|
241
|
+
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
|
|
242
|
+
return day + "th";
|
|
243
|
+
}
|
|
244
|
+
if (lastDigit === 1) return day + "st";
|
|
245
|
+
if (lastDigit === 2) return day + "nd";
|
|
246
|
+
if (lastDigit === 3) return day + "rd";
|
|
247
|
+
return day + "th";
|
|
248
|
+
}, "day"],
|
|
249
|
+
// Quarter computed from month: 1-3=Q1, 4-6=Q2, 7-9=Q3, 10-12=Q4.
|
|
250
|
+
// `Q` is plain numeric, `QQQ` renders as "Q3" — same convention as
|
|
251
|
+
// date-fns's `Q` and `QQQ` for parity with the most common prior art.
|
|
252
|
+
// Both format and parse; parse() cross-checks Q/QQQ against the parsed
|
|
253
|
+
// month in the same spirit as the EEEE-vs-date cross-check.
|
|
254
|
+
["Q", (t) => String(Math.ceil(t.month / 3)), "month"],
|
|
255
|
+
["QQQ", (t) => "Q" + Math.ceil(t.month / 3), "month"],
|
|
256
|
+
// ISO 8601 week and week-numbering year. Both are format-only — parsing
|
|
257
|
+
// "ww"/"RRRR" back into a real date requires resolving an ISO week + a
|
|
258
|
+
// weekday (or some other disambiguator) to a specific date, which is a
|
|
259
|
+
// different parsing surface than the token-based parse() here. The
|
|
260
|
+
// ISO-week year (RRRR) can differ from the calendar year at the boundary:
|
|
261
|
+
// Dec 29-31 often belong to week 1 of the *next* year; Jan 1-3 often
|
|
262
|
+
// belong to week 52/53 of the *previous* year. See isoWeekYearAndWeek().
|
|
263
|
+
["ww", (t) => {
|
|
264
|
+
const { week } = isoWeekYearAndWeek(t.year, t.month, t.day, t.dayOfWeek);
|
|
265
|
+
return pad(week, 2);
|
|
266
|
+
}, "dayOfWeek"],
|
|
267
|
+
["RRRR", (t) => {
|
|
268
|
+
const { isoYear } = isoWeekYearAndWeek(t.year, t.month, t.day, t.dayOfWeek);
|
|
269
|
+
return pad(isoYear, 4);
|
|
270
|
+
}, "dayOfWeek"],
|
|
271
|
+
// Day of year — number of days since Jan 1 (1-366). Three widths:
|
|
272
|
+
// D — unpadded (1, 2, 366)
|
|
273
|
+
// DD — 2-digit minimum (zero-padded if <100)
|
|
274
|
+
// DDD — 3-digit zero-padded (001, 002, 366)
|
|
275
|
+
// Format-only — parsing day-of-year requires resolving against a year,
|
|
276
|
+
// which is a different shape from the token-based parse() surface.
|
|
277
|
+
// The dayOfYearHelper() in calendarUtils.ts covers the same field for
|
|
278
|
+
// callers who need the numeric value.
|
|
279
|
+
["D", (t) => String(dayOfYear(t.year, t.month, t.day)), "day"],
|
|
280
|
+
["DD", (t) => pad(dayOfYear(t.year, t.month, t.day), 2), "day"],
|
|
281
|
+
["DDD", (t) => pad(dayOfYear(t.year, t.month, t.day), 3), "day"],
|
|
282
|
+
// Stand-alone month — uses Intl's stand-alone form. In most locales
|
|
283
|
+
// (en, fr, de, es) this is identical to MMMM/MMM. In Slavic/Baltic
|
|
284
|
+
// locales (cs, sk, pl, ru) the stand-alone form differs from the
|
|
285
|
+
// format form (nominative vs genitive case). LLLL = long, LLL = short.
|
|
286
|
+
["LLLL", (t, locale) => {
|
|
287
|
+
const custom = getCustomVocab(locale);
|
|
288
|
+
return localeAwareName(t, locale, { month: "long" }, "month", custom?.monthLong, t.month - 1);
|
|
289
|
+
}, "month"],
|
|
290
|
+
["LLL", (t, locale) => {
|
|
291
|
+
const custom = getCustomVocab(locale);
|
|
292
|
+
return localeAwareName(t, locale, { month: "short" }, "month", custom?.monthShort, t.month - 1);
|
|
293
|
+
}, "month"],
|
|
294
|
+
// Stand-alone weekday — same pattern as stand-alone month but for
|
|
295
|
+
// weekday names. cccc = long, ccc = short.
|
|
296
|
+
["cccc", (t, locale) => {
|
|
297
|
+
const custom = getCustomVocab(locale);
|
|
298
|
+
return localeAwareName(t, locale, { weekday: "long" }, "weekday", custom?.weekdayLong, t.dayOfWeek - 1);
|
|
299
|
+
}, "dayOfWeek"],
|
|
300
|
+
["ccc", (t, locale) => {
|
|
301
|
+
const custom = getCustomVocab(locale);
|
|
302
|
+
return localeAwareName(t, locale, { weekday: "short" }, "weekday", custom?.weekdayShort, t.dayOfWeek - 1);
|
|
303
|
+
}, "dayOfWeek"],
|
|
304
|
+
// Era — locale-aware ("AD"/"BC" in en, "ap. J.-C."/"av. J.-C." in fr).
|
|
305
|
+
// GGGG = long, G = short. Format-only.
|
|
306
|
+
["GGGG", (t, locale) => {
|
|
307
|
+
return intlPart(t, locale, { era: "long" }, "era");
|
|
308
|
+
}, "year"],
|
|
309
|
+
["G", (t, locale) => {
|
|
310
|
+
return intlPart(t, locale, { era: "short" }, "era");
|
|
311
|
+
}, "year"],
|
|
312
|
+
// Localized timezone name — uses Intl's longLocalized/short timezone
|
|
313
|
+
// name option. Format-only — these names are locale-dependent and
|
|
314
|
+
// vary by season (EST vs EDT), so parsing them back requires a
|
|
315
|
+
// lookup table that isn't practical to ship.
|
|
316
|
+
["zzzz", (t, locale) => {
|
|
317
|
+
return intlPart(t, locale, { timeZoneName: "longGeneric" }, "timeZoneName");
|
|
318
|
+
}, "timeZoneId"],
|
|
319
|
+
["z", (t, locale) => {
|
|
320
|
+
return intlPart(t, locale, { timeZoneName: "short" }, "timeZoneName");
|
|
321
|
+
}, "timeZoneId"]
|
|
322
|
+
];
|
|
323
|
+
|
|
324
|
+
export {
|
|
325
|
+
DEFAULT_LOCALE,
|
|
326
|
+
TOKENS
|
|
327
|
+
};
|
|
328
|
+
//# sourceMappingURL=chunk-L24NPTAJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tokens.ts"],"sourcesContent":["import { getTemporal, subscribeToTemporalChanges } from './temporalProvider.js';\nimport { canonicalCacheKey, getCustomVocab, normalizeLocaleTag } from './localeVocab.js';\nimport { InvalidLocaleError } from './errors.js';\nimport { isoWeekYearAndWeek, dayOfYear } from './isoWeek.js';\n\nexport function pad(n: number, len: number): string {\n // padStart pads the whole string, sign included, so pad(-45, 4) used to\n // come out \"0-45\" instead of \"-045\" — split the sign off first.\n const negative = n < 0;\n const digits = String(Math.abs(n)).padStart(len, '0');\n return negative ? '-' + digits : digits;\n}\n\n// Combines the three sub-second fields Temporal exposes into one 9-digit\n// nanosecond-of-second value, then truncates (never rounds) to the\n// requested width. Truncating matches what every digit-width token in\n// this library already does elsewhere (yy, MM, dd, ...) — the token\n// asked for N digits of precision, not a rounded N-digit approximation.\n// A caller asking for SSS on a value with nanosecond precision gets the\n// leading 3 digits of it, same as they'd get the leading 3 digits of any\n// other multi-digit field this library formats.\n//\n// Attached to pad() rather than declared standalone: the bundler's\n// per-function coverage instrumentation attributes hits to each of the\n// 9 fraction-token arrow functions individually but not to a shared\n// helper they all close over, so a correctly-exercised helper still\n// shows as 0 hits under c8. pad() itself is called directly all over\n// this file and is reliably attributed — routing through it here keeps\n// the coverage numbers honest without duplicating the slice logic\n// across every token entry below.\npad.fraction = function formatFraction(t: TemporalLike, width: number): string {\n const nanoOfSecond = t.millisecond! * 1_000_000 + (t.microsecond ?? 0) * 1_000 + (t.nanosecond ?? 0);\n return pad(nanoOfSecond, 9).slice(0, width);\n};\n\n// Not every field exists on every Temporal type (PlainDate has no .hour,\n// etc). Callers check for undefined before formatting a token.\nexport interface TemporalLike {\n year?: number;\n month?: number;\n day?: number;\n hour?: number;\n minute?: number;\n second?: number;\n millisecond?: number;\n microsecond?: number;\n nanosecond?: number;\n timeZoneId?: string;\n // ZonedDateTime.prototype.offset — `±HH:MM` (6 chars) for any modern\n // date, but pre-1900 local-mean-time zones (e.g. America/New_York\n // before 1883) surface a seconds component too: `±HH:MM:SS` (9\n // chars). Format-side offset tokens must check the length rather\n // than assume 6. Parse-side writes a canonicalized `+HH:MM` here\n // before handing it to Temporal.ZonedDateTime.from as the\n // `timeZone` value.\n offset?: string;\n dayOfWeek?: number; // 1=Mon, 7=Sun, per Temporal spec\n calendarId?: string;\n toInstant?: () => unknown;\n toLocaleString?: (locale: string, options: Intl.DateTimeFormatOptions) => string;\n}\n\nexport interface FormatOptions {\n /** BCP 47 locale tag, e.g. 'en-US', 'fr-FR', 'ar-EG'. Defaults to 'en-US'. */\n locale?: string;\n /**\n * When set on parse(), opts into the lenient split heuristic for ambiguous\n * glued numeric runs (e.g. \"121\" against \"Md\"). Default (false) keeps\n * parse()'s strict behavior — throw on ambiguity rather than guess.\n * See README \"Lenient parse mode\" for the heuristic and why it's opt-in.\n */\n lenient?: boolean;\n}\n\nexport const DEFAULT_LOCALE = 'en-US';\n\n// Intl.DateTimeFormat is expensive to construct and format() can run in a\n// loop (rendering a table of dates), so cache by (locale, options).\nconst formatterCache = new Map<string, Intl.DateTimeFormat>();\nconst MAX_CACHE_SIZE = 500;\n\nfunction getFormatter(locale: string, options: Intl.DateTimeFormatOptions): Intl.DateTimeFormat {\n const key = JSON.stringify([canonicalCacheKey(locale), options]);\n let formatter = formatterCache.get(key);\n if (formatter) {\n return formatter;\n }\n if (formatterCache.size >= MAX_CACHE_SIZE) {\n // not real LRU, just evicts oldest insertion — fine for this key space\n const oldestKey = formatterCache.keys().next().value;\n if (oldestKey !== undefined) formatterCache.delete(oldestKey);\n }\n try {\n formatter = new Intl.DateTimeFormat(normalizeLocaleTag(locale), options);\n } catch (err) {\n // Malformed locale tags reach Intl as a bare RangeError; surface the\n // library's typed error instead (reached via dayPeriodPart — the\n // 'a' token — on any runtime, and the native-Intl path for the rest).\n // Every failure mode of this constructor with a string locale is a\n // RangeError, so converting unconditionally preserves the original\n // message in `reason` either way.\n throw new InvalidLocaleError({ actual: locale, reason: (err as Error).message });\n }\n formatterCache.set(key, formatter);\n return formatter;\n}\n\n// Passing a Temporal object straight into `new Intl.DateTimeFormat().formatToParts()`\n// only works when the engine's Intl implementation has special-cased support for\n// *native* Temporal instances (checked via internal slots and/or gated behind a V8 flag,\n// not tied to a specific Node version).\n//\n// A Temporal polyfill's instances don't have those slots, so the engine falls back to ToNumber() -> .valueOf(),\n// which the polyfill deliberately throws on (\"Cannot use valueOf\").\n// Probed once and memoized and only from intlPart(), so it never\n// runs unless a format string actually uses a locale-aware token.\nlet nativeSupport: boolean | undefined;\n// Invalidate the memoized probe whenever setTemporal() swaps the active\n// implementation — otherwise a probe result from \"is native Temporal\n// supported\" could keep being used after the active implementation is\n// no longer the one that was probed. See setTemporal() in\n// temporalProvider.ts for the other half of this.\nsubscribeToTemporalChanges(() => { nativeSupport = undefined; });\n\nfunction intlSupportsNativeTemporal(): boolean {\n if (nativeSupport === undefined) {\n nativeSupport = false;\n try {\n const temporal = getTemporal();\n new Intl.DateTimeFormat('en-US', { day: 'numeric' })\n .formatToParts(temporal.PlainDate.from({ year: 1970, month: 1, day: 1 }) as Date);\n // Version-gated, not dead — see the matching note on the\n // !intlSupportsNativeTemporal() branch in intlPart() below for\n // why this can't be exercised from this environment.\n /* c8 ignore next */\n nativeSupport = true;\n /* c8 ignore start */\n } catch {\n // native Temporal absent, or present but not recognized by Intl — fall back.\n // Version-gated, not dead: this catch only fires on runtimes where the\n // probe above throws (no native Temporal, or Intl doesn't recognize it).\n // On a runtime with full native support (e.g. Node builds where Intl\n // accepts native Temporal instances directly) the try succeeds and this\n // branch is unreachable — mirror case of the block below.\n }\n /* c8 ignore stop */\n }\n return nativeSupport;\n}\n\nfunction intlPart(\n temporal: TemporalLike,\n locale: string,\n options: Intl.DateTimeFormatOptions,\n partType: Intl.DateTimeFormatPartTypes\n): string {\n // Intl throws \"Mismatching Calendars\" if the formatter's calendar doesn't\n // match the object's own (e.g. en-US formatter defaults to gregory, but\n // a hebrew/islamic PlainDate needs its own calendar passed through).\n //\n // For iso8601 specifically, force 'gregory' rather than leaving calendar\n // unset: numeric fields (yyyy/dd, see tokens' pad()-based handlers) are\n // always pulled straight off the object's own ISO fields — so if the\n // *locale* carries a `-u-ca-*` extension (e.g. 'en-u-ca-hebrew') and this\n // step left calendar unset, the formatter would resolve its own default\n // calendar from the locale and format MMMM/EEEE in that calendar while\n // yyyy/dd stay ISO, producing a date that looks internally consistent\n // (a real Hebrew month name next to a real-looking day/year) but names a\n // completely different day than the object actually represents. Forcing\n // 'gregory' here keeps every field of an ISO object's output anchored to\n // the same (ISO/Gregorian) calendar — a locale's calendar extension only\n // takes effect when the object itself already carries a non-ISO calendar\n // (via `.withCalendar()`), matching what the README documents.\n //\n // 'gregory' specifically, not 'iso8601' — passing `calendar: 'iso8601'`\n // explicitly alongside a single-field options object makes\n // formatToParts() come back empty for some reason, but 'gregory' doesn't\n // have that problem and Temporal's iso8601 calendar is Gregorian-shaped\n // (proleptic Gregorian throughout, no Julian cutover) so the two agree\n // on every numeric field this library ever reads.\n const calendar = temporal?.calendarId;\n const formatterOptions: Intl.DateTimeFormatOptions = {\n ...options,\n calendar: calendar && calendar !== 'iso8601' ? calendar : 'gregory',\n };\n\n // Field-bag guard: a plain { year, month, day } object only has\n // Object.prototype.toLocaleString, which ignores both arguments and\n // returns \"[object Object]\". On engines without native Temporal\n // support in Intl this used to be caught below, but on engines where\n // Intl *does* recognize native Temporal instances (Node 26+), a bag\n // skips that branch entirely and reaches formatToParts() directly —\n // which doesn't throw \"[object Object]\", it throws a bare\n // \"RangeError: Invalid time value\" once the bag fails ToNumber()\n // coercion. Neither failure mode is useful to a caller, so check for\n // a real toLocaleString up front, before branching on native support,\n // so the descriptive error fires on every engine.\n const ls = temporal.toLocaleString;\n if (typeof ls !== 'function' || ls === Object.prototype.toLocaleString) {\n throw new Error(\n `temporal-fmt: locale-aware part \"${partType}\" needs a value that implements ` +\n `toLocaleString (a real Temporal object). A plain field bag cannot render ` +\n `locale-aware names — pass a Temporal.PlainDate/PlainDateTime/ZonedDateTime.`\n );\n }\n\n // Temporal.prototype.toLocaleString() is part of the Temporal spec itself:\n // polyfills implement the ICU formatting internally without needing the\n // engine to recognize the object, so it works without native Intl support.\n //\n // Everything from here to the end of this function is genuinely\n // reachable — NOT dead code — but only on a Node build where a global\n // `Temporal` exists AND Intl.DateTimeFormat.formatToParts() recognizes\n // native Temporal instances directly (this is real, observed to vary\n // across Node versions: absent on the Node 22/24 builds this suite has\n // been run against, present on at least one Node 26 build). This\n // environment has no native Temporal (`typeof globalThis.Temporal ===\n // 'undefined'`), so intlSupportsNativeTemporal() always returns false\n // here and this branch can't be exercised from this test suite without\n // faking native-instance recognition, which turned out to be\n // impractical (Intl's native-Temporal detection isn't spoofable via a\n // Proxy or valueOf() shim — see the M-02 regression test in\n // temporalProvider.test.js for the same conclusion reached about the\n // sibling probe function). Coverage numbers for this block will differ\n // between Node versions for that reason; that's expected, not a\n // regression.\n /* c8 ignore start */\n if (!intlSupportsNativeTemporal()) {\n // normalizeLocaleTag: the active Temporal implementation's\n // toLocaleString forwards the locale to Intl.DateTimeFormat, which\n // (unlike this library's cache keys) rejects underscore-separated\n // tags like 'en_US' outright.\n // (Field-bag guard now runs unconditionally above, before this\n // native-support branch, so it's not repeated here.)\n try {\n return ls.call(temporal, normalizeLocaleTag(locale), formatterOptions);\n } catch (err) {\n // The active Temporal implementation forwards the tag to Intl, which\n // throws a bare RangeError for a malformed one — rethrow typed.\n if (err instanceof RangeError) {\n throw new InvalidLocaleError({ actual: locale, reason: err.message });\n }\n throw err;\n }\n }\n\n // formatToParts() throws on ZonedDateTime directly (per spec), so convert\n // to Instant and pass the zone via `timeZone` instead. Don't convert to\n // PlainDateTime — that drops the zone, which breaks 'MMMM' + 'zzz' combos.\n const { toInstant, timeZoneId } = temporal;\n const isZoned = typeof toInstant === 'function' && typeof timeZoneId === 'string';\n // has to be called as temporal.toInstant() because destructuring it off breaks\n // the receiver and throws\n const intlSafeTemporal = isZoned ? temporal.toInstant!() : temporal;\n const nativeOptions: Intl.DateTimeFormatOptions = {\n ...formatterOptions,\n ...(isZoned ? { timeZone: timeZoneId } : {}),\n };\n\n const formatter = getFormatter(locale, nativeOptions);\n const parts = formatter.formatToParts(intlSafeTemporal as Date | number);\n const index = parts.findIndex((p) => p.type === partType);\n if (index === -1) {\n throw new Error(\n `temporal-fmt: locale \"${locale}\" produced no \"${partType}\" part for this token. ` +\n `This usually means the Temporal object is missing the field the token needs.`\n );\n }\n // some locales (ja-JP) split a field across two parts — e.g. month \"8\"\n // plus a counter suffix \"月\" as a separate sibling literal part. Merge in\n // an adjacent literal only if it has no whitespace, so a genuine suffix\n // gets folded in but an ordinary separator (the space before \"AM\") stays\n // a separator. Mirrors partValue() in localeVocab.ts, which builds the\n // vocab this token's output needs to match for parse() to round-trip.\n let value = parts[index]!.value;\n const prev = parts[index - 1];\n const next = parts[index + 1];\n if (prev?.type === 'literal' && !/\\s/.test(prev.value)) value = prev.value + value;\n if (next?.type === 'literal' && !/\\s/.test(next.value)) value = value + next.value;\n return value;\n}\n/* c8 ignore stop */\n\n// Temporal.prototype.toLocaleString() can't isolate a single field the way\n// formatToParts() can — asking for `hour` + `dayPeriod` together returns one\n// joined string (e.g. \"3 in the afternoon\"), and `dayPeriod` alone resolves\n// against a different, non-hour-anchored set of periods (\"in the\n// afternoon\"/\"昼\" instead of \"PM\"/\"午後\"). Day period only depends on the\n// hour anyway, so route it through a plain UTC Date and Intl.DateTimeFormat\n// instead — that's worked the same on every engine regardless of whether\n// Temporal itself is native or polyfilled.\nfunction dayPeriodPart(hour: number, locale: string): string {\n // Custom vocab (when registered) takes precedence over Intl — same\n // contract as the other locale-aware tokens. Intl won't know about a\n // caller-supplied AM/PM string for a made-up locale key, so going\n // through Intl would produce something other than what the caller\n // registered.\n const custom = getCustomVocab(locale);\n if (custom) {\n return hour < 12 ? custom.dayPeriod[0]! : custom.dayPeriod[1]!;\n }\n const date = new Date(Date.UTC(1970, 0, 1, hour));\n const formatter = getFormatter(locale, { hour: 'numeric', hour12: true, timeZone: 'UTC' });\n const part = formatter.formatToParts(date).find((p) => p.type === 'dayPeriod');\n // Defensive guard, confirmed unreachable on this ICU build: forcing\n // hour12: true (as this call always does) produces a dayPeriod part\n // for every locale checked, including 24-hour-clock locales (ja-JP,\n // zh-CN, th-TH, he-IL) and a wide sweep of less-common tags (dz-BT,\n // bo-CN, am-ET, etc.). Same finding as partValue()'s twin guard in\n // localeVocab.ts. Kept in case a future ICU/locale-data update\n // produces a locale that genuinely omits it.\n /* c8 ignore start */\n if (!part) {\n throw new Error(`temporal-fmt: locale \"${locale}\" produced no \"dayPeriod\" part for token \"a\".`);\n }\n /* c8 ignore stop */\n return part.value;\n}\n\n// Resolves a locale-aware month/weekday name from the registered custom\n// vocab when one exists for this locale, falling through to Intl otherwise.\n// Without this, format() would silently keep producing Intl's strings while\n// parse() matched against the registered vocab — the two would round-trip-fail\n// against each other.\nfunction localeAwareName(\n temporal: TemporalLike,\n locale: string,\n options: Intl.DateTimeFormatOptions,\n partType: Intl.DateTimeFormatPartTypes,\n customArray: string[] | undefined,\n customIndex: number | undefined,\n): string {\n if (customArray && customIndex !== undefined && customIndex >= 0 && customIndex < customArray.length) {\n return customArray[customIndex]!;\n }\n return intlPart(temporal, locale, options, partType);\n}\n\n// Formats a `±HH:MM` offset string (the shape Temporal exposes on\n// ZonedDateTime.prototype.offset) into one of the six offset-token widths.\n// Width and Z-handling come from the variant letter+case:\n//\n// X / x — short form: minutes omitted when zero, no colon otherwise\n// XX / xx — hours + minutes, no colon\n// XXX / xxx — hours + minutes, with colon\n//\n// Uppercase (X) collapses +00:00 to \"Z\"; lowercase (x) always emits a\n// numeric offset, even for UTC. Mirrors the date-fns/Unicode-LDML offset\n// family — see README for the full variant table.\nfunction formatOffset(offset: string, variant: 'X' | 'XX' | 'XXX' | 'x' | 'xx' | 'xxx'): string {\n if (offset === '+00:00' && (variant === 'X' || variant === 'XX' || variant === 'XXX')) {\n return 'Z';\n }\n // Most offsets are 6 chars: sign + HH + ':' + MM. Pre-1900 local-mean-time\n // zones can surface a seconds component too, 9 chars: sign + HH + ':' +\n // MM + ':' + SS. \"xxx\" is the one variant with a always-signed,\n // never-\"Z\" colon-separated shape wide enough to carry that unchanged,\n // so it passes a sub-minute offset through verbatim. Every other\n // variant has no seconds slot and must throw rather than silently\n // truncate them away.\n if (offset.length > 6) {\n if (variant === 'xxx') {\n return offset;\n }\n throw new Error(\n `temporal-fmt: token \"${variant}\" cannot represent the offset \"${offset}\", ` +\n `which has a seconds component. None of the X/XX/XXX/x/xx tokens ` +\n `support offset seconds; use \"xxx\" instead, which formats the full ` +\n `offset unchanged.`\n );\n }\n const sign = offset[0]!;\n const hours = offset.slice(1, 3);\n const minutes = offset.slice(4, 6);\n switch (variant) {\n case 'X': case 'x':\n // minutes only matter when they're non-zero — otherwise drop them\n // entirely. Matches LDML: \"With a single X, the hours field is\n // required. The minutes field is optional, but only if the\n // minutes value is 0.\"\n return minutes === '00' ? `${sign}${hours}` : `${sign}${hours}${minutes}`;\n case 'XX': case 'xx':\n return `${sign}${hours}${minutes}`;\n case 'XXX': case 'xxx':\n return `${sign}${hours}:${minutes}`;\n }\n}\n\ntype TokenHandler = (t: TemporalLike, locale: string) => string;\n\n// Longest-first — tokenizer is greedy, \"yyyy\" has to be tried before \"yy\".\n//\n// Numeric tokens always render in ASCII digits, never locale-native\n// (Arabic-Indic, Devanagari, etc). Padding non-ASCII digits isn't as simple\n// as padding \"3\", and most consumers parsing these back out want plain\n// digits anyway.\nexport const TOKENS: Array<[string, TokenHandler, keyof TemporalLike]> = [\n ['yyyy', (t) => pad(t.year!, 4), 'year'],\n ['yy', (t) => {\n // -45 % 100 === -45, so truncating negative years to 2 digits doesn't\n // work and Math.abs() would make 45 CE and 45 BCE render the same.\n if (t.year! < 0) {\n throw new Error(\n `temporal-fmt: token \"yy\" doesn't support negative years (got ${t.year}), ` +\n `since truncating to 2 digits would make it indistinguishable from a ` +\n `positive year. Use \"yyyy\" instead.`\n );\n }\n return pad(t.year! % 100, 2);\n }, 'year'],\n // Unpadded year — no minimum width, unlike yyyy's fixed 4 digits.\n // pad(n, 0) still does the right thing here: Math.abs(n) with no\n // padStart floor just yields the plain digit string, and the sign\n // handling (split off before padding) already covers negative years,\n // so this doesn't need its own sign branch the way \"yy\" does.\n ['y', (t) => pad(t.year!, 0), 'year'],\n ['MMMM', (t, locale) => {\n const custom = getCustomVocab(locale);\n return localeAwareName(t, locale, { month: 'long' }, 'month', custom?.monthLong, t.month! - 1);\n }, 'month'],\n ['MMM', (t, locale) => {\n const custom = getCustomVocab(locale);\n return localeAwareName(t, locale, { month: 'short' }, 'month', custom?.monthShort, t.month! - 1);\n }, 'month'],\n ['MM', (t) => pad(t.month!, 2), 'month'],\n ['M', (t) => String(t.month!), 'month'],\n ['dd', (t) => pad(t.day!, 2), 'day'],\n ['d', (t) => String(t.day!), 'day'],\n ['EEEE', (t, locale) => {\n const custom = getCustomVocab(locale);\n return localeAwareName(t, locale, { weekday: 'long' }, 'weekday', custom?.weekdayLong, t.dayOfWeek! - 1);\n }, 'dayOfWeek'],\n ['EEE', (t, locale) => {\n const custom = getCustomVocab(locale);\n return localeAwareName(t, locale, { weekday: 'short' }, 'weekday', custom?.weekdayShort, t.dayOfWeek! - 1);\n }, 'dayOfWeek'],\n ['HH', (t) => pad(t.hour!, 2), 'hour'],\n ['H', (t) => String(t.hour!), 'hour'],\n ['hh', (t) => pad(t.hour! % 12 || 12, 2), 'hour'],\n ['h', (t) => String(t.hour! % 12 || 12), 'hour'],\n ['mm', (t) => pad(t.minute!, 2), 'minute'],\n ['m', (t) => String(t.minute!), 'minute'],\n ['ss', (t) => pad(t.second!, 2), 'second'],\n ['s', (t) => String(t.second!), 'second'],\n // Fractional-second tokens, S through SSSSSSSSS (1-9 digits). Each token\n // formats a slice of the same underlying nanosecond-of-second value —\n // combining millisecond/microsecond/nanosecond into one 9-digit number\n // and truncating to the token's width — so \"SSS\" keeps meaning exactly\n // what it always meant (3-digit milliseconds) while wider tokens expose\n // the precision Temporal actually carries. formatFraction below is the\n // shared implementation; see its comment for the truncate-not-round\n // rule and why.\n ['SSSSSSSSS', (t) => pad.fraction(t, 9), 'millisecond'],\n ['SSSSSSSS', (t) => pad.fraction(t, 8), 'millisecond'],\n ['SSSSSSS', (t) => pad.fraction(t, 7), 'millisecond'],\n ['SSSSSS', (t) => pad.fraction(t, 6), 'millisecond'],\n ['SSSSS', (t) => pad.fraction(t, 5), 'millisecond'],\n ['SSSS', (t) => pad.fraction(t, 4), 'millisecond'],\n ['SSS', (t) => pad.fraction(t, 3), 'millisecond'],\n ['SS', (t) => pad.fraction(t, 2), 'millisecond'],\n ['S', (t) => pad.fraction(t, 1), 'millisecond'],\n // dayPeriod text is locale-specific (AM/PM in en-US, م/ص in ar-EG) but\n // still needs .hour on the input to compute which period it is\n ['a', (t, locale) => dayPeriodPart(t.hour!, locale), 'hour'],\n ['zzz', (t) => t.timeZoneId!, 'timeZoneId'],\n // Numeric UTC offset tokens (date-fns/Unicode-LDML family). Only\n // ZonedDateTime carries an offset, so the field check in format() throws\n // the same \"requires offset, which this Temporal object doesn't have\"\n // error zzz throws on PlainDate/PlainTime/PlainDateTime — same\n // validation path, just a different field name. See formatOffset above\n // for the per-variant width and Z/numeric distinction.\n ['xxx', (t) => formatOffset(t.offset!, 'xxx'), 'offset'],\n ['xx', (t) => formatOffset(t.offset!, 'xx'), 'offset'],\n ['X', (t) => formatOffset(t.offset!, 'X'), 'offset'],\n ['XX', (t) => formatOffset(t.offset!, 'XX'), 'offset'],\n ['XXX', (t) => formatOffset(t.offset!, 'XXX'), 'offset'],\n ['x', (t) => formatOffset(t.offset!, 'x'), 'offset'],\n\n // Ordinal day (1st, 2nd, 3rd, ... 21st). English suffix rules only —\n // locale-aware ordinals (\"2.\" in de-DE, \"2日\" in ja-JP) are out of scope,\n // since the rest of this library routes locale-specific names through\n // Intl.DateTimeFormat, and Intl has no part type for ordinals. Format-only:\n // the suffix isn't structurally distinguishable from a literal in a parse\n // context (a \"st\"/\"nd\"/\"rd\"/\"th\" suffix isn't a digit and would collide\n // with any adjacent literal text), so there's no good way to read it back.\n ['do', (t) => {\n const day = t.day!;\n const lastDigit = day % 10;\n // 11, 12, 13 are the exception — they'd otherwise match the 1/2/3 rule\n // and produce \"11st\"/\"12nd\"/\"13rd\", which is wrong. They always take \"th\".\n const lastTwoDigits = day % 100;\n if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {\n return day + 'th';\n }\n if (lastDigit === 1) return day + 'st';\n if (lastDigit === 2) return day + 'nd';\n if (lastDigit === 3) return day + 'rd';\n return day + 'th';\n }, 'day'],\n\n // Quarter computed from month: 1-3=Q1, 4-6=Q2, 7-9=Q3, 10-12=Q4.\n // `Q` is plain numeric, `QQQ` renders as \"Q3\" — same convention as\n // date-fns's `Q` and `QQQ` for parity with the most common prior art.\n // Both format and parse; parse() cross-checks Q/QQQ against the parsed\n // month in the same spirit as the EEEE-vs-date cross-check.\n ['Q', (t) => String(Math.ceil(t.month! / 3)), 'month'],\n ['QQQ', (t) => 'Q' + Math.ceil(t.month! / 3), 'month'],\n\n // ISO 8601 week and week-numbering year. Both are format-only — parsing\n // \"ww\"/\"RRRR\" back into a real date requires resolving an ISO week + a\n // weekday (or some other disambiguator) to a specific date, which is a\n // different parsing surface than the token-based parse() here. The\n // ISO-week year (RRRR) can differ from the calendar year at the boundary:\n // Dec 29-31 often belong to week 1 of the *next* year; Jan 1-3 often\n // belong to week 52/53 of the *previous* year. See isoWeekYearAndWeek().\n ['ww', (t) => {\n const { week } = isoWeekYearAndWeek(t.year!, t.month!, t.day!, t.dayOfWeek!);\n return pad(week, 2);\n }, 'dayOfWeek'],\n ['RRRR', (t) => {\n const { isoYear } = isoWeekYearAndWeek(t.year!, t.month!, t.day!, t.dayOfWeek!);\n return pad(isoYear, 4);\n }, 'dayOfWeek'],\n\n // Day of year — number of days since Jan 1 (1-366). Three widths:\n // D — unpadded (1, 2, 366)\n // DD — 2-digit minimum (zero-padded if <100)\n // DDD — 3-digit zero-padded (001, 002, 366)\n // Format-only — parsing day-of-year requires resolving against a year,\n // which is a different shape from the token-based parse() surface.\n // The dayOfYearHelper() in calendarUtils.ts covers the same field for\n // callers who need the numeric value.\n ['D', (t) => String(dayOfYear(t.year!, t.month!, t.day!)), 'day'],\n ['DD', (t) => pad(dayOfYear(t.year!, t.month!, t.day!), 2), 'day'],\n ['DDD', (t) => pad(dayOfYear(t.year!, t.month!, t.day!), 3), 'day'],\n\n // Stand-alone month — uses Intl's stand-alone form. In most locales\n // (en, fr, de, es) this is identical to MMMM/MMM. In Slavic/Baltic\n // locales (cs, sk, pl, ru) the stand-alone form differs from the\n // format form (nominative vs genitive case). LLLL = long, LLL = short.\n ['LLLL', (t, locale) => {\n const custom = getCustomVocab(locale);\n return localeAwareName(t, locale, { month: 'long' }, 'month', custom?.monthLong, t.month! - 1);\n }, 'month'],\n ['LLL', (t, locale) => {\n const custom = getCustomVocab(locale);\n return localeAwareName(t, locale, { month: 'short' }, 'month', custom?.monthShort, t.month! - 1);\n }, 'month'],\n\n // Stand-alone weekday — same pattern as stand-alone month but for\n // weekday names. cccc = long, ccc = short.\n ['cccc', (t, locale) => {\n const custom = getCustomVocab(locale);\n return localeAwareName(t, locale, { weekday: 'long' }, 'weekday', custom?.weekdayLong, t.dayOfWeek! - 1);\n }, 'dayOfWeek'],\n ['ccc', (t, locale) => {\n const custom = getCustomVocab(locale);\n return localeAwareName(t, locale, { weekday: 'short' }, 'weekday', custom?.weekdayShort, t.dayOfWeek! - 1);\n }, 'dayOfWeek'],\n\n // Era — locale-aware (\"AD\"/\"BC\" in en, \"ap. J.-C.\"/\"av. J.-C.\" in fr).\n // GGGG = long, G = short. Format-only.\n ['GGGG', (t, locale) => {\n return intlPart(t, locale, { era: 'long' }, 'era');\n }, 'year'],\n ['G', (t, locale) => {\n return intlPart(t, locale, { era: 'short' }, 'era');\n }, 'year'],\n\n // Localized timezone name — uses Intl's longLocalized/short timezone\n // name option. Format-only — these names are locale-dependent and\n // vary by season (EST vs EDT), so parsing them back requires a\n // lookup table that isn't practical to ship.\n ['zzzz', (t, locale) => {\n return intlPart(t, locale, { timeZoneName: 'longGeneric' as Intl.DateTimeFormatOptions['timeZoneName'] }, 'timeZoneName' as Intl.DateTimeFormatPartTypes);\n }, 'timeZoneId'],\n ['z', (t, locale) => {\n return intlPart(t, locale, { timeZoneName: 'short' as Intl.DateTimeFormatOptions['timeZoneName'] }, 'timeZoneName' as Intl.DateTimeFormatPartTypes);\n }, 'timeZoneId'],\n\n];"],"mappings":";;;;;;;;;;;;;;;;AAKO,SAAS,IAAI,GAAW,KAAqB;AAGlD,QAAM,WAAW,IAAI;AACrB,QAAM,SAAS,OAAO,KAAK,IAAI,CAAC,CAAC,EAAE,SAAS,KAAK,GAAG;AACpD,SAAO,WAAW,MAAM,SAAS;AACnC;AAmBA,IAAI,WAAW,SAAS,eAAe,GAAiB,OAAuB;AAC7E,QAAM,eAAe,EAAE,cAAe,OAAa,EAAE,eAAe,KAAK,OAAS,EAAE,cAAc;AAClG,SAAO,IAAI,cAAc,CAAC,EAAE,MAAM,GAAG,KAAK;AAC5C;AAyCO,IAAM,iBAAiB;AAI9B,IAAM,iBAAiB,oBAAI,IAAiC;AAC5D,IAAM,iBAAiB;AAEvB,SAAS,aAAa,QAAgB,SAA0D;AAC9F,QAAM,MAAM,KAAK,UAAU,CAAC,kBAAkB,MAAM,GAAG,OAAO,CAAC;AAC/D,MAAI,YAAY,eAAe,IAAI,GAAG;AACtC,MAAI,WAAW;AACb,WAAO;AAAA,EACT;AACA,MAAI,eAAe,QAAQ,gBAAgB;AAEzC,UAAM,YAAY,eAAe,KAAK,EAAE,KAAK,EAAE;AAC/C,QAAI,cAAc,OAAW,gBAAe,OAAO,SAAS;AAAA,EAC9D;AACA,MAAI;AACF,gBAAY,IAAI,KAAK,eAAe,mBAAmB,MAAM,GAAG,OAAO;AAAA,EACzE,SAAS,KAAK;AAOZ,UAAM,IAAI,mBAAmB,EAAE,QAAQ,QAAQ,QAAS,IAAc,QAAQ,CAAC;AAAA,EACjF;AACA,iBAAe,IAAI,KAAK,SAAS;AACjC,SAAO;AACT;AAWA,IAAI;AAMJ,2BAA2B,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AC3G,GAAG,WAAW;AAAA;AAAA;AAAA,EAId,CAAC,QAAQ,CAAC,GAAG,WAAW;AACtB,WAAO,SAAS,GAAG,QAAQ,EAAE,KAAK,OAAO,GAAG,KAAK;AAAA,EACnD,GAAG,MAAM;AAAA,EACT,CAAC,KAAK,CAAC,GAAG,WAAW;AACnB,WAAO,SAAS,GAAG,QAAQ,EAAE,KAAK,QAAQ,GAAG,KAAK;AAAA,EACpD,GAAG,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAMT,CAAC,QAAQ,CAAC,GAAG,WAAW;AACtB,WAAO,SAAS,GAAG,QAAQ,EAAE,cAAc,cAA4D,GAAG,cAA8C;AAAA,EAC1J,GAAG,YAAY;AAAA,EACf,CAAC,KAAK,CAAC,GAAG,WAAW;AACnB,WAAO,SAAS,GAAG,QAAQ,EAAE,cAAc,QAAsD,GAAG,cAA8C;AAAA,EACpJ,GAAG,YAAY;AAEjB;","names":[]}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TOKENS
|
|
3
|
+
} from "./chunk-L24NPTAJ.js";
|
|
4
|
+
import {
|
|
5
|
+
FormatSyntaxError,
|
|
6
|
+
InvalidLocaleError,
|
|
7
|
+
UnknownTokenError
|
|
8
|
+
} from "./chunk-EGUUO6LE.js";
|
|
9
|
+
|
|
10
|
+
// src/tokenize.ts
|
|
11
|
+
var SORTED_TOKEN_STRINGS = TOKENS.map(([tok]) => tok).sort((a, b) => b.length - a.length);
|
|
12
|
+
function tokenize(format) {
|
|
13
|
+
const pieces = [];
|
|
14
|
+
let i = 0;
|
|
15
|
+
while (i < format.length) {
|
|
16
|
+
const ch = format[i];
|
|
17
|
+
if (ch === "'") {
|
|
18
|
+
if (format[i + 1] === "'") {
|
|
19
|
+
appendLiteral(pieces, "'");
|
|
20
|
+
i += 2;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
let j = i + 1;
|
|
24
|
+
let literal = "";
|
|
25
|
+
let closed = false;
|
|
26
|
+
while (j < format.length) {
|
|
27
|
+
if (format[j] === "'") {
|
|
28
|
+
if (format[j + 1] === "'") {
|
|
29
|
+
literal += "'";
|
|
30
|
+
j += 2;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
closed = true;
|
|
34
|
+
j += 1;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
literal += format[j];
|
|
38
|
+
j += 1;
|
|
39
|
+
}
|
|
40
|
+
if (!closed) {
|
|
41
|
+
throw new FormatSyntaxError({
|
|
42
|
+
format,
|
|
43
|
+
message: `temporal-fmt: unterminated quote in format string "${format}"`
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
appendLiteral(pieces, literal);
|
|
47
|
+
i = j;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const match = SORTED_TOKEN_STRINGS.find((tok) => format.startsWith(tok, i));
|
|
51
|
+
if (match) {
|
|
52
|
+
const runChar = match[match.length - 1];
|
|
53
|
+
if (format[i + match.length] === runChar) {
|
|
54
|
+
let end = i + match.length;
|
|
55
|
+
while (format[end] === runChar) end += 1;
|
|
56
|
+
throw new UnknownTokenError({
|
|
57
|
+
format,
|
|
58
|
+
token: format.slice(i, end),
|
|
59
|
+
message: `temporal-fmt: "${format.slice(i, end)}" in format string "${format}" isn't a recognized token \u2014 did you mean "${match}"?`
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
pieces.push({ kind: "token", value: match });
|
|
63
|
+
i += match.length;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
appendLiteral(pieces, ch);
|
|
67
|
+
i += 1;
|
|
68
|
+
}
|
|
69
|
+
return pieces;
|
|
70
|
+
}
|
|
71
|
+
function appendLiteral(pieces, value) {
|
|
72
|
+
const last = pieces[pieces.length - 1];
|
|
73
|
+
if (last && last.kind === "literal") {
|
|
74
|
+
last.value += value;
|
|
75
|
+
} else {
|
|
76
|
+
pieces.push({ kind: "literal", value });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/numbering.ts
|
|
81
|
+
var SUPPORTED_NUMBERING_SYSTEMS = /* @__PURE__ */ new Set([
|
|
82
|
+
"latn",
|
|
83
|
+
"arab",
|
|
84
|
+
"deva",
|
|
85
|
+
"beng",
|
|
86
|
+
"guru",
|
|
87
|
+
"gujr",
|
|
88
|
+
"orya",
|
|
89
|
+
"tamldec",
|
|
90
|
+
"telu",
|
|
91
|
+
"knda",
|
|
92
|
+
"mlym",
|
|
93
|
+
"fullwide",
|
|
94
|
+
"hanidec"
|
|
95
|
+
]);
|
|
96
|
+
var digitMapCache = /* @__PURE__ */ new Map();
|
|
97
|
+
function getDigitMap(system) {
|
|
98
|
+
let map = digitMapCache.get(system);
|
|
99
|
+
if (map) return map;
|
|
100
|
+
/* c8 ignore start @preserve -- this branch is dead by construction, not
|
|
101
|
+
just untested: both callers (convertDigits, convertDigitsToAscii)
|
|
102
|
+
already bail out early on system === 'latn' before ever calling
|
|
103
|
+
getDigitMap, so it never actually gets invoked with 'latn'. keeping
|
|
104
|
+
it anyway as a defensive fallback rather than betting that stays
|
|
105
|
+
true forever */
|
|
106
|
+
if (system === "latn") {
|
|
107
|
+
map = {};
|
|
108
|
+
for (let i = 0; i < 10; i++) map[String(i)] = String(i);
|
|
109
|
+
} else {
|
|
110
|
+
/* c8 ignore stop @preserve */
|
|
111
|
+
const fmt = new Intl.NumberFormat("en-US-u-nu-" + system, { useGrouping: false });
|
|
112
|
+
map = {};
|
|
113
|
+
for (let i = 0; i < 10; i++) {
|
|
114
|
+
map[String(i)] = fmt.format(i);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
digitMapCache.set(system, map);
|
|
118
|
+
return map;
|
|
119
|
+
}
|
|
120
|
+
function convertDigits(s, system) {
|
|
121
|
+
if (system === "latn") return s;
|
|
122
|
+
if (!SUPPORTED_NUMBERING_SYSTEMS.has(system)) {
|
|
123
|
+
throw new InvalidLocaleError({ actual: system, reason: `numbering system "${system}" is not supported. Supported: ${[...SUPPORTED_NUMBERING_SYSTEMS].join(", ")}.` });
|
|
124
|
+
}
|
|
125
|
+
const map = getDigitMap(system);
|
|
126
|
+
let result = "";
|
|
127
|
+
for (const ch of s) {
|
|
128
|
+
if (ch >= "0" && ch <= "9") {
|
|
129
|
+
result += map[ch] ?? ch;
|
|
130
|
+
} else {
|
|
131
|
+
result += ch;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
function convertDigitsToAscii(s, system) {
|
|
137
|
+
if (system === "latn") return s;
|
|
138
|
+
if (!SUPPORTED_NUMBERING_SYSTEMS.has(system)) {
|
|
139
|
+
throw new InvalidLocaleError({ actual: system, reason: `numbering system "${system}" is not supported.` });
|
|
140
|
+
}
|
|
141
|
+
const map = getDigitMap(system);
|
|
142
|
+
const reverse = {};
|
|
143
|
+
for (const k of Object.keys(map)) reverse[map[k]] = k;
|
|
144
|
+
let result = "";
|
|
145
|
+
for (const ch of s) {
|
|
146
|
+
result += reverse[ch] ?? ch;
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
function applyNumbering(s, options) {
|
|
151
|
+
const system = options.numberingSystem ?? "latn";
|
|
152
|
+
if (system === "latn") return s;
|
|
153
|
+
return convertDigits(s, system);
|
|
154
|
+
}
|
|
155
|
+
function applyParseNumbering(s, options) {
|
|
156
|
+
const system = options.parseNumberingSystem ?? "latn";
|
|
157
|
+
if (system === "latn") return s;
|
|
158
|
+
return convertDigitsToAscii(s, system);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export {
|
|
162
|
+
tokenize,
|
|
163
|
+
SUPPORTED_NUMBERING_SYSTEMS,
|
|
164
|
+
convertDigits,
|
|
165
|
+
convertDigitsToAscii,
|
|
166
|
+
applyNumbering,
|
|
167
|
+
applyParseNumbering
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=chunk-M3GDTHMT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tokenize.ts","../src/numbering.ts"],"sourcesContent":["import { TOKENS } from './tokens.js';\nimport { FormatSyntaxError, UnknownTokenError } from './errors.js';\n\nexport type Piece =\n | { kind: 'token'; value: string }\n | { kind: 'literal'; value: string };\n\n// gotta sort longest-first or the greedy scan grabs \"M\" when \"MMMM\" was actually there\nconst SORTED_TOKEN_STRINGS = TOKENS.map(([tok]) => tok).sort((a, b) => b.length - a.length);\n\n/**\n * Splits a format string like `\"yyyy-MM-dd 'at' HH:mm\"` into token/literal\n * pieces. Text in single quotes is always literal (e.g. write 'rd' in\n * \"3rd\" so it's not read as the day token). A doubled quote ('') means a\n * literal quote character, both inside a quoted span and standalone.\n */\nexport function tokenize(format: string): Piece[] {\n const pieces: Piece[] = [];\n let i = 0;\n\n while (i < format.length) {\n const ch = format[i];\n\n if (ch === \"'\") {\n // gotta check the doubled-quote case first, otherwise \"''best''\" parses wrong\n if (format[i + 1] === \"'\") {\n appendLiteral(pieces, \"'\");\n i += 2;\n continue;\n }\n\n let j = i + 1;\n let literal = '';\n let closed = false;\n while (j < format.length) {\n if (format[j] === \"'\") {\n if (format[j + 1] === \"'\") {\n literal += \"'\";\n j += 2;\n continue;\n }\n closed = true;\n j += 1;\n break;\n }\n literal += format[j];\n j += 1;\n }\n\n if (!closed) {\n throw new FormatSyntaxError({\n format,\n message: `temporal-fmt: unterminated quote in format string \"${format}\"`,\n });\n }\n\n appendLiteral(pieces, literal);\n i = j;\n continue;\n }\n\n const match = SORTED_TOKEN_STRINGS.find((tok) => format.startsWith(tok, i));\n if (match) {\n // this is already the longest token that starts here, so if there's\n // one more of the same char after it, that's not a real token — it'd\n // just silently fall through to whatever handles that next char and\n // get glued onto this one. found this the hard way: \"zzzz\" was\n // parsing as zzz + literal \"z\", \"MMMMM\" as MMMM + the M token. so now\n // we just treat the whole overlong run as one bad token instead\n const runChar = match[match.length - 1];\n if (format[i + match.length] === runChar) {\n let end = i + match.length;\n while (format[end] === runChar) end += 1;\n // UnknownTokenError, not FormatSyntaxError: wrapUntypedError's\n // classifier already treats this exact message (\"isn't a\n // recognized token\") as UNKNOWN_TOKEN (see errors.test.js's\n // \"overlong token run classifies as UnknownTokenError\"), and a\n // direct throw here needs to agree with what safeParse's fallback\n // path would have classified it as.\n throw new UnknownTokenError({\n format,\n token: format.slice(i, end),\n message:\n `temporal-fmt: \"${format.slice(i, end)}\" in format string \"${format}\" isn't a recognized token — ` +\n `did you mean \"${match}\"?`,\n });\n }\n pieces.push({ kind: 'token', value: match });\n i += match.length;\n continue;\n }\n\n // not a token or quote — pass through as-is\n appendLiteral(pieces, ch);\n i += 1;\n }\n\n return pieces;\n}\n\n// merges into the previous piece if it's also a literal, so \"---\" is one\n// piece instead of three\nfunction appendLiteral(pieces: Piece[], value: string): void {\n const last = pieces[pieces.length - 1];\n if (last && last.kind === 'literal') {\n last.value += value;\n } else {\n pieces.push({ kind: 'literal', value });\n }\n}","// numbering systems. latn (ASCII digits) is the default, but arab, deva,\n// beng, etc are all options, configurable per format call.\n//\n// the tokens in this lib always spit out ASCII digits normally (check\n// tokens.ts's pad() — just String(n), which is ASCII). this module bolts\n// on the ability to convert that output to a locale's native digits via\n// Intl.NumberFormat, since that's the standard way JS does digit\n// transliteration anyway.\n//\n// parse side is stricter: parse() only accepts ASCII digits, matches how\n// NUMERIC_FRAGMENTS is already built. could add a parseNumberingSystem\n// option to convert input digits to ASCII first — but that should be an\n// explicit opt-in per call, not silently accepting any numeral system\n// that shows up\n\nimport { DEFAULT_LOCALE, type FormatOptions } from './tokens.js';\nimport { InvalidLocaleError } from './errors.js';\n\nexport type NumberingSystem = 'latn' | 'arab' | 'deva' | 'beng' | 'guru' | 'gujr' | 'orya' | 'tamldec' | 'telu' | 'knda' | 'mlym' | 'fullwide' | 'hanidec';\n\n// every NumberingSystem value we support. latn's the default and\n// what the rest of this lib naturally produces\nexport const SUPPORTED_NUMBERING_SYSTEMS: ReadonlySet<string> = new Set([\n 'latn', 'arab', 'deva', 'beng', 'guru', 'gujr', 'orya', 'tamldec',\n 'telu', 'knda', 'mlym', 'fullwide', 'hanidec',\n]);\n\nconst digitMapCache = new Map<string, Record<string, string>>();\n\n// builds a digit-transliteration map per numbering system. renders 0-9\n// through Intl.NumberFormat in the target system, then builds the lookup\n// table from that. caching it since spinning up a formatter isn't free\n// and we reuse the same map for every digit we convert\nfunction getDigitMap(system: string): Record<string, string> {\n let map = digitMapCache.get(system);\n if (map) return map;\n /* c8 ignore start @preserve -- this branch is dead by construction, not\n just untested: both callers (convertDigits, convertDigitsToAscii)\n already bail out early on system === 'latn' before ever calling\n getDigitMap, so it never actually gets invoked with 'latn'. keeping\n it anyway as a defensive fallback rather than betting that stays\n true forever */\n if (system === 'latn') {\n map = {};\n for (let i = 0; i < 10; i++) map[String(i)] = String(i);\n } else {\n /* c8 ignore stop @preserve */\n const fmt = new Intl.NumberFormat('en-US-u-nu-' + system, { useGrouping: false });\n map = {};\n for (let i = 0; i < 10; i++) {\n map[String(i)] = fmt.format(i);\n }\n }\n digitMapCache.set(system, map);\n return map;\n}\n\n// swaps every ASCII digit in `s` for its equivalent in the target\n// numbering system. anything that's not a digit passes through untouched\nexport function convertDigits(s: string, system: string): string {\n if (system === 'latn') return s;\n if (!SUPPORTED_NUMBERING_SYSTEMS.has(system)) {\n throw new InvalidLocaleError({ actual: system, reason: `numbering system \"${system}\" is not supported. Supported: ${[...SUPPORTED_NUMBERING_SYSTEMS].join(', ')}.` });\n }\n const map = getDigitMap(system);\n let result = '';\n for (const ch of s) {\n if (ch >= '0' && ch <= '9') {\n // map[ch] is always populated for 0-9 — getDigitMap builds all ten\n // keys for every system we support, and ch is already range-checked\n // above. the ?? ch is really just there to satisfy TS about Record's\n // implicit undefined, not because this path is actually reachable\n /* c8 ignore next */\n result += map[ch] ?? ch;\n } else {\n result += ch;\n }\n }\n return result;\n}\n\n// inverse of convertDigits — takes non-ASCII digits back to ASCII. used\n// by parse() when someone passes an explicit numberingSystem option.\n// throws on anything unsupported\nexport function convertDigitsToAscii(s: string, system: string): string {\n // same dead-by-construction thing as the 'latn' guard above —\n // applyParseNumbering (the only caller) already returns early on\n // 'latn' before this ever gets called, so system's never actually\n // 'latn' here in practice. leaving the guard anyway in case someone\n // calls this directly someday without going through that guard\n /* c8 ignore next */\n if (system === 'latn') return s;\n if (!SUPPORTED_NUMBERING_SYSTEMS.has(system)) {\n throw new InvalidLocaleError({ actual: system, reason: `numbering system \"${system}\" is not supported.` });\n }\n const map = getDigitMap(system);\n // just flip the map around\n const reverse: Record<string, string> = {};\n for (const k of Object.keys(map)) reverse[map[k]!] = k;\n let result = '';\n for (const ch of s) {\n result += reverse[ch] ?? ch;\n }\n return result;\n}\n\n// FormatOptions plus a numberingSystem field. pass { numberingSystem: 'arab' }\n// to format() to get Arabic-Indic digits out\nexport interface NumberingFormatOptions extends FormatOptions {\n numberingSystem?: string;\n}\n\n// same idea but for the parse side. called parseNumberingSystem instead of\n// just numberingSystem so someone mixing format() and parse() options in\n// one config object can set both independently — the two directions\n// aren't always symmetric (you might want native digits out without\n// wanting to accept them back in, or vice versa)\nexport interface NumberingParseOptions extends FormatOptions {\n parseNumberingSystem?: string;\n}\n\n// format-path helper: takes format()'s ASCII output and converts digits\n// if numberingSystem was asked for. lives here so format.ts doesn't need\n// to know anything about numbering systems\nexport function applyNumbering(s: string, options: NumberingFormatOptions): string {\n const system = options.numberingSystem ?? 'latn';\n if (system === 'latn') return s;\n return convertDigits(s, system);\n}\n\n// parse-path helper: converts input digits to ASCII before matching, if\n// parseNumberingSystem got set. kept as a separate option name from the\n// format side so callers can be explicit about which direction they\n// actually want transliterated\nexport function applyParseNumbering(s: string, options: { parseNumberingSystem?: string }): string {\n // both call sites for this (both in parse.ts) already guard with\n // `if (options.parseNumberingSystem)` before calling, so this is\n // always truthy in practice — the ?? 'latn' and the early return\n // below are dead by construction. leaving them in as a safety net\n // rather than betting every future caller replicates the same guard\n /* c8 ignore next 2 */\n const system = options.parseNumberingSystem ?? 'latn';\n if (system === 'latn') return s;\n return convertDigitsToAscii(s, system);\n}\n\n// this is just to stop TS complaining about an unused import — DEFAULT_LOCALE\n// is imported for the type augmentation pattern above. if this project\n// ever ships a typed-locale interface, that'll be the real source of truth\nvoid DEFAULT_LOCALE;"],"mappings":";;;;;;;;;;AAQA,IAAM,uBAAuB,OAAO,IAAI,CAAC,CAAC,GAAG,MAAM,GAAG,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM;AAQnF,SAAS,SAAS,QAAyB;AAChD,QAAM,SAAkB,CAAC;AACzB,MAAI,IAAI;AAER,SAAO,IAAI,OAAO,QAAQ;AACxB,UAAM,KAAK,OAAO,CAAC;AAEnB,QAAI,OAAO,KAAK;AAEd,UAAI,OAAO,IAAI,CAAC,MAAM,KAAK;AACzB,sBAAc,QAAQ,GAAG;AACzB,aAAK;AACL;AAAA,MACF;AAEA,UAAI,IAAI,IAAI;AACZ,UAAI,UAAU;AACd,UAAI,SAAS;AACb,aAAO,IAAI,OAAO,QAAQ;AACxB,YAAI,OAAO,CAAC,MAAM,KAAK;AACrB,cAAI,OAAO,IAAI,CAAC,MAAM,KAAK;AACzB,uBAAW;AACX,iBAAK;AACL;AAAA,UACF;AACA,mBAAS;AACT,eAAK;AACL;AAAA,QACF;AACA,mBAAW,OAAO,CAAC;AACnB,aAAK;AAAA,MACP;AAEA,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,kBAAkB;AAAA,UAC1B;AAAA,UACA,SAAS,sDAAsD,MAAM;AAAA,QACvE,CAAC;AAAA,MACH;AAEA,oBAAc,QAAQ,OAAO;AAC7B,UAAI;AACJ;AAAA,IACF;AAEA,UAAM,QAAQ,qBAAqB,KAAK,CAAC,QAAQ,OAAO,WAAW,KAAK,CAAC,CAAC;AAC1E,QAAI,OAAO;AAOT,YAAM,UAAU,MAAM,MAAM,SAAS,CAAC;AACtC,UAAI,OAAO,IAAI,MAAM,MAAM,MAAM,SAAS;AACx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