@sanity/util 6.7.0-next.4 → 6.7.0-next.40

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.
@@ -5,291 +5,443 @@ 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
- const validLocale = sanitizeLocale(locale);
9
- return new Intl.DateTimeFormat(validLocale, { month: style }).format(date);
8
+ let 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
- const validLocale = sanitizeLocale(locale);
13
- return new Intl.DateTimeFormat(validLocale, { weekday: style }).format(date);
12
+ let 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
- const validLocale = sanitizeLocale(locale);
17
- return new Intl.DateTimeFormat(validLocale, options).format(date);
16
+ let 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
+ */
19
22
  function zeroPad(num, length) {
20
- return String(num).padStart(length, "0");
23
+ return String(num).padStart(length, "0");
21
24
  }
25
+ /**
26
+ * Returns an English ordinal for a given day number
27
+ */
22
28
  function getOrdinal(day) {
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`;
29
+ let j = day % 10, k = day % 100;
30
+ return j === 1 && k !== 11 ? `${day}st` : j === 2 && k !== 12 ? `${day}nd` : j === 3 && k !== 13 ? `${day}rd` : `${day}th`;
25
31
  }
26
32
  function getISODayOfWeek(date) {
27
- const dow = date.getDay();
28
- return dow === 0 ? 7 : dow;
33
+ let dow = date.getDay();
34
+ return dow === 0 ? 7 : dow;
29
35
  }
30
36
  function getISOWeekYear(date) {
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();
37
+ let temp = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())), dayOfWeek = getISODayOfWeek(temp);
38
+ return temp.setUTCDate(temp.getUTCDate() - dayOfWeek + 4), temp.getUTCFullYear();
33
39
  }
34
40
  function getISOWeekNumber(date) {
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);
41
+ let temp = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())), dayOfWeek = getISODayOfWeek(temp);
42
+ temp.setUTCDate(temp.getUTCDate() - dayOfWeek + 4);
43
+ let yearStart = new Date(Date.UTC(temp.getUTCFullYear(), 0, 1));
44
+ return Math.ceil(((temp.valueOf() - yearStart.valueOf()) / 864e5 + 1) / 7);
39
45
  }
40
46
  function getDayOfYear(date) {
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;
47
+ let startOfYear = new Date(Date.UTC(date.getFullYear(), 0, 1)), diff = date.valueOf() - startOfYear.valueOf() + (startOfYear.getTimezoneOffset() - date.getTimezoneOffset()) * 6e4;
48
+ return Math.floor(diff / (1e3 * 60 * 60 * 24)) + 1;
43
49
  }
44
50
  function getLocaleWeekYear(date) {
45
- return getISOWeekYear(date);
51
+ return getISOWeekYear(date);
46
52
  }
53
+ /**
54
+ * Returns fractional seconds based on the count of 'S' in the token.
55
+ */
47
56
  function getFractionalSeconds(date, length) {
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`;
57
+ let ms = zeroPad(date.getMilliseconds(), 3);
58
+ return length === 1 ? ms.slice(0, 1) : length === 2 ? ms.slice(0, 2) : length === 3 ? ms : `${ms}0`;
50
59
  }
51
60
  function getTimeZoneAbbreviation(date) {
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 : "";
61
+ let tz = new Intl.DateTimeFormat(sanitizeLocale("en-US"), { timeZoneName: "short" }).formatToParts(date).find((part) => part.type === "timeZoneName");
62
+ return tz ? tz.value : "";
56
63
  }
64
+ /**
65
+ * Formats a Date object using many Moment-like tokens.
66
+ */
57
67
  function formatMomentLike(date, formatStr) {
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;
68
+ let escapeSequences = [], processedFormat = formatStr.replace(/\[([^\]]+)\]/g, (_, contents) => (escapeSequences.push(contents), "")), 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 = [
69
+ {
70
+ key: "YYYY",
71
+ getValue: () => String(year)
72
+ },
73
+ {
74
+ key: "YY",
75
+ getValue: () => String(year).slice(-2)
76
+ },
77
+ {
78
+ key: "Y",
79
+ getValue: () => String(year)
80
+ },
81
+ {
82
+ key: "YYYYY",
83
+ getValue: () => zeroPad(year, 5)
84
+ },
85
+ {
86
+ key: "GGGG",
87
+ getValue: () => String(isoWeekYear)
88
+ },
89
+ {
90
+ key: "GG",
91
+ getValue: () => String(isoWeekYear).slice(-2)
92
+ },
93
+ {
94
+ key: "gggg",
95
+ getValue: () => String(localeWeekYear)
96
+ },
97
+ {
98
+ key: "gg",
99
+ getValue: () => String(localeWeekYear).slice(-2)
100
+ },
101
+ {
102
+ key: "Q",
103
+ getValue: () => String(Math.floor(monthIndex / 3) + 1)
104
+ },
105
+ {
106
+ key: "Qo",
107
+ getValue: () => getOrdinal(Math.floor(monthIndex / 3) + 1)
108
+ },
109
+ {
110
+ key: "MMMM",
111
+ getValue: () => getMonthName(date, "long")
112
+ },
113
+ {
114
+ key: "MMM",
115
+ getValue: () => getMonthName(date, "short")
116
+ },
117
+ {
118
+ key: "MM",
119
+ getValue: () => zeroPad(monthIndex + 1, 2)
120
+ },
121
+ {
122
+ key: "M",
123
+ getValue: () => String(monthIndex + 1)
124
+ },
125
+ {
126
+ key: "Mo",
127
+ getValue: () => getOrdinal(monthIndex + 1)
128
+ },
129
+ {
130
+ key: "DD",
131
+ getValue: () => zeroPad(dayOfMonth, 2)
132
+ },
133
+ {
134
+ key: "D",
135
+ getValue: () => String(dayOfMonth)
136
+ },
137
+ {
138
+ key: "Do",
139
+ getValue: () => getOrdinal(dayOfMonth)
140
+ },
141
+ {
142
+ key: "dddd",
143
+ getValue: () => getDayName(date, "long")
144
+ },
145
+ {
146
+ key: "ddd",
147
+ getValue: () => getDayName(date, "short")
148
+ },
149
+ {
150
+ key: "dd",
151
+ getValue: () => getDayName(date, "short").slice(0, 2)
152
+ },
153
+ {
154
+ key: "d",
155
+ getValue: () => String(dayOfWeek)
156
+ },
157
+ {
158
+ key: "do",
159
+ getValue: () => getOrdinal(dayOfWeek + 1)
160
+ },
161
+ {
162
+ key: "DDDD",
163
+ getValue: () => zeroPad(getDayOfYear(date), 3)
164
+ },
165
+ {
166
+ key: "DDD",
167
+ getValue: () => String(getDayOfYear(date))
168
+ },
169
+ {
170
+ key: "DDDo",
171
+ getValue: () => getOrdinal(getDayOfYear(date))
172
+ },
173
+ {
174
+ key: "E",
175
+ getValue: () => String(getISODayOfWeek(date))
176
+ },
177
+ {
178
+ key: "w",
179
+ getValue: () => zeroPad(isoWeekNum, 2)
180
+ },
181
+ {
182
+ key: "wo",
183
+ getValue: () => getOrdinal(isoWeekNum)
184
+ },
185
+ {
186
+ key: "ww",
187
+ getValue: () => zeroPad(isoWeekNum, 2)
188
+ },
189
+ {
190
+ key: "WW",
191
+ getValue: () => zeroPad(isoWeekNum, 2)
192
+ },
193
+ {
194
+ key: "W",
195
+ getValue: () => String(isoWeekNum)
196
+ },
197
+ {
198
+ key: "Wo",
199
+ getValue: () => getOrdinal(isoWeekNum)
200
+ },
201
+ {
202
+ key: "HH",
203
+ getValue: () => zeroPad(hours, 2)
204
+ },
205
+ {
206
+ key: "H",
207
+ getValue: () => String(hours)
208
+ },
209
+ {
210
+ key: "hh",
211
+ getValue: () => zeroPad((hours + 11) % 12 + 1, 2)
212
+ },
213
+ {
214
+ key: "h",
215
+ getValue: () => String((hours + 11) % 12 + 1)
216
+ },
217
+ {
218
+ key: "k",
219
+ getValue: () => String(hours || 24)
220
+ },
221
+ {
222
+ key: "kk",
223
+ getValue: () => zeroPad(hours || 24, 2)
224
+ },
225
+ {
226
+ key: "mm",
227
+ getValue: () => zeroPad(minutes, 2)
228
+ },
229
+ {
230
+ key: "m",
231
+ getValue: () => String(minutes)
232
+ },
233
+ {
234
+ key: "ss",
235
+ getValue: () => zeroPad(seconds, 2)
236
+ },
237
+ {
238
+ key: "s",
239
+ getValue: () => String(seconds)
240
+ },
241
+ {
242
+ key: "A",
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;
233
386
  }
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
+ */
234
395
  function momentToDateFnsFormat(momentFormat) {
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
- );
396
+ let formatMap = {
397
+ YYYY: "yyyy",
398
+ YY: "yy",
399
+ MMMM: "MMMM",
400
+ MMM: "MMM",
401
+ MM: "MM",
402
+ M: "M",
403
+ DD: "dd",
404
+ D: "d",
405
+ dddd: "EEEE",
406
+ ddd: "EEE",
407
+ HH: "HH",
408
+ H: "H",
409
+ hh: "hh",
410
+ h: "h",
411
+ mm: "mm",
412
+ m: "m",
413
+ ss: "ss",
414
+ s: "s",
415
+ A: "a",
416
+ a: "a"
417
+ };
418
+ return Object.keys(formatMap).reduce((acc, key) => acc.replace(new RegExp(key, "g"), formatMap[key]), momentFormat);
261
419
  }
262
420
  const DEFAULT_DATE_FORMAT = "YYYY-MM-DD", DEFAULT_TIME_FORMAT = "HH:mm", DEFAULT_TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;
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);
421
+ function format(input, dateFormat, options = {
422
+ useUTC: !1,
423
+ timeZone: void 0
424
+ }) {
425
+ let { useUTC, timeZone } = options;
426
+ return formatMomentLike(useUTC ? new UTCDateMini(input) : timeZone ? new TZDateMini(input, timeZone || DEFAULT_TIMEZONE) : new Date(input), dateFormat);
266
427
  }
267
428
  function parse(dateString, dateFormat, timeZone) {
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}"` };
429
+ let dnsFormat = dateFormat ? momentToDateFnsFormat(dateFormat) : void 0, parsed = dnsFormat ? parse$1(dateString, dnsFormat, /* @__PURE__ */ new Date()) : parseISO(dateString);
430
+ if (parsed && !isNaN(parsed.getTime())) {
431
+ let parsedDate = parsed;
432
+ return timeZone && isValidTimeZoneString(timeZone) && dateFormat ? parsedDate = new TZDateMini(parsed.getFullYear(), parsed.getMonth(), parsed.getDate(), parsed.getHours(), parsed.getMinutes(), parsed.getSeconds(), parsed.getMilliseconds(), timeZone) : timeZone && isValidTimeZoneString(timeZone) && (parsedDate = new TZDateMini(parsed, timeZone)), {
433
+ isValid: !0,
434
+ date: parsedDate
435
+ };
436
+ }
437
+ return {
438
+ isValid: !1,
439
+ error: `Invalid date. Must be on the format "${dateFormat}"`
440
+ };
283
441
  }
284
442
  function isValidTimeZoneString(timeZone) {
285
- return Intl.supportedValuesOf("timeZone").includes(timeZone);
443
+ return Intl.supportedValuesOf("timeZone").includes(timeZone);
286
444
  }
287
- export {
288
- DEFAULT_DATE_FORMAT,
289
- DEFAULT_TIME_FORMAT,
290
- format,
291
- isValidTimeZoneString,
292
- parse,
293
- sanitizeLocale
294
- };
295
- //# sourceMappingURL=legacyDateFormat.js.map
445
+ export { DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT, format, isValidTimeZoneString, parse, sanitizeLocale };
446
+
447
+ //# sourceMappingURL=legacyDateFormat.js.map