@formatjs/icu-skeleton-parser 1.3.8 → 1.3.11
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/BUILD +80 -0
- package/CHANGELOG.md +133 -0
- package/LICENSE.md +0 -0
- package/README.md +0 -0
- package/date-time.ts +144 -0
- package/index.ts +2 -0
- package/number.ts +357 -0
- package/package.json +3 -3
- package/regex.generated.ts +2 -0
- package/scripts/global.ts +1 -0
- package/scripts/regex-gen.ts +19 -0
- package/tests/__snapshots__/index.test.ts.snap +389 -0
- package/tests/index.test.ts +65 -0
- package/tsconfig.json +5 -0
- package/date-time.d.ts +0 -8
- package/date-time.d.ts.map +0 -1
- package/date-time.js +0 -125
- package/index.d.ts +0 -3
- package/index.d.ts.map +0 -1
- package/index.js +0 -5
- package/lib/date-time.d.ts +0 -8
- package/lib/date-time.d.ts.map +0 -1
- package/lib/date-time.js +0 -121
- package/lib/index.d.ts +0 -3
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -2
- package/lib/number.d.ts +0 -14
- package/lib/number.d.ts.map +0 -1
- package/lib/number.js +0 -295
- package/lib/regex.generated.d.ts +0 -2
- package/lib/regex.generated.d.ts.map +0 -1
- package/lib/regex.generated.js +0 -2
- package/number.d.ts +0 -14
- package/number.d.ts.map +0 -1
- package/number.js +0 -300
- package/regex.generated.d.ts +0 -2
- package/regex.generated.d.ts.map +0 -1
- package/regex.generated.js +0 -5
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`[parseNumberSkeleton] case: "% .##" 1`] = `
|
|
4
|
+
Object {
|
|
5
|
+
"maximumFractionDigits": 2,
|
|
6
|
+
"style": "percent",
|
|
7
|
+
}
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
exports[`[parseNumberSkeleton] case: "%x100" 1`] = `
|
|
11
|
+
Object {
|
|
12
|
+
"scale": 100,
|
|
13
|
+
"style": "percent",
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
exports[`[parseNumberSkeleton] case: "()!" 1`] = `
|
|
18
|
+
Object {
|
|
19
|
+
"currencySign": "accounting",
|
|
20
|
+
"signDisplay": "always",
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
exports[`[parseNumberSkeleton] case: "()" 1`] = `
|
|
25
|
+
Object {
|
|
26
|
+
"currencySign": "accounting",
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
exports[`[parseNumberSkeleton] case: "()?" 1`] = `
|
|
31
|
+
Object {
|
|
32
|
+
"currencySign": "accounting",
|
|
33
|
+
"signDisplay": "exceptZero",
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
exports[`[parseNumberSkeleton] case: "+!" 1`] = `
|
|
38
|
+
Object {
|
|
39
|
+
"signDisplay": "always",
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
exports[`[parseNumberSkeleton] case: "+?" 1`] = `
|
|
44
|
+
Object {
|
|
45
|
+
"signDisplay": "exceptZero",
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
exports[`[parseNumberSkeleton] case: "+_" 1`] = `
|
|
50
|
+
Object {
|
|
51
|
+
"signDisplay": "never",
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
exports[`[parseNumberSkeleton] case: "." 1`] = `
|
|
56
|
+
Object {
|
|
57
|
+
"maximumFractionDigits": 0,
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
exports[`[parseNumberSkeleton] case: ".##" 1`] = `
|
|
62
|
+
Object {
|
|
63
|
+
"maximumFractionDigits": 2,
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
exports[`[parseNumberSkeleton] case: ".##/@##r" 1`] = `
|
|
68
|
+
Object {
|
|
69
|
+
"maximumFractionDigits": 2,
|
|
70
|
+
"maximumSignificantDigits": 3,
|
|
71
|
+
"minimumSignificantDigits": 1,
|
|
72
|
+
"roundingPriority": "morePrecision",
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
exports[`[parseNumberSkeleton] case: ".##/@##s" 1`] = `
|
|
77
|
+
Object {
|
|
78
|
+
"maximumFractionDigits": 2,
|
|
79
|
+
"maximumSignificantDigits": 3,
|
|
80
|
+
"minimumSignificantDigits": 1,
|
|
81
|
+
"roundingPriority": "lessPrecision",
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
|
|
85
|
+
exports[`[parseNumberSkeleton] case: ".##/w" 1`] = `
|
|
86
|
+
Object {
|
|
87
|
+
"maximumFractionDigits": 2,
|
|
88
|
+
"trailingZeroDisplay": "stripIfInteger",
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
exports[`[parseNumberSkeleton] case: ".00/w currency/CAD" 1`] = `
|
|
93
|
+
Object {
|
|
94
|
+
"currency": "CAD",
|
|
95
|
+
"maximumFractionDigits": 2,
|
|
96
|
+
"minimumFractionDigits": 2,
|
|
97
|
+
"style": "currency",
|
|
98
|
+
"trailingZeroDisplay": "stripIfInteger",
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
exports[`[parseNumberSkeleton] case: "000" 1`] = `
|
|
103
|
+
Object {
|
|
104
|
+
"minimumIntegerDigits": 3,
|
|
105
|
+
}
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
exports[`[parseNumberSkeleton] case: "E+!00" 1`] = `
|
|
109
|
+
Object {
|
|
110
|
+
"minimumIntegerDigits": 2,
|
|
111
|
+
"notation": "scientific",
|
|
112
|
+
"signDisplay": "always",
|
|
113
|
+
}
|
|
114
|
+
`;
|
|
115
|
+
|
|
116
|
+
exports[`[parseNumberSkeleton] case: "E0" 1`] = `
|
|
117
|
+
Object {
|
|
118
|
+
"minimumIntegerDigits": 1,
|
|
119
|
+
"notation": "scientific",
|
|
120
|
+
}
|
|
121
|
+
`;
|
|
122
|
+
|
|
123
|
+
exports[`[parseNumberSkeleton] case: "EE+?000" 1`] = `
|
|
124
|
+
Object {
|
|
125
|
+
"minimumIntegerDigits": 3,
|
|
126
|
+
"notation": "engineering",
|
|
127
|
+
"signDisplay": "exceptZero",
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
|
|
131
|
+
exports[`[parseNumberSkeleton] case: "compact-long" 1`] = `
|
|
132
|
+
Object {
|
|
133
|
+
"compactDisplay": "long",
|
|
134
|
+
"notation": "compact",
|
|
135
|
+
}
|
|
136
|
+
`;
|
|
137
|
+
|
|
138
|
+
exports[`[parseNumberSkeleton] case: "compact-short" 1`] = `
|
|
139
|
+
Object {
|
|
140
|
+
"compactDisplay": "short",
|
|
141
|
+
"notation": "compact",
|
|
142
|
+
}
|
|
143
|
+
`;
|
|
144
|
+
|
|
145
|
+
exports[`[parseNumberSkeleton] case: "currency/CAD ." 1`] = `
|
|
146
|
+
Object {
|
|
147
|
+
"currency": "CAD",
|
|
148
|
+
"maximumFractionDigits": 0,
|
|
149
|
+
"style": "currency",
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
|
|
153
|
+
exports[`[parseNumberSkeleton] case: "currency/GBP .0*/@@@" 1`] = `
|
|
154
|
+
Object {
|
|
155
|
+
"currency": "GBP",
|
|
156
|
+
"maximumSignificantDigits": 3,
|
|
157
|
+
"minimumFractionDigits": 1,
|
|
158
|
+
"minimumSignificantDigits": 3,
|
|
159
|
+
"style": "currency",
|
|
160
|
+
}
|
|
161
|
+
`;
|
|
162
|
+
|
|
163
|
+
exports[`[parseNumberSkeleton] case: "currency/GBP .00##/@@@ unit-width-full-name" 1`] = `
|
|
164
|
+
Object {
|
|
165
|
+
"currency": "GBP",
|
|
166
|
+
"currencyDisplay": "name",
|
|
167
|
+
"maximumFractionDigits": 4,
|
|
168
|
+
"maximumSignificantDigits": 3,
|
|
169
|
+
"minimumFractionDigits": 2,
|
|
170
|
+
"minimumSignificantDigits": 3,
|
|
171
|
+
"style": "currency",
|
|
172
|
+
"unitDisplay": "long",
|
|
173
|
+
}
|
|
174
|
+
`;
|
|
175
|
+
|
|
176
|
+
exports[`[parseNumberSkeleton] case: "currency/GBP .00##/@@@" 1`] = `
|
|
177
|
+
Object {
|
|
178
|
+
"currency": "GBP",
|
|
179
|
+
"maximumFractionDigits": 4,
|
|
180
|
+
"maximumSignificantDigits": 3,
|
|
181
|
+
"minimumFractionDigits": 2,
|
|
182
|
+
"minimumSignificantDigits": 3,
|
|
183
|
+
"style": "currency",
|
|
184
|
+
}
|
|
185
|
+
`;
|
|
186
|
+
|
|
187
|
+
exports[`[parseNumberSkeleton] case: "engineering" 1`] = `
|
|
188
|
+
Object {
|
|
189
|
+
"notation": "engineering",
|
|
190
|
+
}
|
|
191
|
+
`;
|
|
192
|
+
|
|
193
|
+
exports[`[parseNumberSkeleton] case: "engineering/sign-except-zero" 1`] = `
|
|
194
|
+
Object {
|
|
195
|
+
"notation": "engineering",
|
|
196
|
+
"signDisplay": "exceptZero",
|
|
197
|
+
}
|
|
198
|
+
`;
|
|
199
|
+
|
|
200
|
+
exports[`[parseNumberSkeleton] case: "integer-width/*000" 1`] = `
|
|
201
|
+
Object {
|
|
202
|
+
"minimumIntegerDigits": 3,
|
|
203
|
+
}
|
|
204
|
+
`;
|
|
205
|
+
|
|
206
|
+
exports[`[parseNumberSkeleton] case: "measure-unit/length-meter .00##/@@@ unit-width-full-name" 1`] = `
|
|
207
|
+
Object {
|
|
208
|
+
"currencyDisplay": "name",
|
|
209
|
+
"maximumFractionDigits": 4,
|
|
210
|
+
"maximumSignificantDigits": 3,
|
|
211
|
+
"minimumFractionDigits": 2,
|
|
212
|
+
"minimumSignificantDigits": 3,
|
|
213
|
+
"style": "unit",
|
|
214
|
+
"unit": "meter",
|
|
215
|
+
"unitDisplay": "long",
|
|
216
|
+
}
|
|
217
|
+
`;
|
|
218
|
+
|
|
219
|
+
exports[`[parseNumberSkeleton] case: "measure-unit/length-meter .00##/@@@" 1`] = `
|
|
220
|
+
Object {
|
|
221
|
+
"maximumFractionDigits": 4,
|
|
222
|
+
"maximumSignificantDigits": 3,
|
|
223
|
+
"minimumFractionDigits": 2,
|
|
224
|
+
"minimumSignificantDigits": 3,
|
|
225
|
+
"style": "unit",
|
|
226
|
+
"unit": "meter",
|
|
227
|
+
}
|
|
228
|
+
`;
|
|
229
|
+
|
|
230
|
+
exports[`[parseNumberSkeleton] case: "notation-simple" 1`] = `
|
|
231
|
+
Object {
|
|
232
|
+
"notation": "standard",
|
|
233
|
+
}
|
|
234
|
+
`;
|
|
235
|
+
|
|
236
|
+
exports[`[parseNumberSkeleton] case: "percent .##" 1`] = `
|
|
237
|
+
Object {
|
|
238
|
+
"maximumFractionDigits": 2,
|
|
239
|
+
"style": "percent",
|
|
240
|
+
}
|
|
241
|
+
`;
|
|
242
|
+
|
|
243
|
+
exports[`[parseNumberSkeleton] case: "percent .0###" 1`] = `
|
|
244
|
+
Object {
|
|
245
|
+
"maximumFractionDigits": 4,
|
|
246
|
+
"minimumFractionDigits": 1,
|
|
247
|
+
"style": "percent",
|
|
248
|
+
}
|
|
249
|
+
`;
|
|
250
|
+
|
|
251
|
+
exports[`[parseNumberSkeleton] case: "percent .00/@##" 1`] = `
|
|
252
|
+
Object {
|
|
253
|
+
"maximumFractionDigits": 2,
|
|
254
|
+
"maximumSignificantDigits": 3,
|
|
255
|
+
"minimumFractionDigits": 2,
|
|
256
|
+
"minimumSignificantDigits": 1,
|
|
257
|
+
"style": "percent",
|
|
258
|
+
}
|
|
259
|
+
`;
|
|
260
|
+
|
|
261
|
+
exports[`[parseNumberSkeleton] case: "percent .00/@@@" 1`] = `
|
|
262
|
+
Object {
|
|
263
|
+
"maximumFractionDigits": 2,
|
|
264
|
+
"maximumSignificantDigits": 3,
|
|
265
|
+
"minimumFractionDigits": 2,
|
|
266
|
+
"minimumSignificantDigits": 3,
|
|
267
|
+
"style": "percent",
|
|
268
|
+
}
|
|
269
|
+
`;
|
|
270
|
+
|
|
271
|
+
exports[`[parseNumberSkeleton] case: "percent .00/@@@@*" 1`] = `
|
|
272
|
+
Object {
|
|
273
|
+
"maximumFractionDigits": 2,
|
|
274
|
+
"minimumFractionDigits": 2,
|
|
275
|
+
"style": "percent",
|
|
276
|
+
}
|
|
277
|
+
`;
|
|
278
|
+
|
|
279
|
+
exports[`[parseNumberSkeleton] case: "percent .000*" 1`] = `
|
|
280
|
+
Object {
|
|
281
|
+
"minimumFractionDigits": 3,
|
|
282
|
+
"style": "percent",
|
|
283
|
+
}
|
|
284
|
+
`;
|
|
285
|
+
|
|
286
|
+
exports[`[parseNumberSkeleton] case: "percent scale/0.01" 1`] = `
|
|
287
|
+
Object {
|
|
288
|
+
"scale": 0.01,
|
|
289
|
+
"style": "percent",
|
|
290
|
+
}
|
|
291
|
+
`;
|
|
292
|
+
|
|
293
|
+
exports[`[parseNumberSkeleton] case: "scientific" 1`] = `
|
|
294
|
+
Object {
|
|
295
|
+
"notation": "scientific",
|
|
296
|
+
}
|
|
297
|
+
`;
|
|
298
|
+
|
|
299
|
+
exports[`[parseNumberSkeleton] case: "scientific/+ee/sign-always" 1`] = `
|
|
300
|
+
Object {
|
|
301
|
+
"notation": "scientific",
|
|
302
|
+
"signDisplay": "always",
|
|
303
|
+
}
|
|
304
|
+
`;
|
|
305
|
+
|
|
306
|
+
exports[`[parseNumberSkeleton] case: "scientific/sign-always" 1`] = `
|
|
307
|
+
Object {
|
|
308
|
+
"notation": "scientific",
|
|
309
|
+
"signDisplay": "always",
|
|
310
|
+
}
|
|
311
|
+
`;
|
|
312
|
+
|
|
313
|
+
exports[`[parseNumberSkeleton] case: "sign-accounting" 1`] = `
|
|
314
|
+
Object {
|
|
315
|
+
"currencySign": "accounting",
|
|
316
|
+
}
|
|
317
|
+
`;
|
|
318
|
+
|
|
319
|
+
exports[`[parseNumberSkeleton] case: "sign-accounting-always" 1`] = `
|
|
320
|
+
Object {
|
|
321
|
+
"currencySign": "accounting",
|
|
322
|
+
"signDisplay": "always",
|
|
323
|
+
}
|
|
324
|
+
`;
|
|
325
|
+
|
|
326
|
+
exports[`[parseNumberSkeleton] case: "sign-accounting-except-zero" 1`] = `
|
|
327
|
+
Object {
|
|
328
|
+
"currencySign": "accounting",
|
|
329
|
+
"signDisplay": "exceptZero",
|
|
330
|
+
}
|
|
331
|
+
`;
|
|
332
|
+
|
|
333
|
+
exports[`[parseNumberSkeleton] case: "sign-always" 1`] = `
|
|
334
|
+
Object {
|
|
335
|
+
"signDisplay": "always",
|
|
336
|
+
}
|
|
337
|
+
`;
|
|
338
|
+
|
|
339
|
+
exports[`[parseNumberSkeleton] case: "sign-auto" 1`] = `
|
|
340
|
+
Object {
|
|
341
|
+
"signDisplay": "auto",
|
|
342
|
+
}
|
|
343
|
+
`;
|
|
344
|
+
|
|
345
|
+
exports[`[parseNumberSkeleton] case: "sign-except-zero" 1`] = `
|
|
346
|
+
Object {
|
|
347
|
+
"signDisplay": "exceptZero",
|
|
348
|
+
}
|
|
349
|
+
`;
|
|
350
|
+
|
|
351
|
+
exports[`[parseNumberSkeleton] case: "sign-never" 1`] = `
|
|
352
|
+
Object {
|
|
353
|
+
"signDisplay": "never",
|
|
354
|
+
}
|
|
355
|
+
`;
|
|
356
|
+
|
|
357
|
+
exports[`case: "" 1`] = `Object {}`;
|
|
358
|
+
|
|
359
|
+
exports[`case: "EEE, MMM d, ''yy" 1`] = `
|
|
360
|
+
Object {
|
|
361
|
+
"day": "numeric",
|
|
362
|
+
"month": "short",
|
|
363
|
+
"weekday": "short",
|
|
364
|
+
"year": "2-digit",
|
|
365
|
+
}
|
|
366
|
+
`;
|
|
367
|
+
|
|
368
|
+
exports[`case: "h:mm a" 1`] = `
|
|
369
|
+
Object {
|
|
370
|
+
"hour": "numeric",
|
|
371
|
+
"hour12": true,
|
|
372
|
+
"hourCycle": "h12",
|
|
373
|
+
"minute": "2-digit",
|
|
374
|
+
}
|
|
375
|
+
`;
|
|
376
|
+
|
|
377
|
+
exports[`case: "yyyy.MM.dd G 'at' HH:mm:ss zzzz" 1`] = `
|
|
378
|
+
Object {
|
|
379
|
+
"day": "2-digit",
|
|
380
|
+
"era": "short",
|
|
381
|
+
"hour": "2-digit",
|
|
382
|
+
"hourCycle": "h23",
|
|
383
|
+
"minute": "2-digit",
|
|
384
|
+
"month": "2-digit",
|
|
385
|
+
"second": "2-digit",
|
|
386
|
+
"timeZoneName": "long",
|
|
387
|
+
"year": "numeric",
|
|
388
|
+
}
|
|
389
|
+
`;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {parseDateTimeSkeleton, parseNumberSkeleton} from '..'
|
|
2
|
+
import {parseNumberSkeletonFromString} from '../number'
|
|
3
|
+
|
|
4
|
+
test.each([
|
|
5
|
+
`yyyy.MM.dd G 'at' HH:mm:ss zzzz`,
|
|
6
|
+
`EEE, MMM d, ''yy`,
|
|
7
|
+
`h:mm a`,
|
|
8
|
+
``,
|
|
9
|
+
])('case: %p', skeleton => {
|
|
10
|
+
expect(parseDateTimeSkeleton(skeleton)).toMatchSnapshot()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test.each([
|
|
14
|
+
'percent .##',
|
|
15
|
+
'.##',
|
|
16
|
+
'.##/w',
|
|
17
|
+
'.',
|
|
18
|
+
'% .##',
|
|
19
|
+
'.##/@##r',
|
|
20
|
+
'.##/@##s',
|
|
21
|
+
'percent .000*',
|
|
22
|
+
'percent .0###',
|
|
23
|
+
'percent .00/@##',
|
|
24
|
+
'percent .00/@@@',
|
|
25
|
+
'percent .00/@@@@*',
|
|
26
|
+
'percent scale/0.01',
|
|
27
|
+
'currency/CAD .',
|
|
28
|
+
'.00/w currency/CAD',
|
|
29
|
+
'currency/GBP .0*/@@@',
|
|
30
|
+
'currency/GBP .00##/@@@',
|
|
31
|
+
'currency/GBP .00##/@@@ unit-width-full-name',
|
|
32
|
+
'measure-unit/length-meter .00##/@@@',
|
|
33
|
+
'measure-unit/length-meter .00##/@@@ unit-width-full-name',
|
|
34
|
+
'compact-short',
|
|
35
|
+
'compact-long',
|
|
36
|
+
'scientific',
|
|
37
|
+
'scientific/sign-always',
|
|
38
|
+
'scientific/+ee/sign-always',
|
|
39
|
+
'engineering',
|
|
40
|
+
'engineering/sign-except-zero',
|
|
41
|
+
'notation-simple',
|
|
42
|
+
'sign-auto',
|
|
43
|
+
'sign-always',
|
|
44
|
+
'+!',
|
|
45
|
+
'sign-never',
|
|
46
|
+
'+_',
|
|
47
|
+
'sign-accounting',
|
|
48
|
+
'()',
|
|
49
|
+
'sign-accounting-always',
|
|
50
|
+
'()!',
|
|
51
|
+
'sign-except-zero',
|
|
52
|
+
'+?',
|
|
53
|
+
'sign-accounting-except-zero',
|
|
54
|
+
'()?',
|
|
55
|
+
'000',
|
|
56
|
+
'integer-width/*000',
|
|
57
|
+
'E0',
|
|
58
|
+
'E+!00',
|
|
59
|
+
'EE+?000',
|
|
60
|
+
'%x100',
|
|
61
|
+
])('[parseNumberSkeleton] case: %p', skeleton => {
|
|
62
|
+
expect(
|
|
63
|
+
parseNumberSkeleton(parseNumberSkeletonFromString(skeleton))
|
|
64
|
+
).toMatchSnapshot()
|
|
65
|
+
})
|
package/tsconfig.json
ADDED
package/date-time.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse Date time skeleton into Intl.DateTimeFormatOptions
|
|
3
|
-
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
4
|
-
* @public
|
|
5
|
-
* @param skeleton skeleton string
|
|
6
|
-
*/
|
|
7
|
-
export declare function parseDateTimeSkeleton(skeleton: string): Intl.DateTimeFormatOptions;
|
|
8
|
-
//# sourceMappingURL=date-time.d.ts.map
|
package/date-time.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"date-time.d.ts","sourceRoot":"","sources":["../../../../../packages/icu-skeleton-parser/date-time.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,GACf,IAAI,CAAC,qBAAqB,CA+H5B"}
|
package/date-time.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseDateTimeSkeleton = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
6
|
-
* Credit: https://github.com/caridy/intl-datetimeformat-pattern/blob/master/index.js
|
|
7
|
-
* with some tweaks
|
|
8
|
-
*/
|
|
9
|
-
var DATE_TIME_REGEX = /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;
|
|
10
|
-
/**
|
|
11
|
-
* Parse Date time skeleton into Intl.DateTimeFormatOptions
|
|
12
|
-
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
13
|
-
* @public
|
|
14
|
-
* @param skeleton skeleton string
|
|
15
|
-
*/
|
|
16
|
-
function parseDateTimeSkeleton(skeleton) {
|
|
17
|
-
var result = {};
|
|
18
|
-
skeleton.replace(DATE_TIME_REGEX, function (match) {
|
|
19
|
-
var len = match.length;
|
|
20
|
-
switch (match[0]) {
|
|
21
|
-
// Era
|
|
22
|
-
case 'G':
|
|
23
|
-
result.era = len === 4 ? 'long' : len === 5 ? 'narrow' : 'short';
|
|
24
|
-
break;
|
|
25
|
-
// Year
|
|
26
|
-
case 'y':
|
|
27
|
-
result.year = len === 2 ? '2-digit' : 'numeric';
|
|
28
|
-
break;
|
|
29
|
-
case 'Y':
|
|
30
|
-
case 'u':
|
|
31
|
-
case 'U':
|
|
32
|
-
case 'r':
|
|
33
|
-
throw new RangeError('`Y/u/U/r` (year) patterns are not supported, use `y` instead');
|
|
34
|
-
// Quarter
|
|
35
|
-
case 'q':
|
|
36
|
-
case 'Q':
|
|
37
|
-
throw new RangeError('`q/Q` (quarter) patterns are not supported');
|
|
38
|
-
// Month
|
|
39
|
-
case 'M':
|
|
40
|
-
case 'L':
|
|
41
|
-
result.month = ['numeric', '2-digit', 'short', 'long', 'narrow'][len - 1];
|
|
42
|
-
break;
|
|
43
|
-
// Week
|
|
44
|
-
case 'w':
|
|
45
|
-
case 'W':
|
|
46
|
-
throw new RangeError('`w/W` (week) patterns are not supported');
|
|
47
|
-
case 'd':
|
|
48
|
-
result.day = ['numeric', '2-digit'][len - 1];
|
|
49
|
-
break;
|
|
50
|
-
case 'D':
|
|
51
|
-
case 'F':
|
|
52
|
-
case 'g':
|
|
53
|
-
throw new RangeError('`D/F/g` (day) patterns are not supported, use `d` instead');
|
|
54
|
-
// Weekday
|
|
55
|
-
case 'E':
|
|
56
|
-
result.weekday = len === 4 ? 'short' : len === 5 ? 'narrow' : 'short';
|
|
57
|
-
break;
|
|
58
|
-
case 'e':
|
|
59
|
-
if (len < 4) {
|
|
60
|
-
throw new RangeError('`e..eee` (weekday) patterns are not supported');
|
|
61
|
-
}
|
|
62
|
-
result.weekday = ['short', 'long', 'narrow', 'short'][len - 4];
|
|
63
|
-
break;
|
|
64
|
-
case 'c':
|
|
65
|
-
if (len < 4) {
|
|
66
|
-
throw new RangeError('`c..ccc` (weekday) patterns are not supported');
|
|
67
|
-
}
|
|
68
|
-
result.weekday = ['short', 'long', 'narrow', 'short'][len - 4];
|
|
69
|
-
break;
|
|
70
|
-
// Period
|
|
71
|
-
case 'a': // AM, PM
|
|
72
|
-
result.hour12 = true;
|
|
73
|
-
break;
|
|
74
|
-
case 'b': // am, pm, noon, midnight
|
|
75
|
-
case 'B': // flexible day periods
|
|
76
|
-
throw new RangeError('`b/B` (period) patterns are not supported, use `a` instead');
|
|
77
|
-
// Hour
|
|
78
|
-
case 'h':
|
|
79
|
-
result.hourCycle = 'h12';
|
|
80
|
-
result.hour = ['numeric', '2-digit'][len - 1];
|
|
81
|
-
break;
|
|
82
|
-
case 'H':
|
|
83
|
-
result.hourCycle = 'h23';
|
|
84
|
-
result.hour = ['numeric', '2-digit'][len - 1];
|
|
85
|
-
break;
|
|
86
|
-
case 'K':
|
|
87
|
-
result.hourCycle = 'h11';
|
|
88
|
-
result.hour = ['numeric', '2-digit'][len - 1];
|
|
89
|
-
break;
|
|
90
|
-
case 'k':
|
|
91
|
-
result.hourCycle = 'h24';
|
|
92
|
-
result.hour = ['numeric', '2-digit'][len - 1];
|
|
93
|
-
break;
|
|
94
|
-
case 'j':
|
|
95
|
-
case 'J':
|
|
96
|
-
case 'C':
|
|
97
|
-
throw new RangeError('`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead');
|
|
98
|
-
// Minute
|
|
99
|
-
case 'm':
|
|
100
|
-
result.minute = ['numeric', '2-digit'][len - 1];
|
|
101
|
-
break;
|
|
102
|
-
// Second
|
|
103
|
-
case 's':
|
|
104
|
-
result.second = ['numeric', '2-digit'][len - 1];
|
|
105
|
-
break;
|
|
106
|
-
case 'S':
|
|
107
|
-
case 'A':
|
|
108
|
-
throw new RangeError('`S/A` (second) patterns are not supported, use `s` instead');
|
|
109
|
-
// Zone
|
|
110
|
-
case 'z': // 1..3, 4: specific non-location format
|
|
111
|
-
result.timeZoneName = len < 4 ? 'short' : 'long';
|
|
112
|
-
break;
|
|
113
|
-
case 'Z': // 1..3, 4, 5: The ISO8601 varios formats
|
|
114
|
-
case 'O': // 1, 4: miliseconds in day short, long
|
|
115
|
-
case 'v': // 1, 4: generic non-location format
|
|
116
|
-
case 'V': // 1, 2, 3, 4: time zone ID or city
|
|
117
|
-
case 'X': // 1, 2, 3, 4: The ISO8601 varios formats
|
|
118
|
-
case 'x': // 1, 2, 3, 4: The ISO8601 varios formats
|
|
119
|
-
throw new RangeError('`Z/O/v/V/X/x` (timeZone) patterns are not supported, use `z` instead');
|
|
120
|
-
}
|
|
121
|
-
return '';
|
|
122
|
-
});
|
|
123
|
-
return result;
|
|
124
|
-
}
|
|
125
|
-
exports.parseDateTimeSkeleton = parseDateTimeSkeleton;
|
package/index.d.ts
DELETED
package/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/icu-skeleton-parser/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA"}
|
package/index.js
DELETED
package/lib/date-time.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse Date time skeleton into Intl.DateTimeFormatOptions
|
|
3
|
-
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
4
|
-
* @public
|
|
5
|
-
* @param skeleton skeleton string
|
|
6
|
-
*/
|
|
7
|
-
export declare function parseDateTimeSkeleton(skeleton: string): Intl.DateTimeFormatOptions;
|
|
8
|
-
//# sourceMappingURL=date-time.d.ts.map
|
package/lib/date-time.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"date-time.d.ts","sourceRoot":"","sources":["../../../../../../packages/icu-skeleton-parser/date-time.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,GACf,IAAI,CAAC,qBAAqB,CA+H5B"}
|