@sanity/util 6.7.0-next.27 → 6.7.0-next.3
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/lib/client.d.ts +1 -2
- package/lib/client.js +62 -48
- package/lib/client.js.map +1 -1
- package/lib/concurrency-limiter.d.ts +1 -2
- package/lib/concurrency-limiter.js +32 -2
- package/lib/concurrency-limiter.js.map +1 -0
- package/lib/content.d.ts +1 -2
- package/lib/content.js +69 -56
- package/lib/content.js.map +1 -1
- package/lib/createSafeJsonParser.cjs +20 -0
- package/lib/createSafeJsonParser.cjs.map +1 -0
- package/lib/createSafeJsonParser.d.cts +14 -0
- package/lib/createSafeJsonParser.d.ts +1 -2
- package/lib/createSafeJsonParser.js +18 -21
- package/lib/createSafeJsonParser.js.map +1 -1
- package/lib/fs.d.ts +1 -2
- package/lib/fs.js +22 -17
- package/lib/fs.js.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/legacyDateFormat.d.ts +1 -2
- package/lib/legacyDateFormat.js +255 -407
- package/lib/legacyDateFormat.js.map +1 -1
- package/lib/paths.d.ts +1 -2
- package/lib/paths.js +114 -92
- package/lib/paths.js.map +1 -1
- package/package.json +16 -10
- package/lib/concurrency-limiter-C6gDjN0m.js +0 -35
- package/lib/concurrency-limiter-C6gDjN0m.js.map +0 -1
package/lib/legacyDateFormat.js
CHANGED
|
@@ -5,443 +5,291 @@ import { parseISO } from "date-fns/parseISO";
|
|
|
5
5
|
import { format as format$1 } from "date-fns/format";
|
|
6
6
|
const sanitizeLocale = (locale) => locale.replace(/@posix$/, "");
|
|
7
7
|
function getMonthName(date, style = "long", locale = "en-US") {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const validLocale = sanitizeLocale(locale);
|
|
9
|
+
return new Intl.DateTimeFormat(validLocale, { month: style }).format(date);
|
|
10
10
|
}
|
|
11
11
|
function getDayName(date, style = "long", locale = "en-US") {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const validLocale = sanitizeLocale(locale);
|
|
13
|
+
return new Intl.DateTimeFormat(validLocale, { weekday: style }).format(date);
|
|
14
14
|
}
|
|
15
15
|
function getLocalizedDate(date, options, locale = "en-US") {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const validLocale = sanitizeLocale(locale);
|
|
17
|
+
return new Intl.DateTimeFormat(validLocale, options).format(date);
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Zero-pads a number to `length` digits (e.g. zeroPad(7, 2) = "07").
|
|
21
|
-
*/
|
|
22
19
|
function zeroPad(num, length) {
|
|
23
|
-
|
|
20
|
+
return String(num).padStart(length, "0");
|
|
24
21
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Returns an English ordinal for a given day number
|
|
27
|
-
*/
|
|
28
22
|
function getOrdinal(day) {
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
const j = day % 10, k = day % 100;
|
|
24
|
+
return j === 1 && k !== 11 ? `${day}st` : j === 2 && k !== 12 ? `${day}nd` : j === 3 && k !== 13 ? `${day}rd` : `${day}th`;
|
|
31
25
|
}
|
|
32
26
|
function getISODayOfWeek(date) {
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
const dow = date.getDay();
|
|
28
|
+
return dow === 0 ? 7 : dow;
|
|
35
29
|
}
|
|
36
30
|
function getISOWeekYear(date) {
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const temp = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())), dayOfWeek = getISODayOfWeek(temp);
|
|
32
|
+
return temp.setUTCDate(temp.getUTCDate() - dayOfWeek + 4), temp.getUTCFullYear();
|
|
39
33
|
}
|
|
40
34
|
function getISOWeekNumber(date) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
const temp = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())), dayOfWeek = getISODayOfWeek(temp);
|
|
36
|
+
temp.setUTCDate(temp.getUTCDate() - dayOfWeek + 4);
|
|
37
|
+
const yearStart = new Date(Date.UTC(temp.getUTCFullYear(), 0, 1));
|
|
38
|
+
return Math.ceil(((temp.valueOf() - yearStart.valueOf()) / 864e5 + 1) / 7);
|
|
45
39
|
}
|
|
46
40
|
function getDayOfYear(date) {
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
const startOfYear = new Date(Date.UTC(date.getFullYear(), 0, 1)), diff = date.valueOf() - startOfYear.valueOf() + (startOfYear.getTimezoneOffset() - date.getTimezoneOffset()) * 6e4;
|
|
42
|
+
return Math.floor(diff / (1e3 * 60 * 60 * 24)) + 1;
|
|
49
43
|
}
|
|
50
44
|
function getLocaleWeekYear(date) {
|
|
51
|
-
|
|
45
|
+
return getISOWeekYear(date);
|
|
52
46
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Returns fractional seconds based on the count of 'S' in the token.
|
|
55
|
-
*/
|
|
56
47
|
function getFractionalSeconds(date, length) {
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
const ms = zeroPad(date.getMilliseconds(), 3);
|
|
49
|
+
return length === 1 ? ms.slice(0, 1) : length === 2 ? ms.slice(0, 2) : length === 3 ? ms : `${ms}0`;
|
|
59
50
|
}
|
|
60
51
|
function getTimeZoneAbbreviation(date) {
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
const tz = new Intl.DateTimeFormat(sanitizeLocale("en-US"), {
|
|
53
|
+
timeZoneName: "short"
|
|
54
|
+
}).formatToParts(date).find((part) => part.type === "timeZoneName");
|
|
55
|
+
return tz ? tz.value : "";
|
|
63
56
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Formats a Date object using many Moment-like tokens.
|
|
66
|
-
*/
|
|
67
57
|
function formatMomentLike(date, formatStr) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
getValue: () => hours < 12 ? "AM" : "PM"
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
key: "a",
|
|
247
|
-
getValue: () => hours < 12 ? "am" : "pm"
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
key: "X",
|
|
251
|
-
getValue: () => String(unixSec)
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
key: "x",
|
|
255
|
-
getValue: () => String(unixMs)
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
key: "N",
|
|
259
|
-
getValue: () => year < 0 ? "BC" : "AD"
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
key: "NN",
|
|
263
|
-
getValue: () => year < 0 ? "BC" : "AD"
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
key: "NNN",
|
|
267
|
-
getValue: () => year < 0 ? "BC" : "AD"
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
key: "NNNN",
|
|
271
|
-
getValue: () => year < 0 ? "Before Christ" : "Anno Domini"
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
key: "NNNNN",
|
|
275
|
-
getValue: () => year < 0 ? "BC" : "AD"
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
key: "z",
|
|
279
|
-
getValue: () => getTimeZoneAbbreviation(date)
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
key: "zz",
|
|
283
|
-
getValue: () => getTimeZoneAbbreviation(date)
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
key: "Z",
|
|
287
|
-
getValue: () => format$1(date, "xxx")
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
key: "ZZ",
|
|
291
|
-
getValue: () => format$1(date, "xx")
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
key: "LTS",
|
|
295
|
-
getValue: () => getLocalizedDate(date, { timeStyle: "medium" })
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
key: "LT",
|
|
299
|
-
getValue: () => getLocalizedDate(date, { timeStyle: "short" })
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
key: "LLLL",
|
|
303
|
-
getValue: () => getLocalizedDate(date, {
|
|
304
|
-
weekday: "long",
|
|
305
|
-
year: "numeric",
|
|
306
|
-
month: "long",
|
|
307
|
-
day: "numeric",
|
|
308
|
-
hour: "numeric",
|
|
309
|
-
minute: "numeric"
|
|
310
|
-
})
|
|
311
|
-
},
|
|
312
|
-
{
|
|
313
|
-
key: "LLL",
|
|
314
|
-
getValue: () => getLocalizedDate(date, {
|
|
315
|
-
year: "numeric",
|
|
316
|
-
month: "long",
|
|
317
|
-
day: "numeric",
|
|
318
|
-
hour: "numeric",
|
|
319
|
-
minute: "numeric"
|
|
320
|
-
})
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
key: "LL",
|
|
324
|
-
getValue: () => getLocalizedDate(date, {
|
|
325
|
-
year: "numeric",
|
|
326
|
-
month: "long",
|
|
327
|
-
day: "numeric"
|
|
328
|
-
})
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
key: "L",
|
|
332
|
-
getValue: () => getLocalizedDate(date, {
|
|
333
|
-
year: "numeric",
|
|
334
|
-
month: "2-digit",
|
|
335
|
-
day: "2-digit"
|
|
336
|
-
})
|
|
337
|
-
},
|
|
338
|
-
{
|
|
339
|
-
key: "llll",
|
|
340
|
-
getValue: () => getLocalizedDate(date, {
|
|
341
|
-
weekday: "short",
|
|
342
|
-
year: "numeric",
|
|
343
|
-
month: "short",
|
|
344
|
-
day: "numeric",
|
|
345
|
-
hour: "numeric",
|
|
346
|
-
minute: "numeric"
|
|
347
|
-
})
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
key: "lll",
|
|
351
|
-
getValue: () => getLocalizedDate(date, {
|
|
352
|
-
year: "numeric",
|
|
353
|
-
month: "short",
|
|
354
|
-
day: "numeric",
|
|
355
|
-
hour: "numeric",
|
|
356
|
-
minute: "numeric"
|
|
357
|
-
})
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
key: "ll",
|
|
361
|
-
getValue: () => getLocalizedDate(date, {
|
|
362
|
-
year: "numeric",
|
|
363
|
-
month: "short",
|
|
364
|
-
day: "numeric"
|
|
365
|
-
})
|
|
366
|
-
},
|
|
367
|
-
{
|
|
368
|
-
key: "l",
|
|
369
|
-
getValue: () => getLocalizedDate(date, {
|
|
370
|
-
year: "numeric",
|
|
371
|
-
month: "numeric",
|
|
372
|
-
day: "numeric"
|
|
373
|
-
})
|
|
374
|
-
}
|
|
375
|
-
];
|
|
376
|
-
tokens.sort((a, b) => b.key.length - a.key.length);
|
|
377
|
-
let output = processedFormat.replace(/(?<!LT)S{1,4}/g, (match) => getFractionalSeconds(date, match.length));
|
|
378
|
-
for (let { key, getValue } of tokens) {
|
|
379
|
-
let escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), tokenRegex = RegExp(`(^|[^A-Z0-9a-z])(${escapedKey})(?![A-Z0-9a-z])`, "g");
|
|
380
|
-
if (output.match(tokenRegex)) {
|
|
381
|
-
let value = getValue();
|
|
382
|
-
output = output.replace(tokenRegex, `$1${value}`);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return output = output.replace(/* @__PURE__ */ RegExp("", "g"), () => escapeSequences.shift() || ""), output;
|
|
58
|
+
const escapeSequences = [], processedFormat = formatStr.replace(/\[([^\]]+)\]/g, (_, contents) => (escapeSequences.push(contents), "\uE000")), year = date.getFullYear(), monthIndex = date.getMonth(), dayOfMonth = date.getDate(), dayOfWeek = date.getDay(), hours = date.getHours(), minutes = date.getMinutes(), seconds = date.getSeconds(), isoWeekNum = getISOWeekNumber(date), isoWeekYear = getISOWeekYear(date), localeWeekYear = getLocaleWeekYear(date), unixMs = date.getTime(), unixSec = Math.floor(unixMs / 1e3), tokens = [
|
|
59
|
+
// Year
|
|
60
|
+
// 1970 1971 ... 2029 2030
|
|
61
|
+
{ key: "YYYY", getValue: () => String(year) },
|
|
62
|
+
// 70 71 ... 29 30
|
|
63
|
+
{ key: "YY", getValue: () => String(year).slice(-2) },
|
|
64
|
+
// 1970 1971 ... 9999 +10000 +10001
|
|
65
|
+
{ key: "Y", getValue: () => String(year) },
|
|
66
|
+
// Expanded years, -001970 -001971 ... +001907 +001971
|
|
67
|
+
{ key: "YYYYY", getValue: () => zeroPad(year, 5) },
|
|
68
|
+
// ISO week-year
|
|
69
|
+
// 1970 1971 ... 2029 2030
|
|
70
|
+
{ key: "GGGG", getValue: () => String(isoWeekYear) },
|
|
71
|
+
// 70 71 ... 29 30
|
|
72
|
+
{ key: "GG", getValue: () => String(isoWeekYear).slice(-2) },
|
|
73
|
+
// "locale" week-year
|
|
74
|
+
{ key: "gggg", getValue: () => String(localeWeekYear) },
|
|
75
|
+
{ key: "gg", getValue: () => String(localeWeekYear).slice(-2) },
|
|
76
|
+
// Quarter
|
|
77
|
+
{ key: "Q", getValue: () => String(Math.floor(monthIndex / 3) + 1) },
|
|
78
|
+
{ key: "Qo", getValue: () => getOrdinal(Math.floor(monthIndex / 3) + 1) },
|
|
79
|
+
// --- Month (using Intl) ---
|
|
80
|
+
{ key: "MMMM", getValue: () => getMonthName(date, "long") },
|
|
81
|
+
// e.g. "January"
|
|
82
|
+
{ key: "MMM", getValue: () => getMonthName(date, "short") },
|
|
83
|
+
// e.g. "Jan"
|
|
84
|
+
// For numeric months, we still do a manual approach:
|
|
85
|
+
{ key: "MM", getValue: () => zeroPad(monthIndex + 1, 2) },
|
|
86
|
+
{ key: "M", getValue: () => String(monthIndex + 1) },
|
|
87
|
+
{ key: "Mo", getValue: () => getOrdinal(monthIndex + 1) },
|
|
88
|
+
// Day of Month
|
|
89
|
+
{ key: "DD", getValue: () => zeroPad(dayOfMonth, 2) },
|
|
90
|
+
{ key: "D", getValue: () => String(dayOfMonth) },
|
|
91
|
+
{ key: "Do", getValue: () => getOrdinal(dayOfMonth) },
|
|
92
|
+
// --- Day of Week (using Intl) ---
|
|
93
|
+
{ key: "dddd", getValue: () => getDayName(date, "long") },
|
|
94
|
+
// e.g. "Monday"
|
|
95
|
+
{ key: "ddd", getValue: () => getDayName(date, "short") },
|
|
96
|
+
// e.g. "Mon"
|
|
97
|
+
{
|
|
98
|
+
key: "dd",
|
|
99
|
+
// e.g. "Mo" => first 2 chars of short day name
|
|
100
|
+
getValue: () => getDayName(date, "short").slice(0, 2)
|
|
101
|
+
},
|
|
102
|
+
{ key: "d", getValue: () => String(dayOfWeek) },
|
|
103
|
+
{ key: "do", getValue: () => getOrdinal(dayOfWeek + 1) },
|
|
104
|
+
// Day of the year
|
|
105
|
+
{ key: "DDDD", getValue: () => zeroPad(getDayOfYear(date), 3) },
|
|
106
|
+
{ key: "DDD", getValue: () => String(getDayOfYear(date)) },
|
|
107
|
+
{ key: "DDDo", getValue: () => getOrdinal(getDayOfYear(date)) },
|
|
108
|
+
// ISO day of week
|
|
109
|
+
{ key: "E", getValue: () => String(getISODayOfWeek(date)) },
|
|
110
|
+
// Week of the year
|
|
111
|
+
// w 1 2 ... 52 53
|
|
112
|
+
{ key: "w", getValue: () => zeroPad(isoWeekNum, 2) },
|
|
113
|
+
// week 1st 2nd ... 52nd 53rd
|
|
114
|
+
{ key: "wo", getValue: () => getOrdinal(isoWeekNum) },
|
|
115
|
+
// 01 02 ... 52 53
|
|
116
|
+
{ key: "ww", getValue: () => zeroPad(isoWeekNum, 2) },
|
|
117
|
+
// ISO Week
|
|
118
|
+
{ key: "WW", getValue: () => zeroPad(isoWeekNum, 2) },
|
|
119
|
+
{ key: "W", getValue: () => String(isoWeekNum) },
|
|
120
|
+
{ key: "Wo", getValue: () => getOrdinal(isoWeekNum) },
|
|
121
|
+
// or "locale" week => replace isoWeekNum
|
|
122
|
+
// 24h hours
|
|
123
|
+
{ key: "HH", getValue: () => zeroPad(hours, 2) },
|
|
124
|
+
{ key: "H", getValue: () => String(hours) },
|
|
125
|
+
// 12h hours
|
|
126
|
+
{ key: "hh", getValue: () => zeroPad((hours + 11) % 12 + 1, 2) },
|
|
127
|
+
{ key: "h", getValue: () => String((hours + 11) % 12 + 1) },
|
|
128
|
+
// 1 2 ... 23 24
|
|
129
|
+
{ key: "k", getValue: () => String(hours || 24) },
|
|
130
|
+
// 01 02 ... 23 24
|
|
131
|
+
{ key: "kk", getValue: () => zeroPad(hours || 24, 2) },
|
|
132
|
+
// Minutes
|
|
133
|
+
{ key: "mm", getValue: () => zeroPad(minutes, 2) },
|
|
134
|
+
{ key: "m", getValue: () => String(minutes) },
|
|
135
|
+
// Seconds
|
|
136
|
+
{ key: "ss", getValue: () => zeroPad(seconds, 2) },
|
|
137
|
+
{ key: "s", getValue: () => String(seconds) },
|
|
138
|
+
// Fractional seconds (S..SSSS) => handled separately
|
|
139
|
+
// Timezone offset (Z, ZZ) => handled separately
|
|
140
|
+
// AM/PM
|
|
141
|
+
{ key: "A", getValue: () => hours < 12 ? "AM" : "PM" },
|
|
142
|
+
{ key: "a", getValue: () => hours < 12 ? "am" : "pm" },
|
|
143
|
+
// Unix timestamps
|
|
144
|
+
{ key: "X", getValue: () => String(unixSec) },
|
|
145
|
+
{ key: "x", getValue: () => String(unixMs) },
|
|
146
|
+
// Eras BC AD
|
|
147
|
+
{ key: "N", getValue: () => year < 0 ? "BC" : "AD" },
|
|
148
|
+
{ key: "NN", getValue: () => year < 0 ? "BC" : "AD" },
|
|
149
|
+
{ key: "NNN", getValue: () => year < 0 ? "BC" : "AD" },
|
|
150
|
+
// Before Christ, Anno Domini
|
|
151
|
+
{ key: "NNNN", getValue: () => year < 0 ? "Before Christ" : "Anno Domini" },
|
|
152
|
+
{ key: "NNNNN", getValue: () => year < 0 ? "BC" : "AD" },
|
|
153
|
+
// Time zone offset
|
|
154
|
+
{ key: "z", getValue: () => getTimeZoneAbbreviation(date) },
|
|
155
|
+
{ key: "zz", getValue: () => getTimeZoneAbbreviation(date) },
|
|
156
|
+
{ key: "Z", getValue: () => format$1(date, "xxx") },
|
|
157
|
+
{ key: "ZZ", getValue: () => format$1(date, "xx") },
|
|
158
|
+
// Time
|
|
159
|
+
{ key: "LTS", getValue: () => getLocalizedDate(date, { timeStyle: "medium" }) },
|
|
160
|
+
{ key: "LT", getValue: () => getLocalizedDate(date, { timeStyle: "short" }) },
|
|
161
|
+
// Date (uppercase = longer names)
|
|
162
|
+
{
|
|
163
|
+
key: "LLLL",
|
|
164
|
+
getValue: () => getLocalizedDate(date, {
|
|
165
|
+
weekday: "long",
|
|
166
|
+
year: "numeric",
|
|
167
|
+
month: "long",
|
|
168
|
+
day: "numeric",
|
|
169
|
+
hour: "numeric",
|
|
170
|
+
minute: "numeric"
|
|
171
|
+
})
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
key: "LLL",
|
|
175
|
+
getValue: () => getLocalizedDate(date, {
|
|
176
|
+
year: "numeric",
|
|
177
|
+
month: "long",
|
|
178
|
+
day: "numeric",
|
|
179
|
+
hour: "numeric",
|
|
180
|
+
minute: "numeric"
|
|
181
|
+
})
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
key: "LL",
|
|
185
|
+
getValue: () => getLocalizedDate(date, { year: "numeric", month: "long", day: "numeric" })
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
key: "L",
|
|
189
|
+
getValue: () => getLocalizedDate(date, { year: "numeric", month: "2-digit", day: "2-digit" })
|
|
190
|
+
},
|
|
191
|
+
// Date (lowercase = shorter names)
|
|
192
|
+
{
|
|
193
|
+
key: "llll",
|
|
194
|
+
getValue: () => getLocalizedDate(date, {
|
|
195
|
+
weekday: "short",
|
|
196
|
+
year: "numeric",
|
|
197
|
+
month: "short",
|
|
198
|
+
day: "numeric",
|
|
199
|
+
hour: "numeric",
|
|
200
|
+
minute: "numeric"
|
|
201
|
+
})
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
key: "lll",
|
|
205
|
+
getValue: () => getLocalizedDate(date, {
|
|
206
|
+
year: "numeric",
|
|
207
|
+
month: "short",
|
|
208
|
+
day: "numeric",
|
|
209
|
+
hour: "numeric",
|
|
210
|
+
minute: "numeric"
|
|
211
|
+
})
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
key: "ll",
|
|
215
|
+
getValue: () => getLocalizedDate(date, { year: "numeric", month: "short", day: "numeric" })
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
key: "l",
|
|
219
|
+
getValue: () => getLocalizedDate(date, { year: "numeric", month: "numeric", day: "numeric" })
|
|
220
|
+
}
|
|
221
|
+
];
|
|
222
|
+
tokens.sort((a, b) => b.key.length - a.key.length);
|
|
223
|
+
const fracSecRegex = /(?<!LT)S{1,4}/g;
|
|
224
|
+
let output = processedFormat.replace(fracSecRegex, (match) => getFractionalSeconds(date, match.length));
|
|
225
|
+
for (const { key, getValue } of tokens) {
|
|
226
|
+
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), tokenRegex = new RegExp(`(^|[^A-Z0-9a-z])(${escapedKey})(?![A-Z0-9a-z])`, "g");
|
|
227
|
+
if (output.match(tokenRegex)) {
|
|
228
|
+
const value = getValue();
|
|
229
|
+
output = output.replace(tokenRegex, `$1${value}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return output = output.replace(new RegExp("\uE000", "g"), () => escapeSequences.shift() || ""), output;
|
|
386
233
|
}
|
|
387
|
-
/**
|
|
388
|
-
* Converts a Moment.js format string into a UTS 35 (Unicode Technical Standard #35)
|
|
389
|
-
* format string
|
|
390
|
-
*
|
|
391
|
-
* This function doesn't take absolutely every token into account, but should cover
|
|
392
|
-
* all common cases. If you find a missing token, feel free to add it.
|
|
393
|
-
*
|
|
394
|
-
*/
|
|
395
234
|
function momentToDateFnsFormat(momentFormat) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
235
|
+
const formatMap = {
|
|
236
|
+
YYYY: "yyyy",
|
|
237
|
+
YY: "yy",
|
|
238
|
+
MMMM: "MMMM",
|
|
239
|
+
MMM: "MMM",
|
|
240
|
+
MM: "MM",
|
|
241
|
+
M: "M",
|
|
242
|
+
DD: "dd",
|
|
243
|
+
D: "d",
|
|
244
|
+
dddd: "EEEE",
|
|
245
|
+
ddd: "EEE",
|
|
246
|
+
HH: "HH",
|
|
247
|
+
H: "H",
|
|
248
|
+
hh: "hh",
|
|
249
|
+
h: "h",
|
|
250
|
+
mm: "mm",
|
|
251
|
+
m: "m",
|
|
252
|
+
ss: "ss",
|
|
253
|
+
s: "s",
|
|
254
|
+
A: "a",
|
|
255
|
+
a: "a"
|
|
256
|
+
};
|
|
257
|
+
return Object.keys(formatMap).reduce(
|
|
258
|
+
(acc, key) => acc.replace(new RegExp(key, "g"), formatMap[key]),
|
|
259
|
+
momentFormat
|
|
260
|
+
);
|
|
419
261
|
}
|
|
420
262
|
const DEFAULT_DATE_FORMAT = "YYYY-MM-DD", DEFAULT_TIME_FORMAT = "HH:mm", DEFAULT_TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
421
|
-
function format(input, dateFormat, options = {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
}) {
|
|
425
|
-
let { useUTC, timeZone } = options;
|
|
426
|
-
return formatMomentLike(useUTC ? new UTCDateMini(input) : timeZone ? new TZDateMini(input, timeZone || DEFAULT_TIMEZONE) : new Date(input), dateFormat);
|
|
263
|
+
function format(input, dateFormat, options = { useUTC: !1, timeZone: void 0 }) {
|
|
264
|
+
const { useUTC, timeZone } = options;
|
|
265
|
+
return formatMomentLike(useUTC ? new UTCDateMini(input) : timeZone ? new TZDateMini(input, timeZone || DEFAULT_TIMEZONE) : new Date(input), dateFormat);
|
|
427
266
|
}
|
|
428
267
|
function parse(dateString, dateFormat, timeZone) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
268
|
+
const dnsFormat = dateFormat ? momentToDateFnsFormat(dateFormat) : void 0, parsed = dnsFormat ? parse$1(dateString, dnsFormat, /* @__PURE__ */ new Date()) : parseISO(dateString);
|
|
269
|
+
if (parsed && !isNaN(parsed.getTime())) {
|
|
270
|
+
let parsedDate = parsed;
|
|
271
|
+
return timeZone && isValidTimeZoneString(timeZone) && dateFormat ? parsedDate = new TZDateMini(
|
|
272
|
+
parsed.getFullYear(),
|
|
273
|
+
parsed.getMonth(),
|
|
274
|
+
parsed.getDate(),
|
|
275
|
+
parsed.getHours(),
|
|
276
|
+
parsed.getMinutes(),
|
|
277
|
+
parsed.getSeconds(),
|
|
278
|
+
parsed.getMilliseconds(),
|
|
279
|
+
timeZone
|
|
280
|
+
) : timeZone && isValidTimeZoneString(timeZone) && (parsedDate = new TZDateMini(parsed, timeZone)), { isValid: !0, date: parsedDate };
|
|
281
|
+
}
|
|
282
|
+
return { isValid: !1, error: `Invalid date. Must be on the format "${dateFormat}"` };
|
|
441
283
|
}
|
|
442
284
|
function isValidTimeZoneString(timeZone) {
|
|
443
|
-
|
|
285
|
+
return Intl.supportedValuesOf("timeZone").includes(timeZone);
|
|
444
286
|
}
|
|
445
|
-
export {
|
|
446
|
-
|
|
447
|
-
|
|
287
|
+
export {
|
|
288
|
+
DEFAULT_DATE_FORMAT,
|
|
289
|
+
DEFAULT_TIME_FORMAT,
|
|
290
|
+
format,
|
|
291
|
+
isValidTimeZoneString,
|
|
292
|
+
parse,
|
|
293
|
+
sanitizeLocale
|
|
294
|
+
};
|
|
295
|
+
//# sourceMappingURL=legacyDateFormat.js.map
|