temporal-fmt 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/calendarUtils.cjs +4 -259
- package/dist/calendarUtils.cjs.map +1 -1
- package/dist/calendarUtils.js +1 -33
- package/dist/chunk-2JHEV7ZF.js +7 -0
- package/dist/chunk-2JHEV7ZF.js.map +1 -0
- package/dist/chunk-3MZLTVP3.js +2 -0
- package/dist/{chunk-MXXYIMFJ.js.map → chunk-3MZLTVP3.js.map} +1 -1
- package/dist/chunk-4JWGUR4O.js +11 -0
- package/dist/{chunk-AXQLUIDY.js.map → chunk-4JWGUR4O.js.map} +1 -1
- package/dist/chunk-5U5WJ465.js +36 -0
- package/dist/chunk-5U5WJ465.js.map +1 -0
- package/dist/chunk-C5YESWFT.js +2 -0
- package/dist/chunk-C5YESWFT.js.map +1 -0
- package/dist/chunk-C6ZZ62ET.js +2 -0
- package/dist/{chunk-YS52LOMJ.js.map → chunk-C6ZZ62ET.js.map} +1 -1
- package/dist/chunk-EHLRZULM.js +5 -0
- package/dist/{chunk-4ZBGVYLR.js.map → chunk-EHLRZULM.js.map} +1 -1
- package/dist/chunk-F4RGUDA3.js +2 -0
- package/dist/chunk-F4RGUDA3.js.map +1 -0
- package/dist/chunk-J2AQNXF2.js +2 -0
- package/dist/{chunk-GRJQHQLW.js.map → chunk-J2AQNXF2.js.map} +1 -1
- package/dist/chunk-NBXF7V5B.js +2 -0
- package/dist/chunk-NBXF7V5B.js.map +1 -0
- package/dist/chunk-R52YOKI3.js +7 -0
- package/dist/{chunk-M33NSC4E.js.map → chunk-R52YOKI3.js.map} +1 -1
- package/dist/chunk-UJR6DHXY.js +2 -0
- package/dist/chunk-UJR6DHXY.js.map +1 -0
- package/dist/chunk-VQXUMFB2.js +21 -0
- package/dist/{chunk-VHSZL3P3.js.map → chunk-VQXUMFB2.js.map} +1 -1
- package/dist/chunk-XH46JNPK.js +2 -0
- package/dist/chunk-XH46JNPK.js.map +1 -0
- package/dist/chunk-YB6YAG7E.js +35 -0
- package/dist/chunk-YB6YAG7E.js.map +1 -0
- package/dist/chunk-ZGMTY52O.js +2 -0
- package/dist/chunk-ZGMTY52O.js.map +1 -0
- package/dist/duration.cjs +9 -624
- package/dist/duration.cjs.map +1 -1
- package/dist/duration.js +1 -29
- package/dist/format.cjs +18 -769
- package/dist/format.cjs.map +1 -1
- package/dist/format.js +1 -20
- package/dist/formatDuration.d.cts +6 -0
- package/dist/formatDuration.d.ts +6 -0
- package/dist/index.cjs +146 -6672
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -3004
- package/dist/index.js.map +1 -1
- package/dist/interval.cjs +18 -952
- package/dist/interval.cjs.map +1 -1
- package/dist/interval.js +1 -41
- package/dist/localeRegistry.cjs +15 -328
- package/dist/localeRegistry.cjs.map +1 -1
- package/dist/localeRegistry.js +1 -11
- package/dist/localeVocab.d.cts +3 -0
- package/dist/localeVocab.d.ts +3 -0
- package/dist/parse.cjs +53 -1637
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.js +1 -20
- package/dist/parsePattern.d.cts +1 -0
- package/dist/parsePattern.d.ts +1 -0
- package/dist/pattern.d.cts +1 -0
- package/dist/pattern.d.ts +1 -0
- package/dist/recurrence.cjs +20 -450
- package/dist/recurrence.cjs.map +1 -1
- package/dist/recurrence.js +1 -20
- package/dist/relativeTime.cjs +24 -177
- package/dist/relativeTime.cjs.map +1 -1
- package/dist/relativeTime.js +1 -14
- package/dist/rounding.d.cts +1 -0
- package/dist/rounding.d.ts +1 -0
- package/dist/serialization.d.cts +1 -1
- package/dist/serialization.d.ts +1 -1
- package/dist/timezone.cjs +20 -387
- package/dist/timezone.cjs.map +1 -1
- package/dist/timezone.js +1 -26
- package/dist/typeGuards.d.cts +9 -9
- package/dist/typeGuards.d.ts +9 -9
- package/package.json +4 -2
- package/dist/chunk-4ZBGVYLR.js +0 -182
- package/dist/chunk-AXQLUIDY.js +0 -183
- package/dist/chunk-CKVHXFX7.js +0 -902
- package/dist/chunk-CKVHXFX7.js.map +0 -1
- package/dist/chunk-CSUIKL73.js +0 -215
- package/dist/chunk-CSUIKL73.js.map +0 -1
- package/dist/chunk-EDUFSRWJ.js +0 -9
- package/dist/chunk-EDUFSRWJ.js.map +0 -1
- package/dist/chunk-FQA4XJME.js +0 -57
- package/dist/chunk-FQA4XJME.js.map +0 -1
- package/dist/chunk-FTMLZ4EN.js +0 -196
- package/dist/chunk-FTMLZ4EN.js.map +0 -1
- package/dist/chunk-GRJQHQLW.js +0 -170
- package/dist/chunk-JCIMP43G.js +0 -602
- package/dist/chunk-JCIMP43G.js.map +0 -1
- package/dist/chunk-KDYK72Z2.js +0 -75
- package/dist/chunk-KDYK72Z2.js.map +0 -1
- package/dist/chunk-M33NSC4E.js +0 -169
- package/dist/chunk-MXXYIMFJ.js +0 -29
- package/dist/chunk-NFKQ3EXC.js +0 -188
- package/dist/chunk-NFKQ3EXC.js.map +0 -1
- package/dist/chunk-O6GVMBLW.js +0 -403
- package/dist/chunk-O6GVMBLW.js.map +0 -1
- package/dist/chunk-VHSZL3P3.js +0 -242
- package/dist/chunk-VSUCBUTC.js +0 -295
- package/dist/chunk-VSUCBUTC.js.map +0 -1
- package/dist/chunk-YS52LOMJ.js +0 -51
package/dist/chunk-AXQLUIDY.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
applyNumbering,
|
|
3
|
-
tokenize
|
|
4
|
-
} from "./chunk-M33NSC4E.js";
|
|
5
|
-
import {
|
|
6
|
-
DEFAULT_LOCALE,
|
|
7
|
-
TOKENS
|
|
8
|
-
} from "./chunk-VSUCBUTC.js";
|
|
9
|
-
import {
|
|
10
|
-
MAX_FORMAT_LENGTH
|
|
11
|
-
} from "./chunk-EDUFSRWJ.js";
|
|
12
|
-
import {
|
|
13
|
-
FormatSyntaxError,
|
|
14
|
-
UnknownTokenError
|
|
15
|
-
} from "./chunk-O6GVMBLW.js";
|
|
16
|
-
|
|
17
|
-
// src/format.ts
|
|
18
|
-
var HANDLER_BY_TOKEN = new Map(TOKENS.map(([tok, fn, field]) => [tok, { fn, field }]));
|
|
19
|
-
var tokenizeCache = /* @__PURE__ */ new Map();
|
|
20
|
-
var MAX_TOKENIZE_CACHE_SIZE = 500;
|
|
21
|
-
function getPieces(formatStr) {
|
|
22
|
-
let pieces = tokenizeCache.get(formatStr);
|
|
23
|
-
if (pieces) return pieces;
|
|
24
|
-
if (tokenizeCache.size >= MAX_TOKENIZE_CACHE_SIZE) {
|
|
25
|
-
const oldestKey = tokenizeCache.keys().next().value;
|
|
26
|
-
if (oldestKey !== void 0) tokenizeCache.delete(oldestKey);
|
|
27
|
-
}
|
|
28
|
-
pieces = tokenize(formatStr);
|
|
29
|
-
tokenizeCache.set(formatStr, pieces);
|
|
30
|
-
return pieces;
|
|
31
|
-
}
|
|
32
|
-
function format(temporal, formatStr, options = {}) {
|
|
33
|
-
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
34
|
-
throw new FormatSyntaxError({
|
|
35
|
-
format: formatStr,
|
|
36
|
-
message: `temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
40
|
-
const pieces = getPieces(formatStr);
|
|
41
|
-
let result = "";
|
|
42
|
-
for (const piece of pieces) {
|
|
43
|
-
if (piece.kind === "literal") {
|
|
44
|
-
result += piece.value;
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
const handler = HANDLER_BY_TOKEN.get(piece.value);
|
|
48
|
-
/* c8 ignore start @preserve -- unreachable: tokenize() only ever emits
|
|
49
|
-
tokens present in TOKENS, and HANDLER_BY_TOKEN is built from that
|
|
50
|
-
same list, so every token piece.value can hold already has an entry
|
|
51
|
-
here. Same defensive-guard category as the twin checks in
|
|
52
|
-
analyze.ts/formatDuration.ts. */
|
|
53
|
-
if (!handler) {
|
|
54
|
-
throw new UnknownTokenError({ token: piece.value, format: formatStr, message: `temporal-fmt: unknown token "${piece.value}"` });
|
|
55
|
-
}
|
|
56
|
-
/* c8 ignore stop @preserve */
|
|
57
|
-
if (temporal[handler.field] === void 0) {
|
|
58
|
-
throw new FormatSyntaxError({
|
|
59
|
-
format: formatStr,
|
|
60
|
-
token: piece.value,
|
|
61
|
-
message: `temporal-fmt: token "${piece.value}" requires "${handler.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
result += handler.fn(temporal, locale);
|
|
65
|
-
}
|
|
66
|
-
return applyNumbering(result, options);
|
|
67
|
-
}
|
|
68
|
-
function formatToParts(temporal, formatStr, options = {}) {
|
|
69
|
-
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
70
|
-
throw new FormatSyntaxError({
|
|
71
|
-
format: formatStr,
|
|
72
|
-
message: `temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
76
|
-
const pieces = getPieces(formatStr);
|
|
77
|
-
const result = [];
|
|
78
|
-
for (const piece of pieces) {
|
|
79
|
-
if (piece.kind === "literal") {
|
|
80
|
-
const last = result[result.length - 1];
|
|
81
|
-
/* c8 ignore start @preserve -- unreachable through tokenize()'s own
|
|
82
|
-
output: appendLiteral() in tokenize.ts already merges every
|
|
83
|
-
adjacent literal character before pieces ever reaches here, so
|
|
84
|
-
two 'literal' pieces never sit back-to-back in the array this
|
|
85
|
-
loop walks. Kept as defense-in-depth in case that invariant ever
|
|
86
|
-
changes upstream. */
|
|
87
|
-
if (last && last.type === "literal") {
|
|
88
|
-
last.value += piece.value;
|
|
89
|
-
} else {
|
|
90
|
-
/* c8 ignore stop @preserve */
|
|
91
|
-
result.push({ type: "literal", value: piece.value });
|
|
92
|
-
}
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
const handler = HANDLER_BY_TOKEN.get(piece.value);
|
|
96
|
-
/* c8 ignore start @preserve -- unreachable, see the note in format() above */
|
|
97
|
-
if (!handler) {
|
|
98
|
-
throw new UnknownTokenError({ token: piece.value, format: formatStr, message: `temporal-fmt: unknown token "${piece.value}"` });
|
|
99
|
-
}
|
|
100
|
-
/* c8 ignore stop @preserve */
|
|
101
|
-
if (temporal[handler.field] === void 0) {
|
|
102
|
-
throw new FormatSyntaxError({
|
|
103
|
-
format: formatStr,
|
|
104
|
-
token: piece.value,
|
|
105
|
-
message: `temporal-fmt: token "${piece.value}" requires "${handler.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
result.push({ type: "token", value: applyNumbering(handler.fn(temporal, locale), options), token: piece.value });
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
function compileFormat(formatStr) {
|
|
113
|
-
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
114
|
-
throw new FormatSyntaxError({
|
|
115
|
-
format: formatStr,
|
|
116
|
-
message: `temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
const pieces = getPieces(formatStr);
|
|
120
|
-
return {
|
|
121
|
-
formatStr,
|
|
122
|
-
pieces,
|
|
123
|
-
format(temporal, options = {}) {
|
|
124
|
-
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
125
|
-
let result = "";
|
|
126
|
-
for (const piece of pieces) {
|
|
127
|
-
if (piece.kind === "literal") {
|
|
128
|
-
result += piece.value;
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
const handler = HANDLER_BY_TOKEN.get(piece.value);
|
|
132
|
-
if (!handler) throw new UnknownTokenError({ token: piece.value, format: formatStr, message: `temporal-fmt: unknown token "${piece.value}"` });
|
|
133
|
-
if (temporal[handler.field] === void 0) {
|
|
134
|
-
throw new FormatSyntaxError({
|
|
135
|
-
format: formatStr,
|
|
136
|
-
token: piece.value,
|
|
137
|
-
message: `temporal-fmt: token "${piece.value}" requires "${handler.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
result += handler.fn(temporal, locale);
|
|
141
|
-
}
|
|
142
|
-
return applyNumbering(result, options);
|
|
143
|
-
},
|
|
144
|
-
formatToParts(temporal, options = {}) {
|
|
145
|
-
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
146
|
-
const out = [];
|
|
147
|
-
for (const piece of pieces) {
|
|
148
|
-
if (piece.kind === "literal") {
|
|
149
|
-
const last = out[out.length - 1];
|
|
150
|
-
if (last && last.type === "literal") last.value += piece.value;
|
|
151
|
-
else out.push({ type: "literal", value: piece.value });
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
const handler = HANDLER_BY_TOKEN.get(piece.value);
|
|
155
|
-
if (!handler) throw new UnknownTokenError({ token: piece.value, format: formatStr, message: `temporal-fmt: unknown token "${piece.value}"` });
|
|
156
|
-
if (temporal[handler.field] === void 0) {
|
|
157
|
-
throw new FormatSyntaxError({
|
|
158
|
-
format: formatStr,
|
|
159
|
-
token: piece.value,
|
|
160
|
-
message: `temporal-fmt: token "${piece.value}" requires "${handler.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
out.push({ type: "token", value: applyNumbering(handler.fn(temporal, locale), options), token: piece.value });
|
|
164
|
-
}
|
|
165
|
-
return out;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
function _getPieces(formatStr) {
|
|
170
|
-
return getPieces(formatStr);
|
|
171
|
-
}
|
|
172
|
-
function _handlerFor(token) {
|
|
173
|
-
return HANDLER_BY_TOKEN.get(token);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export {
|
|
177
|
-
format,
|
|
178
|
-
formatToParts,
|
|
179
|
-
compileFormat,
|
|
180
|
-
_getPieces,
|
|
181
|
-
_handlerFor
|
|
182
|
-
};
|
|
183
|
-
//# sourceMappingURL=chunk-AXQLUIDY.js.map
|