temporal-fmt 0.9.80 → 0.9.82
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 +302 -490
- package/dist/{chunk-Z245NHDT.js → chunk-4JMHI6E2.js} +6 -6
- package/dist/chunk-7XSIPXIR.js +129 -0
- package/dist/chunk-7XSIPXIR.js.map +1 -0
- package/dist/{chunk-DMJWJTFY.js → chunk-AF3LHBDQ.js} +2 -2
- package/dist/{chunk-WEVNKOQA.js → chunk-IEQCJPB5.js} +5 -5
- package/dist/{chunk-DFWTCRS3.js → chunk-JCJW2VOV.js} +10 -7
- package/dist/chunk-JCJW2VOV.js.map +1 -0
- package/dist/{chunk-HGRT37LT.js → chunk-KWOTFJNY.js} +3 -3
- package/dist/{chunk-64UB3WDT.js → chunk-NHNUFNQ7.js} +4 -4
- package/dist/{chunk-WP7TBCTT.js → chunk-TIMSK72I.js} +8 -8
- package/dist/{chunk-LHR5PCP4.js → chunk-UYKKGBZ3.js} +7 -7
- package/dist/{chunk-5KP5H7X2.js → chunk-W45J4E76.js} +6 -4
- package/dist/duration.js +3 -3
- package/dist/format.cjs +7 -4
- package/dist/format.cjs.map +1 -1
- package/dist/format.js +5 -5
- package/dist/index.cjs +147 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +108 -87
- package/dist/index.js.map +1 -1
- package/dist/interval.cjs +7 -4
- package/dist/interval.cjs.map +1 -1
- package/dist/interval.js +7 -7
- package/dist/legacy/index.d.cts +23 -0
- package/dist/legacy/index.d.ts +23 -0
- package/dist/legacy/matchesFormat.d.cts +6 -0
- package/dist/legacy/matchesFormat.d.ts +6 -0
- package/dist/legacy.cjs +2156 -0
- package/dist/legacy.cjs.map +1 -0
- package/dist/legacy.d.cts +1 -0
- package/dist/legacy.d.ts +1 -0
- package/dist/legacy.js +31 -0
- package/dist/legacy.js.map +1 -0
- package/dist/parse.cjs +7 -4
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.js +5 -5
- package/dist/relativeTime.cjs +6 -2
- package/dist/relativeTime.cjs.map +1 -1
- package/dist/relativeTime.js +4 -4
- package/dist/timezone.cjs +6 -2
- package/dist/timezone.cjs.map +1 -1
- package/dist/timezone.js +2 -2
- package/legacy.d.cts +1 -0
- package/legacy.d.ts +1 -0
- package/package.json +13 -1
- package/dist/chunk-DFWTCRS3.js.map +0 -1
- /package/dist/{chunk-Z245NHDT.js.map → chunk-4JMHI6E2.js.map} +0 -0
- /package/dist/{chunk-DMJWJTFY.js.map → chunk-AF3LHBDQ.js.map} +0 -0
- /package/dist/{chunk-WEVNKOQA.js.map → chunk-IEQCJPB5.js.map} +0 -0
- /package/dist/{chunk-HGRT37LT.js.map → chunk-KWOTFJNY.js.map} +0 -0
- /package/dist/{chunk-64UB3WDT.js.map → chunk-NHNUFNQ7.js.map} +0 -0
- /package/dist/{chunk-WP7TBCTT.js.map → chunk-TIMSK72I.js.map} +0 -0
- /package/dist/{chunk-LHR5PCP4.js.map → chunk-UYKKGBZ3.js.map} +0 -0
- /package/dist/{chunk-5KP5H7X2.js.map → chunk-W45J4E76.js.map} +0 -0
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getTemporal,
|
|
3
3
|
subscribeToTemporalChanges
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-JCJW2VOV.js";
|
|
5
|
+
import {
|
|
6
|
+
dayOfYear,
|
|
7
|
+
isoWeekYearAndWeek
|
|
8
|
+
} from "./chunk-BLZDBPSV.js";
|
|
5
9
|
import {
|
|
6
10
|
FormatSyntaxError,
|
|
7
11
|
InvalidLocaleError,
|
|
@@ -10,10 +14,6 @@ import {
|
|
|
10
14
|
normalizeLocaleTag,
|
|
11
15
|
partValue
|
|
12
16
|
} from "./chunk-QRLQ7RR7.js";
|
|
13
|
-
import {
|
|
14
|
-
dayOfYear,
|
|
15
|
-
isoWeekYearAndWeek
|
|
16
|
-
} from "./chunk-BLZDBPSV.js";
|
|
17
17
|
|
|
18
18
|
// src/tokens.ts
|
|
19
19
|
function requireFields(t, token, ...fields) {
|
|
@@ -364,4 +364,4 @@ export {
|
|
|
364
364
|
DEFAULT_LOCALE,
|
|
365
365
|
TOKENS
|
|
366
366
|
};
|
|
367
|
-
//# sourceMappingURL=chunk-
|
|
367
|
+
//# sourceMappingURL=chunk-4JMHI6E2.js.map
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compileFormat,
|
|
3
|
+
format,
|
|
4
|
+
formatToParts
|
|
5
|
+
} from "./chunk-KWOTFJNY.js";
|
|
6
|
+
import {
|
|
7
|
+
buildCapturingPattern,
|
|
8
|
+
compileParser,
|
|
9
|
+
enumerateValidSplits,
|
|
10
|
+
parse,
|
|
11
|
+
parseToParts,
|
|
12
|
+
safeParse,
|
|
13
|
+
tryParse
|
|
14
|
+
} from "./chunk-W45J4E76.js";
|
|
15
|
+
import {
|
|
16
|
+
tokenize
|
|
17
|
+
} from "./chunk-AF3LHBDQ.js";
|
|
18
|
+
import {
|
|
19
|
+
DEFAULT_LOCALE
|
|
20
|
+
} from "./chunk-4JMHI6E2.js";
|
|
21
|
+
import {
|
|
22
|
+
MAX_FORMAT_LENGTH
|
|
23
|
+
} from "./chunk-SOPTTXUI.js";
|
|
24
|
+
import {
|
|
25
|
+
TemporalFmtError
|
|
26
|
+
} from "./chunk-QRLQ7RR7.js";
|
|
27
|
+
|
|
28
|
+
// src/legacy/matchesFormat.ts
|
|
29
|
+
var patternCache = /* @__PURE__ */ new Map();
|
|
30
|
+
var MAX_CACHE_SIZE = 500;
|
|
31
|
+
function getPattern(formatStr, locale) {
|
|
32
|
+
const key = locale + "\0" + formatStr;
|
|
33
|
+
const cached = patternCache.get(key);
|
|
34
|
+
if (cached) return cached;
|
|
35
|
+
if (patternCache.size >= MAX_CACHE_SIZE) {
|
|
36
|
+
const oldestKey = patternCache.keys().next().value;
|
|
37
|
+
if (oldestKey !== void 0) patternCache.delete(oldestKey);
|
|
38
|
+
}
|
|
39
|
+
const pattern = buildCapturingPattern(tokenize(formatStr), locale);
|
|
40
|
+
patternCache.set(key, pattern);
|
|
41
|
+
return pattern;
|
|
42
|
+
}
|
|
43
|
+
function matchesFormat(formatStr, input, options = {}) {
|
|
44
|
+
try {
|
|
45
|
+
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
51
|
+
const pattern = getPattern(formatStr, locale);
|
|
52
|
+
const match = pattern.regex.exec(input);
|
|
53
|
+
if (!match) return false;
|
|
54
|
+
for (const run of pattern.ambiguousRuns) {
|
|
55
|
+
const range = match.indices?.groups?.[run.groupName];
|
|
56
|
+
if (!range || enumerateValidSplits(input.slice(range[0], range[1]), run.tokens).length === 0) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (error instanceof TemporalFmtError) throw new Error(error.message);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/legacy/index.ts
|
|
68
|
+
function withLegacyErrors(operation) {
|
|
69
|
+
try {
|
|
70
|
+
return operation();
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (error instanceof TemporalFmtError) {
|
|
73
|
+
throw new Error(error.message);
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function toLegacySafeParseResult(result) {
|
|
79
|
+
return result.ok ? result : { ok: false, error: new Error(result.error.message) };
|
|
80
|
+
}
|
|
81
|
+
function format2(temporal, formatStr, options = {}) {
|
|
82
|
+
return withLegacyErrors(() => format(temporal, formatStr, options));
|
|
83
|
+
}
|
|
84
|
+
function formatToParts2(temporal, formatStr, options = {}) {
|
|
85
|
+
return withLegacyErrors(() => formatToParts(temporal, formatStr, options));
|
|
86
|
+
}
|
|
87
|
+
function compileFormat2(formatStr) {
|
|
88
|
+
const compiled = withLegacyErrors(() => compileFormat(formatStr));
|
|
89
|
+
return {
|
|
90
|
+
...compiled,
|
|
91
|
+
format: (temporal, options) => withLegacyErrors(() => compiled.format(temporal, options)),
|
|
92
|
+
formatToParts: (temporal, options) => withLegacyErrors(() => compiled.formatToParts(temporal, options))
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function parse2(formatStr, input, options = {}) {
|
|
96
|
+
return withLegacyErrors(() => parse(formatStr, input, options));
|
|
97
|
+
}
|
|
98
|
+
function safeParse2(formatStr, input, options = {}) {
|
|
99
|
+
return toLegacySafeParseResult(safeParse(formatStr, input, options));
|
|
100
|
+
}
|
|
101
|
+
function tryParse2(formatStr, input, options = {}) {
|
|
102
|
+
return tryParse(formatStr, input, options);
|
|
103
|
+
}
|
|
104
|
+
function parseToParts2(formatStr, input, options = {}) {
|
|
105
|
+
return withLegacyErrors(() => parseToParts(formatStr, input, options));
|
|
106
|
+
}
|
|
107
|
+
function compileParser2(formatStr, options = {}) {
|
|
108
|
+
const compiled = withLegacyErrors(() => compileParser(formatStr, options));
|
|
109
|
+
return {
|
|
110
|
+
...compiled,
|
|
111
|
+
parse: (input, callOptions) => withLegacyErrors(() => compiled.parse(input, callOptions)),
|
|
112
|
+
safeParse: (input, callOptions) => toLegacySafeParseResult(compiled.safeParse(input, callOptions)),
|
|
113
|
+
tryParse: (input, callOptions) => compiled.tryParse(input, callOptions),
|
|
114
|
+
parseToParts: (input, callOptions) => withLegacyErrors(() => compiled.parseToParts(input, callOptions))
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export {
|
|
119
|
+
matchesFormat,
|
|
120
|
+
format2 as format,
|
|
121
|
+
formatToParts2 as formatToParts,
|
|
122
|
+
compileFormat2 as compileFormat,
|
|
123
|
+
parse2 as parse,
|
|
124
|
+
safeParse2 as safeParse,
|
|
125
|
+
tryParse2 as tryParse,
|
|
126
|
+
parseToParts2 as parseToParts,
|
|
127
|
+
compileParser2 as compileParser
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=chunk-7XSIPXIR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/legacy/matchesFormat.ts","../src/legacy/index.ts"],"sourcesContent":["/*\n * Copyright 2026 DirazCoder\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DEFAULT_LOCALE, type FormatOptions } from '../tokens.js';\nimport { tokenize } from '../tokenize.js';\nimport { buildCapturingPattern, type CapturingPattern } from '../parsePattern.js';\nimport { MAX_FORMAT_LENGTH } from '../constants.js';\nimport { TemporalFmtError } from '../errors.js';\nimport { enumerateValidSplits } from '../pattern.js';\n\nconst patternCache = new Map<string, CapturingPattern>();\nconst MAX_CACHE_SIZE = 500;\n\nfunction getPattern(formatStr: string, locale: string) {\n const key = locale + '\\0' + formatStr;\n const cached = patternCache.get(key);\n if (cached) return cached;\n\n if (patternCache.size >= MAX_CACHE_SIZE) {\n const oldestKey = patternCache.keys().next().value;\n if (oldestKey !== undefined) patternCache.delete(oldestKey);\n }\n\n const pattern = buildCapturingPattern(tokenize(formatStr), locale);\n patternCache.set(key, pattern);\n return pattern;\n}\n\n/**\n * Checks whether `input` could plausibly be output from `format()` for the\n * given format. It checks shape and locale vocabulary, not date validity.\n */\nexport function matchesFormat(formatStr: string, input: string, options: FormatOptions = {}): boolean {\n try {\n if (formatStr.length > MAX_FORMAT_LENGTH) {\n throw new Error(\n `temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters ` +\n `(got ${formatStr.length}).`,\n );\n }\n const locale = options.locale ?? DEFAULT_LOCALE;\n const pattern = getPattern(formatStr, locale);\n const match = pattern.regex.exec(input);\n if (!match) return false;\n\n for (const run of pattern.ambiguousRuns) {\n const range = match.indices?.groups?.[run.groupName];\n if (!range || enumerateValidSplits(input.slice(range[0], range[1]), run.tokens).length === 0) {\n return false;\n }\n }\n return true;\n } catch (error) {\n if (error instanceof TemporalFmtError) throw new Error(error.message);\n throw error;\n }\n}\n","/*\n * Copyright 2026 DirazCoder\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n format as typedFormat,\n formatToParts as typedFormatToParts,\n compileFormat as typedCompileFormat,\n type CompiledFormat,\n type FormattedPart,\n} from '../format.js';\nimport {\n parse as typedParse,\n safeParse as typedSafeParse,\n tryParse as typedTryParse,\n parseToParts as typedParseToParts,\n compileParser as typedCompileParser,\n type CompiledParser,\n type ParsedPart,\n} from '../parse.js';\nimport type { TemporalLike } from '../tokens.js';\nimport type { NumberingFormatOptions, NumberingParseOptions } from '../numbering.js';\nimport { TemporalFmtError } from '../errors.js';\n\nexport type LegacySafeParseResult =\n | { ok: true; value: unknown }\n | { ok: false; error: Error };\n\nexport type LegacyCompiledParser = Omit<CompiledParser, 'safeParse'> & {\n safeParse(input: string, options?: NumberingParseOptions): LegacySafeParseResult;\n};\n\nfunction withLegacyErrors<T>(operation: () => T): T {\n try {\n return operation();\n } catch (error) {\n if (error instanceof TemporalFmtError) {\n throw new Error(error.message);\n }\n throw error;\n }\n}\n\nfunction toLegacySafeParseResult(result: ReturnType<typeof typedSafeParse>): LegacySafeParseResult {\n return result.ok\n ? result\n : { ok: false, error: new Error(result.error.message) };\n}\n\nexport function format(\n temporal: TemporalLike,\n formatStr: string,\n options: NumberingFormatOptions = {},\n): string {\n return withLegacyErrors(() => typedFormat(temporal, formatStr, options));\n}\n\nexport function formatToParts(\n temporal: TemporalLike,\n formatStr: string,\n options: NumberingFormatOptions = {},\n): FormattedPart[] {\n return withLegacyErrors(() => typedFormatToParts(temporal, formatStr, options));\n}\n\nexport function compileFormat(formatStr: string): CompiledFormat {\n const compiled = withLegacyErrors(() => typedCompileFormat(formatStr));\n return {\n ...compiled,\n format: (temporal, options) => withLegacyErrors(() => compiled.format(temporal, options)),\n formatToParts: (temporal, options) => withLegacyErrors(() => compiled.formatToParts(temporal, options)),\n };\n}\n\nexport function parse(formatStr: string, input: string, options: NumberingParseOptions = {}): unknown | undefined {\n return withLegacyErrors(() => typedParse(formatStr, input, options));\n}\n\nexport function safeParse(\n formatStr: string,\n input: string,\n options: NumberingParseOptions = {},\n): LegacySafeParseResult {\n return toLegacySafeParseResult(typedSafeParse(formatStr, input, options));\n}\n\nexport function tryParse(formatStr: string, input: string, options: NumberingParseOptions = {}): unknown | undefined {\n return typedTryParse(formatStr, input, options);\n}\n\nexport function parseToParts(\n formatStr: string,\n input: string,\n options: NumberingParseOptions = {},\n): ParsedPart[] {\n return withLegacyErrors(() => typedParseToParts(formatStr, input, options));\n}\n\nexport function compileParser(formatStr: string, options: NumberingParseOptions = {}): LegacyCompiledParser {\n const compiled = withLegacyErrors(() => typedCompileParser(formatStr, options));\n return {\n ...compiled,\n parse: (input, callOptions) => withLegacyErrors(() => compiled.parse(input, callOptions)),\n safeParse: (input, callOptions) => toLegacySafeParseResult(compiled.safeParse(input, callOptions)),\n tryParse: (input, callOptions) => compiled.tryParse(input, callOptions),\n parseToParts: (input, callOptions) => withLegacy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,UAAiC,CAAC,GAAyB;AAC1G,QAAM,WAAW,iBAAiB,MAAM,cAAmB,WAAW,OAAO,CAAC;AAC9E,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,CAAC,OAAO,gBAAgB,iBAAiB,MAAM,SAAS,MAAM,OAAO,WAAW,CAAC;AAAA,IACxF,WAAW,CAAC,OAAO,gBAAgB,wBAAwB,SAAS,UAAU,OAAO,WAAW,CAAC;AAAA,IACjG,UAAU,CAAC,OAAO,gBAAgB,SAAS,SAAS,OAAO,WAAW;AAAA,IACtE,cAAc,CAAC,OAAO,gBAAgB,iBAAiB,MAAM,SAAS,aAAa,OAAO,WAAW,CAAC;AAAA,EACxG;AACF;","names":["format","formatToParts","compileFormat","parse","safeParse","tryParse","parseToParts","compileParser"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_LOCALE,
|
|
3
3
|
TOKENS
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4JMHI6E2.js";
|
|
5
5
|
import {
|
|
6
6
|
FormatSyntaxError,
|
|
7
7
|
InvalidLocaleError,
|
|
@@ -199,4 +199,4 @@ export {
|
|
|
199
199
|
applyNumbering,
|
|
200
200
|
applyParseNumbering
|
|
201
201
|
};
|
|
202
|
-
//# sourceMappingURL=chunk-
|
|
202
|
+
//# sourceMappingURL=chunk-AF3LHBDQ.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
differenceInDays
|
|
3
|
+
} from "./chunk-SC6ENLEB.js";
|
|
1
4
|
import {
|
|
2
5
|
DEFAULT_LOCALE
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4JMHI6E2.js";
|
|
4
7
|
import {
|
|
5
8
|
InvalidLocaleError,
|
|
6
9
|
normalizeLocaleTag
|
|
7
10
|
} from "./chunk-QRLQ7RR7.js";
|
|
8
|
-
import {
|
|
9
|
-
differenceInDays
|
|
10
|
-
} from "./chunk-SC6ENLEB.js";
|
|
11
11
|
|
|
12
12
|
// src/relativeTime.ts
|
|
13
13
|
var rtfCache = /* @__PURE__ */ new Map();
|
|
@@ -62,4 +62,4 @@ export {
|
|
|
62
62
|
formatRelative,
|
|
63
63
|
formatRelativeToNow
|
|
64
64
|
};
|
|
65
|
-
//# sourceMappingURL=chunk-
|
|
65
|
+
//# sourceMappingURL=chunk-IEQCJPB5.js.map
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
// src/temporalProvider.ts
|
|
2
|
-
var
|
|
3
|
-
var
|
|
2
|
+
var TEMPORAL_PROVIDER_STATE = /* @__PURE__ */ Symbol.for("temporal-fmt.temporal-provider");
|
|
3
|
+
var globalState = globalThis;
|
|
4
|
+
var providerState = globalState[TEMPORAL_PROVIDER_STATE] ??= {
|
|
5
|
+
onTemporalChanged: []
|
|
6
|
+
};
|
|
4
7
|
function subscribeToTemporalChanges(listener) {
|
|
5
|
-
onTemporalChanged.push(listener);
|
|
8
|
+
providerState.onTemporalChanged.push(listener);
|
|
6
9
|
}
|
|
7
10
|
function setTemporal(temporal) {
|
|
8
|
-
injectedTemporal = temporal;
|
|
9
|
-
for (const listener of onTemporalChanged) listener();
|
|
11
|
+
providerState.injectedTemporal = temporal;
|
|
12
|
+
for (const listener of providerState.onTemporalChanged) listener();
|
|
10
13
|
}
|
|
11
14
|
function resolveTemporal() {
|
|
12
|
-
return injectedTemporal ?? globalThis.Temporal;
|
|
15
|
+
return providerState.injectedTemporal ?? globalThis.Temporal;
|
|
13
16
|
}
|
|
14
17
|
function getTemporal() {
|
|
15
18
|
const temporal = resolveTemporal();
|
|
@@ -26,4 +29,4 @@ export {
|
|
|
26
29
|
setTemporal,
|
|
27
30
|
getTemporal
|
|
28
31
|
};
|
|
29
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-JCJW2VOV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/temporalProvider.ts"],"sourcesContent":["/*\n * Copyright 2026 DirazCoder\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// tsconfig here is lib: [\"ESNext\"] only, so there's no ambient Temporal\n// namespace type to lean on. everywhere else in the codebase we just read\n// fields off whatever Temporal-like object gets passed in (see TemporalLike\n// in tokens.ts) but this file is the one place that actually touches the\n// Temporal namespace itself — PlainDate.from and friends. parse() uses it\n// to build results, tokens.ts uses it to check native Intl<->Temporal\n// support. you can hand us your own implementation via setTemporal(), or\n// we just grab globalThis.Temporal if there is one\ninterface TemporalFactory {\n from(fields: Record<string, number | string | undefined>, options?: { overflow?: 'constrain' | 'reject'; disambiguation?: 'compatible' | 'earlier' | 'later' | 'reject'; offset?: 'use' | 'ignore' | 'prefer' | 'reject' }): unknown;\n // compare() is on the namespace, not instances (Temporal.PlainDate.compare).\n // made optional since someone might hand us a stripped-down shim that\n // doesn't bother implementing it\n compare?(one: unknown, two: unknown): number;\n}\n\n// Instant doesn't use from(fields) like the others, it's\n// fromEpochMilliseconds / fromEpochNanoseconds. needs its own shape.\ninterface InstantFactory {\n from(iso: string): unknown;\n fromEpochMilliseconds(ms: number): unknown;\n fromEpochMicroseconds(µs: number): unknown;\n fromEpochNanoseconds(ns: bigint): unknown;\n}\n\n// Duration uses from(fields) too, but also has round() and compare()\ninterface DurationFactory extends TemporalFactory {\n compare?(one: unknown, two: unknown): number;\n prototype?: { round(options: unknown): unknown };\n}\n\n// PlainYearMonth / PlainMonthDay also just use from(fields) — same shape\n// as TemporalFactory really, kept as its own type so callers can narrow\nexport interface TemporalNamespace {\n PlainDate: TemporalFactory;\n PlainTime: TemporalFactory;\n PlainDateTime: TemporalFactory;\n ZonedDateTime: TemporalFactory;\n Instant?: InstantFactory;\n Duration?: DurationFactory;\n PlainYearMonth?: TemporalFactory;\n PlainMonthDay?: TemporalFactory;\n}\n\ninterface TemporalProviderState {\n injectedTemporal?: TemporalNamespace;\n onTemporalChanged: Array<() => void>;\n}\n\nconst TEMPORAL_PROVIDER_STATE = Symbol.for('temporal-fmt.temporal-provider');\nconst globalState = globalThis as unknown as Record<symbol, unknown>;\nconst providerState = (globalState[TEMPORAL_PROVIDER_STATE] ??= {\n onTemporalChanged: [],\n}) as TemporalProviderState;\n\n// anything caching something tied to WHICH Temporal impl is active\n// (right now just tokens.ts's native-Intl probe) registers a listener\n// here so it knows to invalidate when setTemporal() swaps things out —\n// see setTemporal() below for why that matters. kept this as a plain\n// array instead of a full event emitter since all we need is \"call\n// everyone back, in order, no payload\" — didn't need unsubscribe either\nexport function subscribeToTemporalChanges(listener: () => void): void {\n providerState.onTemporalChanged.push(listener);\n}\n\n/**\n * Explicitly hand temporal-fmt the Temporal implementation to use, instead\n * of relying on a global `Temporal`. Call this once, before your first\n * `format()`/`parse()`/`parseISO()`/etc.\n *\n * Call with no argument (or `undefined`) to clear the override and fall\n * back to `globalThis.Temporal` again.\n *\n * @example\n * import { Temporal } from 'temporal-polyfill';\n * import { setTemporal } from 'temporal-fmt';\n * setTemporal(Temporal);\n */\nexport function setTemporal(temporal?: TemporalNamespace): void {\n providerState.injectedTemporal = temporal;\n // tokens.ts caches its native-Intl probe result based on whatever\n // Temporal was active the first time it ran. if that changes later\n // (native -> polyfill, say) the cached result goes stale. so just reset\n // everyone on any setTemporal() call — costs one extra probe re-run,\n // worth it to not silently use a stale answer\n for (const listener of providerState.onTemporalChanged) listener();\n}\n\nfunction resolveTemporal(): TemporalNamespace | undefined {\n return providerState.injectedTemporal ?? (globalThis as unknown as { Temporal?: TemporalNamespace }).Temporal;\n}\n\nexport function getTemporal(): TemporalNamespace {\n const temporal = resolveTemporal();\n if (!temporal) {\n throw new Error(\n 'temporal-fmt: parse() needs a Temporal implementation to construct its result. ' +\n 'Call setTemporal(Temporal) once at startup, or assign one to globalThis.Temporal ' +\n '(native on Node 26+, or a polyfill like temporal-polyfill).'\n );\n }\n return temporal;\n}\n"],"mappings":";AAiEA,IAAM,0BAA0B,uBAAO,IAAI,gCAAgC;AAC3E,IAAM,cAAc;AACpB,IAAM,gBAAiB,YAAY,uBAAuB,MAAM;AAAA,EAC9D,mBAAmB,CAAC;AACtB;AAQO,SAAS,2BAA2B,UAA4B;AACrE,gBAAc,kBAAkB,KAAK,QAAQ;AAC/C;AAeO,SAAS,YAAY,UAAoC;AAC9D,gBAAc,mBAAmB;AAMjC,aAAW,YAAY,cAAc,kBAAmB,UAAS;AACnE;AAEA,SAAS,kBAAiD;AACxD,SAAO,cAAc,oBAAqB,WAA2D;AACvG;AAEO,SAAS,cAAiC;AAC/C,QAAM,WAAW,gBAAgB;AACjC,MAAI,CAAC,UAAU;AACb,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyNumbering,
|
|
3
3
|
tokenize
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-AF3LHBDQ.js";
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_LOCALE,
|
|
7
7
|
TOKENS
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-4JMHI6E2.js";
|
|
9
9
|
import {
|
|
10
10
|
MAX_FORMAT_LENGTH
|
|
11
11
|
} from "./chunk-SOPTTXUI.js";
|
|
@@ -189,4 +189,4 @@ export {
|
|
|
189
189
|
_getPieces,
|
|
190
190
|
_handlerFor
|
|
191
191
|
};
|
|
192
|
-
//# sourceMappingURL=chunk-
|
|
192
|
+
//# sourceMappingURL=chunk-KWOTFJNY.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getTemporal
|
|
3
|
-
} from "./chunk-DFWTCRS3.js";
|
|
4
1
|
import {
|
|
5
2
|
add
|
|
6
3
|
} from "./chunk-SC6ENLEB.js";
|
|
4
|
+
import {
|
|
5
|
+
getTemporal
|
|
6
|
+
} from "./chunk-JCJW2VOV.js";
|
|
7
7
|
|
|
8
8
|
// src/timezone.ts
|
|
9
9
|
function resolveZoned(fields, timeZone, options = {}) {
|
|
@@ -232,4 +232,4 @@ export {
|
|
|
232
232
|
getTransitions,
|
|
233
233
|
possibleInstantsFor
|
|
234
234
|
};
|
|
235
|
-
//# sourceMappingURL=chunk-
|
|
235
|
+
//# sourceMappingURL=chunk-NHNUFNQ7.js.map
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
format,
|
|
3
|
-
formatToParts
|
|
4
|
-
} from "./chunk-HGRT37LT.js";
|
|
5
|
-
import {
|
|
6
|
-
normalizeLocaleTag
|
|
7
|
-
} from "./chunk-QRLQ7RR7.js";
|
|
8
1
|
import {
|
|
9
2
|
compare
|
|
10
3
|
} from "./chunk-UGYSEYUQ.js";
|
|
11
4
|
import {
|
|
12
5
|
asDateFieldView
|
|
13
6
|
} from "./chunk-KEPIXQK7.js";
|
|
7
|
+
import {
|
|
8
|
+
format,
|
|
9
|
+
formatToParts
|
|
10
|
+
} from "./chunk-KWOTFJNY.js";
|
|
14
11
|
import {
|
|
15
12
|
daysFromCivil
|
|
16
13
|
} from "./chunk-BLZDBPSV.js";
|
|
14
|
+
import {
|
|
15
|
+
normalizeLocaleTag
|
|
16
|
+
} from "./chunk-QRLQ7RR7.js";
|
|
17
17
|
|
|
18
18
|
// src/interval.ts
|
|
19
19
|
function interval(start, end, bounds = "closed") {
|
|
@@ -238,4 +238,4 @@ export {
|
|
|
238
238
|
formatRange,
|
|
239
239
|
formatRangeToParts
|
|
240
240
|
};
|
|
241
|
-
//# sourceMappingURL=chunk-
|
|
241
|
+
//# sourceMappingURL=chunk-TIMSK72I.js.map
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
asDateFieldView
|
|
3
|
+
} from "./chunk-KEPIXQK7.js";
|
|
1
4
|
import {
|
|
2
5
|
MAX_FORMAT_LENGTH
|
|
3
6
|
} from "./chunk-SOPTTXUI.js";
|
|
7
|
+
import {
|
|
8
|
+
daysFromCivil
|
|
9
|
+
} from "./chunk-BLZDBPSV.js";
|
|
4
10
|
import {
|
|
5
11
|
FormatSyntaxError,
|
|
6
12
|
InvalidDurationError,
|
|
@@ -8,12 +14,6 @@ import {
|
|
|
8
14
|
canonicalCacheKey,
|
|
9
15
|
normalizeLocaleTag
|
|
10
16
|
} from "./chunk-QRLQ7RR7.js";
|
|
11
|
-
import {
|
|
12
|
-
asDateFieldView
|
|
13
|
-
} from "./chunk-KEPIXQK7.js";
|
|
14
|
-
import {
|
|
15
|
-
daysFromCivil
|
|
16
|
-
} from "./chunk-BLZDBPSV.js";
|
|
17
17
|
|
|
18
18
|
// src/rounding.ts
|
|
19
19
|
var MS_PER_UNIT = {
|
|
@@ -578,4 +578,4 @@ export {
|
|
|
578
578
|
addDuration,
|
|
579
579
|
subtractDuration
|
|
580
580
|
};
|
|
581
|
-
//# sourceMappingURL=chunk-
|
|
581
|
+
//# sourceMappingURL=chunk-UYKKGBZ3.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyParseNumbering,
|
|
3
3
|
tokenize
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-AF3LHBDQ.js";
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_LOCALE
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4JMHI6E2.js";
|
|
8
8
|
import {
|
|
9
9
|
getTemporal
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-JCJW2VOV.js";
|
|
11
11
|
import {
|
|
12
12
|
MAX_FORMAT_LENGTH,
|
|
13
13
|
MAX_INPUT_LENGTH
|
|
@@ -975,10 +975,12 @@ function compileParser(formatStr, options = {}) {
|
|
|
975
975
|
export {
|
|
976
976
|
FORMAT_ONLY_TOKENS,
|
|
977
977
|
UNPADDED_NUMERIC_TOKENS,
|
|
978
|
+
enumerateValidSplits,
|
|
979
|
+
buildCapturingPattern,
|
|
978
980
|
parse,
|
|
979
981
|
safeParse,
|
|
980
982
|
tryParse,
|
|
981
983
|
parseToParts,
|
|
982
984
|
compileParser
|
|
983
985
|
};
|
|
984
|
-
//# sourceMappingURL=chunk-
|
|
986
|
+
//# sourceMappingURL=chunk-W45J4E76.js.map
|
package/dist/duration.js
CHANGED
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
roundDuration,
|
|
10
10
|
subtractDuration,
|
|
11
11
|
totalDuration
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-SOPTTXUI.js";
|
|
14
|
-
import "./chunk-QRLQ7RR7.js";
|
|
12
|
+
} from "./chunk-UYKKGBZ3.js";
|
|
15
13
|
import "./chunk-KEPIXQK7.js";
|
|
14
|
+
import "./chunk-SOPTTXUI.js";
|
|
16
15
|
import "./chunk-BLZDBPSV.js";
|
|
16
|
+
import "./chunk-QRLQ7RR7.js";
|
|
17
17
|
export {
|
|
18
18
|
addDuration,
|
|
19
19
|
balanceDuration,
|
package/dist/format.cjs
CHANGED
|
@@ -29,13 +29,16 @@ __export(format_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(format_exports);
|
|
30
30
|
|
|
31
31
|
// src/temporalProvider.ts
|
|
32
|
-
var
|
|
33
|
-
var
|
|
32
|
+
var TEMPORAL_PROVIDER_STATE = /* @__PURE__ */ Symbol.for("temporal-fmt.temporal-provider");
|
|
33
|
+
var globalState = globalThis;
|
|
34
|
+
var providerState = globalState[TEMPORAL_PROVIDER_STATE] ??= {
|
|
35
|
+
onTemporalChanged: []
|
|
36
|
+
};
|
|
34
37
|
function subscribeToTemporalChanges(listener) {
|
|
35
|
-
onTemporalChanged.push(listener);
|
|
38
|
+
providerState.onTemporalChanged.push(listener);
|
|
36
39
|
}
|
|
37
40
|
function resolveTemporal() {
|
|
38
|
-
return injectedTemporal ?? globalThis.Temporal;
|
|
41
|
+
return providerState.injectedTemporal ?? globalThis.Temporal;
|
|
39
42
|
}
|
|
40
43
|
function getTemporal() {
|
|
41
44
|
const temporal = resolveTemporal();
|