@sanity/util 6.7.0-next.3 → 6.7.0-next.30
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 +2 -1
- package/lib/client.js +48 -62
- package/lib/client.js.map +1 -1
- package/lib/concurrency-limiter-C6gDjN0m.js +35 -0
- package/lib/concurrency-limiter-C6gDjN0m.js.map +1 -0
- package/lib/concurrency-limiter.d.ts +2 -1
- package/lib/concurrency-limiter.js +2 -32
- package/lib/content.d.ts +2 -1
- package/lib/content.js +56 -69
- package/lib/content.js.map +1 -1
- package/lib/createSafeJsonParser.d.ts +2 -1
- package/lib/createSafeJsonParser.js +21 -18
- package/lib/createSafeJsonParser.js.map +1 -1
- package/lib/fs.d.ts +2 -1
- package/lib/fs.js +17 -22
- package/lib/fs.js.map +1 -1
- package/lib/index.js +0 -2
- package/lib/legacyDateFormat.d.ts +2 -1
- package/lib/legacyDateFormat.js +407 -255
- package/lib/legacyDateFormat.js.map +1 -1
- package/lib/paths.d.ts +2 -1
- package/lib/paths.js +92 -114
- package/lib/paths.js.map +1 -1
- package/package.json +10 -16
- package/lib/concurrency-limiter.js.map +0 -1
- package/lib/createSafeJsonParser.cjs +0 -20
- package/lib/createSafeJsonParser.cjs.map +0 -1
- package/lib/createSafeJsonParser.d.cts +0 -14
- package/lib/index.js.map +0 -1
package/lib/legacyDateFormat.js
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
28
|
-
|
|
33
|
+
let dow = date.getDay();
|
|
34
|
+
return dow === 0 ? 7 : dow;
|
|
29
35
|
}
|
|
30
36
|
function getISOWeekYear(date) {
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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 = {
|
|
264
|
-
|
|
265
|
-
|
|
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
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
|
|
443
|
+
return Intl.supportedValuesOf("timeZone").includes(timeZone);
|
|
286
444
|
}
|
|
287
|
-
export {
|
|
288
|
-
|
|
289
|
-
|
|
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
|