@markuplint/types 3.0.0-dev.24 → 3.0.0-dev.290
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/README.md +63 -61
- package/lib/check-multi-types.d.ts +2 -2
- package/lib/check-multi-types.js +9 -13
- package/lib/check.d.ts +7 -6
- package/lib/check.js +20 -30
- package/lib/css-syntax.d.ts +1 -1
- package/lib/css-syntax.js +60 -63
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +1 -1
- package/lib/defs.js +163 -91
- package/lib/enum.d.ts +4 -3
- package/lib/enum.js +7 -12
- package/lib/get-candidate.d.ts +1 -1
- package/lib/get-candidate.js +3 -8
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -6
- package/lib/keyword-type.d.ts +2 -2
- package/lib/keyword-type.js +17 -21
- package/lib/list.d.ts +4 -3
- package/lib/list.js +9 -13
- package/lib/match-result.d.ts +4 -4
- package/lib/match-result.js +6 -12
- package/lib/number.d.ts +3 -3
- package/lib/number.js +11 -15
- package/lib/primitive/index.d.ts +7 -7
- package/lib/primitive/index.js +7 -17
- package/lib/primitive/is-float.js +1 -5
- package/lib/primitive/is-int.js +1 -5
- package/lib/primitive/is-non-zero-uint.js +1 -5
- package/lib/primitive/is-quantity.d.ts +1 -1
- package/lib/primitive/is-quantity.js +9 -13
- package/lib/primitive/is-uint.d.ts +1 -1
- package/lib/primitive/is-uint.js +1 -5
- package/lib/primitive/range.js +1 -5
- package/lib/primitive/split-unit.js +3 -7
- package/lib/rfc/is-bcp-47.d.ts +1 -1
- package/lib/rfc/is-bcp-47.js +3 -7
- package/lib/token/index.d.ts +2 -2
- package/lib/token/index.js +2 -7
- package/lib/token/token-collection.d.ts +13 -13
- package/lib/token/token-collection.js +55 -50
- package/lib/token/token.d.ts +11 -10
- package/lib/token/token.js +16 -24
- package/lib/token/types.d.ts +3 -0
- package/lib/types.d.ts +47 -46
- package/lib/types.js +1 -2
- package/lib/types.schema.d.ts +2 -2
- package/lib/types.schema.js +1 -3
- package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
- package/lib/w3c/check-serialized-permissions-policy.js +16 -20
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +28 -32
- package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/date-string.js +9 -13
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -1
- package/lib/whatwg/check-datetime/datetime-tokens.js +43 -46
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +48 -44
- package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/global-date-and-time-string.js +17 -21
- package/lib/whatwg/check-datetime/index.d.ts +1 -1
- package/lib/whatwg/check-datetime/index.js +25 -29
- package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +25 -26
- package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/month-string.js +9 -13
- package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/time-string.js +9 -13
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +16 -21
- package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/week-string.js +9 -13
- package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/year-string.js +9 -13
- package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/yearless-date-string.js +9 -13
- package/lib/whatwg/check-mime-type.d.ts +1 -1
- package/lib/whatwg/check-mime-type.js +12 -18
- package/lib/whatwg/is-abs-url.d.ts +1 -1
- package/lib/whatwg/is-abs-url.js +1 -5
- package/lib/whatwg/is-browser-context-name.d.ts +3 -1
- package/lib/whatwg/is-browser-context-name.js +3 -5
- package/lib/whatwg/is-custom-element-name.d.ts +1 -1
- package/lib/whatwg/is-custom-element-name.js +1 -5
- package/lib/whatwg/is-itemprop-name.d.ts +1 -1
- package/lib/whatwg/is-itemprop-name.js +2 -6
- package/lib/whatwg/is-navigable-target-name.d.ts +11 -0
- package/lib/whatwg/is-navigable-target-name.js +20 -0
- package/package.json +19 -13
- package/types.schema.json +314 -311
- package/gen/specific-schema.json +0 -98
- package/gen/types.ts +0 -66
- package/lib/check.spec.js +0 -76
- package/lib/css-syntax.spec.d.ts +0 -1
- package/lib/css-syntax.spec.js +0 -157
- package/lib/list.spec.d.ts +0 -1
- package/lib/list.spec.js +0 -129
- package/lib/primitive/index.spec.d.ts +0 -1
- package/lib/primitive/index.spec.js +0 -62
- package/lib/rfc/is-bcp-47.spec.d.ts +0 -1
- package/lib/rfc/is-bcp-47.spec.js +0 -19
- package/lib/token/token-collection.spec.d.ts +0 -1
- package/lib/token/token-collection.spec.js +0 -144
- package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +0 -1
- package/lib/w3c/check-serialized-permissions-policy.spec.js +0 -34
- package/lib/whatwg/check-autocomplete.spec.d.ts +0 -1
- package/lib/whatwg/check-autocomplete.spec.js +0 -379
- package/lib/whatwg/check-datetime/index.spec.d.ts +0 -1
- package/lib/whatwg/check-datetime/index.spec.js +0 -318
- package/lib/whatwg/check-mime-type.spec.d.ts +0 -1
- package/lib/whatwg/check-mime-type.spec.js +0 -58
- package/lib/whatwg/is-abs-url.spec.d.ts +0 -1
- package/lib/whatwg/is-abs-url.spec.js +0 -8
- package/patches/css-tree+2.3.1.patch +0 -23
- package/src/check-multi-types.ts +0 -35
- package/src/check.spec.ts +0 -83
- package/src/check.ts +0 -48
- package/src/css-syntax.spec.ts +0 -167
- package/src/css-syntax.ts +0 -188
- package/src/debug.ts +0 -3
- package/src/defs.ts +0 -811
- package/src/enum.ts +0 -25
- package/src/get-candidate.ts +0 -24
- package/src/index.ts +0 -3
- package/src/keyword-type.ts +0 -64
- package/src/list.spec.ts +0 -133
- package/src/list.ts +0 -34
- package/src/match-result.ts +0 -49
- package/src/number.ts +0 -46
- package/src/primitive/index.spec.ts +0 -65
- package/src/primitive/index.ts +0 -7
- package/src/primitive/is-float.ts +0 -8
- package/src/primitive/is-int.ts +0 -8
- package/src/primitive/is-non-zero-uint.ts +0 -8
- package/src/primitive/is-quantity.ts +0 -38
- package/src/primitive/is-uint.ts +0 -15
- package/src/primitive/range.ts +0 -14
- package/src/primitive/split-unit.ts +0 -20
- package/src/rfc/is-bcp-47.spec.ts +0 -23
- package/src/rfc/is-bcp-47.ts +0 -13
- package/src/token/index.ts +0 -2
- package/src/token/token-collection.spec.ts +0 -147
- package/src/token/token-collection.ts +0 -444
- package/src/token/token.ts +0 -144
- package/src/types.schema.ts +0 -1113
- package/src/types.ts +0 -118
- package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
- package/src/w3c/check-serialized-permissions-policy.ts +0 -303
- package/src/whatwg/check-autocomplete.spec.ts +0 -387
- package/src/whatwg/check-autocomplete.ts +0 -380
- package/src/whatwg/check-datetime/date-string.ts +0 -44
- package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
- package/src/whatwg/check-datetime/duration-string.ts +0 -399
- package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
- package/src/whatwg/check-datetime/index.spec.ts +0 -333
- package/src/whatwg/check-datetime/index.ts +0 -36
- package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
- package/src/whatwg/check-datetime/month-string.ts +0 -31
- package/src/whatwg/check-datetime/time-string.ts +0 -49
- package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
- package/src/whatwg/check-datetime/week-string.ts +0 -41
- package/src/whatwg/check-datetime/year-string.ts +0 -26
- package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
- package/src/whatwg/check-mime-type.spec.ts +0 -59
- package/src/whatwg/check-mime-type.ts +0 -46
- package/src/whatwg/is-abs-url.spec.ts +0 -8
- package/src/whatwg/is-abs-url.ts +0 -31
- package/src/whatwg/is-browser-context-name.ts +0 -16
- package/src/whatwg/is-custom-element-name.ts +0 -76
- package/src/whatwg/is-itemprop-name.ts +0 -17
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
- /package/lib/{check.spec.d.ts → token/types.js} +0 -0
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../../debug");
|
|
5
|
-
const match_result_1 = require("../../match-result");
|
|
6
|
-
exports.datetimeTokenCheck = {
|
|
1
|
+
import { log } from '../../debug.js';
|
|
2
|
+
import { matched, unmatched } from '../../match-result.js';
|
|
3
|
+
export const datetimeTokenCheck = {
|
|
7
4
|
/**
|
|
8
5
|
* Temporary year state
|
|
9
6
|
*/
|
|
@@ -16,10 +13,10 @@ exports.datetimeTokenCheck = {
|
|
|
16
13
|
* > Four or more ASCII digits, representing year, where year > 0
|
|
17
14
|
*/
|
|
18
15
|
year(year) {
|
|
19
|
-
|
|
16
|
+
log('Parsing Datetime Year: "%s"', year?.value);
|
|
20
17
|
this._year = null;
|
|
21
18
|
if (!year || !year.value) {
|
|
22
|
-
return
|
|
19
|
+
return unmatched('', 'missing-token', {
|
|
23
20
|
expects: [{ type: 'common', value: 'year' }],
|
|
24
21
|
partName: 'year',
|
|
25
22
|
});
|
|
@@ -51,10 +48,10 @@ exports.datetimeTokenCheck = {
|
|
|
51
48
|
* > Two ASCII digits, representing the month month, in the range 1 ≤ month ≤ 12
|
|
52
49
|
*/
|
|
53
50
|
month(month) {
|
|
54
|
-
|
|
51
|
+
log('Parsing Datetime Month: "%s"', month?.value);
|
|
55
52
|
this._month = null;
|
|
56
53
|
if (!month || !month.value) {
|
|
57
|
-
return
|
|
54
|
+
return unmatched('', 'missing-token', {
|
|
58
55
|
expects: [{ type: 'common', value: 'month' }],
|
|
59
56
|
partName: 'month',
|
|
60
57
|
});
|
|
@@ -95,9 +92,9 @@ exports.datetimeTokenCheck = {
|
|
|
95
92
|
* > then the day can be 29, as if the year was a leap year.
|
|
96
93
|
*/
|
|
97
94
|
date(date) {
|
|
98
|
-
|
|
95
|
+
log('Parsing Datetime Date: "%s"', date?.value);
|
|
99
96
|
if (!date || !date.value) {
|
|
100
|
-
return
|
|
97
|
+
return unmatched('', 'missing-token', {
|
|
101
98
|
expects: [{ type: 'common', value: 'date' }],
|
|
102
99
|
partName: 'date',
|
|
103
100
|
});
|
|
@@ -117,13 +114,13 @@ exports.datetimeTokenCheck = {
|
|
|
117
114
|
});
|
|
118
115
|
}
|
|
119
116
|
// Set the leap year if _year is null
|
|
120
|
-
const year = this._year
|
|
117
|
+
const year = this._year ?? 2000;
|
|
121
118
|
const isLeap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
122
|
-
const month = this._month
|
|
123
|
-
const dayOfMonth = daysOfMonth[month] + (month === 2 && isLeap ? 1 : 0);
|
|
119
|
+
const month = this._month ?? 1;
|
|
120
|
+
const dayOfMonth = (daysOfMonth[month] ?? 0) + (month === 2 && isLeap ? 1 : 0);
|
|
124
121
|
const _date = date.toNumber();
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
log('Temporary Year and Month: %s, %s', this._year, this._month);
|
|
123
|
+
log('Computed Year, Month, and Day of Month: %s, %s, %s', year, month, dayOfMonth);
|
|
127
124
|
if (!(1 <= _date && _date <= dayOfMonth)) {
|
|
128
125
|
return date.unmatched({
|
|
129
126
|
reason: { type: 'out-of-range', gte: 1, lte: dayOfMonth },
|
|
@@ -136,9 +133,9 @@ exports.datetimeTokenCheck = {
|
|
|
136
133
|
* > Two ASCII digits, representing hour, in the range 0 ≤ hour ≤ 23
|
|
137
134
|
*/
|
|
138
135
|
hour(hour) {
|
|
139
|
-
|
|
136
|
+
log('Parsing Datetime Hour: "%s"', hour?.value);
|
|
140
137
|
if (!hour || !hour.value) {
|
|
141
|
-
return
|
|
138
|
+
return unmatched('', 'missing-token', {
|
|
142
139
|
expects: [{ type: 'common', value: 'hour' }],
|
|
143
140
|
partName: 'hour',
|
|
144
141
|
});
|
|
@@ -170,9 +167,9 @@ exports.datetimeTokenCheck = {
|
|
|
170
167
|
* > Two ASCII digits, representing minute, in the range 0 ≤ minute ≤ 59
|
|
171
168
|
*/
|
|
172
169
|
minute(minute) {
|
|
173
|
-
|
|
170
|
+
log('Parsing Datetime Minute: "%s"', minute?.value);
|
|
174
171
|
if (!minute || !minute.value) {
|
|
175
|
-
return
|
|
172
|
+
return unmatched('', 'missing-token', {
|
|
176
173
|
expects: [{ type: 'common', value: 'minute' }],
|
|
177
174
|
partName: 'minute',
|
|
178
175
|
});
|
|
@@ -204,9 +201,9 @@ exports.datetimeTokenCheck = {
|
|
|
204
201
|
* > Two ASCII digits, representing the integer part of second, in the range 0 ≤ s ≤ 59
|
|
205
202
|
*/
|
|
206
203
|
second(second) {
|
|
207
|
-
|
|
204
|
+
log('Parsing Datetime Second: "%s"', second?.value);
|
|
208
205
|
if (!second || !second.value) {
|
|
209
|
-
return
|
|
206
|
+
return unmatched('', 'missing-token', {
|
|
210
207
|
expects: [{ type: 'common', value: 'second' }],
|
|
211
208
|
partName: 'second',
|
|
212
209
|
});
|
|
@@ -238,9 +235,9 @@ exports.datetimeTokenCheck = {
|
|
|
238
235
|
* > One, two, or three ASCII digits, representing the fractional part of second
|
|
239
236
|
*/
|
|
240
237
|
secondFractionalPart(secondFP) {
|
|
241
|
-
|
|
238
|
+
log('Parsing Datetime Second Fractional Part: "%s"', secondFP?.value);
|
|
242
239
|
if (!secondFP || !secondFP.value) {
|
|
243
|
-
return
|
|
240
|
+
return unmatched('', 'missing-token', {
|
|
244
241
|
expects: [{ type: 'common', value: 'fractional part' }],
|
|
245
242
|
partName: 'fractional part',
|
|
246
243
|
});
|
|
@@ -264,9 +261,9 @@ exports.datetimeTokenCheck = {
|
|
|
264
261
|
* > Two ASCII digits, representing the week week, in the range 1 ≤ week ≤ maxweek, where maxweek is the week number of the last day of week-year year
|
|
265
262
|
*/
|
|
266
263
|
week(week) {
|
|
267
|
-
|
|
264
|
+
log('Parsing Datetime Week: "%s"', week?.value);
|
|
268
265
|
if (!week || !week.value) {
|
|
269
|
-
return
|
|
266
|
+
return unmatched('', 'missing-token', {
|
|
270
267
|
expects: [{ type: 'common', value: 'week' }],
|
|
271
268
|
partName: 'week',
|
|
272
269
|
});
|
|
@@ -285,7 +282,7 @@ exports.datetimeTokenCheck = {
|
|
|
285
282
|
partName: 'week',
|
|
286
283
|
});
|
|
287
284
|
}
|
|
288
|
-
const maxweek = getMaxWeekNum(this._year
|
|
285
|
+
const maxweek = getMaxWeekNum(this._year ?? 0);
|
|
289
286
|
const _week = week.toNumber();
|
|
290
287
|
if (!(1 <= _week && _week <= maxweek)) {
|
|
291
288
|
return week.unmatched({
|
|
@@ -299,9 +296,9 @@ exports.datetimeTokenCheck = {
|
|
|
299
296
|
* > A U+002D HYPHEN-MINUS character (-)
|
|
300
297
|
*/
|
|
301
298
|
hyphen(hyphen) {
|
|
302
|
-
|
|
299
|
+
log('Parsing Datetime hyphen: "%s"', hyphen?.value);
|
|
303
300
|
if (!hyphen || !hyphen.value) {
|
|
304
|
-
return
|
|
301
|
+
return unmatched('', 'missing-token', {
|
|
305
302
|
expects: [{ type: 'common', value: 'hyphen' }],
|
|
306
303
|
partName: 'datetime',
|
|
307
304
|
});
|
|
@@ -318,9 +315,9 @@ exports.datetimeTokenCheck = {
|
|
|
318
315
|
* > A U+003A COLON character (:)
|
|
319
316
|
*/
|
|
320
317
|
colon(colon) {
|
|
321
|
-
|
|
318
|
+
log('Parsing Datetime colon: "%s"', colon?.value);
|
|
322
319
|
if (!colon || !colon.value) {
|
|
323
|
-
return
|
|
320
|
+
return unmatched('', 'missing-token', {
|
|
324
321
|
expects: [{ type: 'common', value: 'colon' }],
|
|
325
322
|
partName: 'time',
|
|
326
323
|
});
|
|
@@ -340,7 +337,7 @@ exports.datetimeTokenCheck = {
|
|
|
340
337
|
*/
|
|
341
338
|
colonOrEnd(colon) {
|
|
342
339
|
if (!colon || !colon.value) {
|
|
343
|
-
return
|
|
340
|
+
return matched();
|
|
344
341
|
}
|
|
345
342
|
if (!colon.match(':')) {
|
|
346
343
|
return colon.unmatched({
|
|
@@ -357,7 +354,7 @@ exports.datetimeTokenCheck = {
|
|
|
357
354
|
*/
|
|
358
355
|
decimalPointOrEnd(dot) {
|
|
359
356
|
if (!dot || !dot.value) {
|
|
360
|
-
return
|
|
357
|
+
return matched();
|
|
361
358
|
}
|
|
362
359
|
if (!dot.match('.')) {
|
|
363
360
|
return dot.unmatched({
|
|
@@ -371,9 +368,9 @@ exports.datetimeTokenCheck = {
|
|
|
371
368
|
* > A U+0054 LATIN CAPITAL LETTER T character (T) or a U+0020 SPACE character
|
|
372
369
|
*/
|
|
373
370
|
localDateTimeSeparator(sep) {
|
|
374
|
-
|
|
371
|
+
log('Parsing Datetime Local-Date-Time separator: "%s"', sep?.value);
|
|
375
372
|
if (!sep || !sep.value) {
|
|
376
|
-
return
|
|
373
|
+
return unmatched('', 'missing-token', {
|
|
377
374
|
expects: [
|
|
378
375
|
{ type: 'const', value: 'T' },
|
|
379
376
|
{ type: 'common', value: 'space' },
|
|
@@ -394,9 +391,9 @@ exports.datetimeTokenCheck = {
|
|
|
394
391
|
* > A U+0054 LATIN CAPITAL LETTER T character (T)
|
|
395
392
|
*/
|
|
396
393
|
normalizedlocalDateTimeSeparator(sep) {
|
|
397
|
-
|
|
394
|
+
log('Parsing Datetime Normalized-Local-Date-Time separator: %s', sep?.value);
|
|
398
395
|
if (!sep || !sep.value) {
|
|
399
|
-
return
|
|
396
|
+
return unmatched('', 'missing-token', {
|
|
400
397
|
expects: [{ type: 'const', value: 'T' }],
|
|
401
398
|
});
|
|
402
399
|
}
|
|
@@ -415,7 +412,7 @@ exports.datetimeTokenCheck = {
|
|
|
415
412
|
*/
|
|
416
413
|
plusOrMinusSign(colon) {
|
|
417
414
|
if (!colon) {
|
|
418
|
-
return
|
|
415
|
+
return unmatched('', 'missing-token', {
|
|
419
416
|
expects: [
|
|
420
417
|
{ type: 'const', value: '+' },
|
|
421
418
|
{ type: 'const', value: '-' },
|
|
@@ -438,9 +435,9 @@ exports.datetimeTokenCheck = {
|
|
|
438
435
|
* > A U+0057 LATIN CAPITAL LETTER W character (W)
|
|
439
436
|
*/
|
|
440
437
|
weekSign(weekSign) {
|
|
441
|
-
|
|
438
|
+
log('Parsing Datetime W sign: "%s"', weekSign?.value);
|
|
442
439
|
if (!weekSign || !weekSign.value) {
|
|
443
|
-
return
|
|
440
|
+
return unmatched('', 'missing-token', {
|
|
444
441
|
expects: [{ type: 'const', value: 'W' }],
|
|
445
442
|
partName: 'time-zone',
|
|
446
443
|
});
|
|
@@ -457,7 +454,7 @@ exports.datetimeTokenCheck = {
|
|
|
457
454
|
* Extra token
|
|
458
455
|
*/
|
|
459
456
|
extra(extra) {
|
|
460
|
-
|
|
457
|
+
log('Parsing Datetime EXTRA STRING: "%s"', extra?.value);
|
|
461
458
|
if (extra && extra.value) {
|
|
462
459
|
return extra.unmatched({
|
|
463
460
|
reason: 'extra-token',
|
|
@@ -492,11 +489,12 @@ const daysOfMonth = [
|
|
|
492
489
|
// 12
|
|
493
490
|
31,
|
|
494
491
|
];
|
|
495
|
-
function getMaxWeekNum(year) {
|
|
492
|
+
export function getMaxWeekNum(year) {
|
|
496
493
|
let date = 31;
|
|
497
|
-
while (date) {
|
|
494
|
+
while (date > 0) {
|
|
498
495
|
const d = new Date(Date.UTC(year, 11, date, 0, 0, 0, 0));
|
|
499
|
-
|
|
496
|
+
const day = d.getDay();
|
|
497
|
+
d.setDate(d.getDate() + 4 - (day > 0 ? day : 7));
|
|
500
498
|
const yearStart = new Date(d.getFullYear(), 0, 1);
|
|
501
499
|
const weekNo = Math.ceil(((d.valueOf() - yearStart.valueOf()) / 86400000 + 1) / 7);
|
|
502
500
|
if (weekNo !== 1) {
|
|
@@ -506,4 +504,3 @@ function getMaxWeekNum(year) {
|
|
|
506
504
|
}
|
|
507
505
|
return NaN;
|
|
508
506
|
}
|
|
509
|
-
exports.getMaxWeekNum = getMaxWeekNum;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const match_result_1 = require("../../match-result");
|
|
6
|
-
const token_1 = require("../../token");
|
|
7
|
-
const datetime_tokens_1 = require("./datetime-tokens");
|
|
1
|
+
import { log } from '../../debug.js';
|
|
2
|
+
import { matched, unmatched } from '../../match-result.js';
|
|
3
|
+
import { TokenCollection } from '../../token/index.js';
|
|
4
|
+
import { datetimeTokenCheck } from './datetime-tokens.js';
|
|
8
5
|
/**
|
|
9
6
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#durations
|
|
10
7
|
*/
|
|
11
|
-
const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeString(value) {
|
|
12
|
-
|
|
8
|
+
export const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeString(value) {
|
|
9
|
+
log('CHECK: duration-string (ISO8601 like)');
|
|
13
10
|
// PnDTnHnMnS
|
|
14
|
-
const tokens =
|
|
11
|
+
const tokens = TokenCollection.fromPatterns(value, [
|
|
15
12
|
// Start sign P
|
|
16
13
|
/[^0-9T]?/,
|
|
17
14
|
// date part
|
|
@@ -21,10 +18,10 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
21
18
|
// Time part
|
|
22
19
|
/.*/,
|
|
23
20
|
]);
|
|
24
|
-
|
|
21
|
+
log('Duration ISO8601: "%s" => %O', tokens.value, tokens);
|
|
25
22
|
const res = tokens.eachCheck(p => {
|
|
26
23
|
if (!p || !p.value) {
|
|
27
|
-
return
|
|
24
|
+
return unmatched('', 'missing-token', {
|
|
28
25
|
expects: [{ type: 'const', value: 'P' }],
|
|
29
26
|
partName: 'duration',
|
|
30
27
|
});
|
|
@@ -40,8 +37,11 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
40
37
|
if (!d || !d.value) {
|
|
41
38
|
return;
|
|
42
39
|
}
|
|
43
|
-
const [num, sign, extra] =
|
|
44
|
-
(
|
|
40
|
+
const [num, sign, extra] = TokenCollection.fromPatterns(d, [/[0-9]+/, /./]);
|
|
41
|
+
if (!num) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
log('Date part: "%s" => %O', d.value, { num, sign });
|
|
45
45
|
if (!num.match(/^[0-9]+$/)) {
|
|
46
46
|
return num.unmatched({
|
|
47
47
|
reason: 'unexpected-token',
|
|
@@ -50,7 +50,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
if (!sign || !sign.value) {
|
|
53
|
-
return
|
|
53
|
+
return unmatched('', 'missing-token', {
|
|
54
54
|
expects: [{ type: 'const', value: 'D' }],
|
|
55
55
|
partName: 'date',
|
|
56
56
|
});
|
|
@@ -70,7 +70,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
70
70
|
}
|
|
71
71
|
}, t => {
|
|
72
72
|
if (!t || !t.value) {
|
|
73
|
-
return
|
|
73
|
+
return unmatched('', 'missing-token', {
|
|
74
74
|
expects: [{ type: 'const', value: 'T' }],
|
|
75
75
|
});
|
|
76
76
|
}
|
|
@@ -82,7 +82,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
82
82
|
}
|
|
83
83
|
}, time => {
|
|
84
84
|
if (!time) {
|
|
85
|
-
return
|
|
85
|
+
return unmatched('', 'missing-token', {
|
|
86
86
|
expects: [
|
|
87
87
|
{ type: 'common', value: 'hour' },
|
|
88
88
|
{ type: 'common', value: 'minute' },
|
|
@@ -91,7 +91,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
91
91
|
partName: 'time',
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
const timeTokens =
|
|
94
|
+
const timeTokens = TokenCollection.fromPatterns(time, [
|
|
95
95
|
// Hour part
|
|
96
96
|
/[0-9]+(\.[0-9]*)?[^0-9]?/,
|
|
97
97
|
// Minute part
|
|
@@ -99,10 +99,10 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
99
99
|
// Second part
|
|
100
100
|
/[0-9]+(\.[0-9]*)?[^0-9]?/,
|
|
101
101
|
]);
|
|
102
|
-
|
|
102
|
+
log('Time part: "%s" => %O', timeTokens.value, timeTokens);
|
|
103
103
|
const [h, m, s] = timeTokens;
|
|
104
|
-
if ((
|
|
105
|
-
return
|
|
104
|
+
if ((h?.value ?? '') + (m?.value ?? '') + (s?.value ?? '') === '') {
|
|
105
|
+
return unmatched('', 'missing-token', {
|
|
106
106
|
expects: [
|
|
107
107
|
{ type: 'common', value: 'hour' },
|
|
108
108
|
{ type: 'common', value: 'minute' },
|
|
@@ -112,7 +112,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
112
112
|
}
|
|
113
113
|
const specified = new Set();
|
|
114
114
|
for (const t of timeTokens) {
|
|
115
|
-
if (!t
|
|
115
|
+
if (!t.value) {
|
|
116
116
|
continue;
|
|
117
117
|
}
|
|
118
118
|
if (specified.has('S')) {
|
|
@@ -120,8 +120,11 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
120
120
|
reason: 'extra-token',
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
-
const [num, dpfp, sign] =
|
|
124
|
-
|
|
123
|
+
const [num, dpfp, sign] = TokenCollection.fromPatterns(t, [/[0-9]+/, /(\.[0-9]*)?/, /[^0-9]+/]);
|
|
124
|
+
if (!num) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
log('Time part (h|m|s): "%s" => %O', t.value, { num, dpfp, sign });
|
|
125
128
|
if (!num.match(/^[0-9]+$/)) {
|
|
126
129
|
return num.unmatched({
|
|
127
130
|
reason: 'unexpected-token',
|
|
@@ -130,8 +133,11 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
130
133
|
});
|
|
131
134
|
}
|
|
132
135
|
if (dpfp && dpfp.value) {
|
|
133
|
-
const [dp, fp] =
|
|
134
|
-
|
|
136
|
+
const [dp, fp] = TokenCollection.fromPatterns(dpfp, [/\./, /[0-9]+/]);
|
|
137
|
+
if (!dp) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
log('Second fractional part (h|m|s): "%s" => %O', dpfp.value, { dp, fp });
|
|
135
141
|
if (!dp.match('.')) {
|
|
136
142
|
return dp.unmatched({
|
|
137
143
|
reason: 'unexpected-token',
|
|
@@ -140,7 +146,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
140
146
|
});
|
|
141
147
|
}
|
|
142
148
|
if (!fp || !fp.value) {
|
|
143
|
-
return
|
|
149
|
+
return unmatched('', 'missing-token', {
|
|
144
150
|
expects: [{ type: 'common', value: 'fractional part' }],
|
|
145
151
|
partName: 'second',
|
|
146
152
|
});
|
|
@@ -166,7 +172,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
166
172
|
{ type: 'const', value: 'S' },
|
|
167
173
|
];
|
|
168
174
|
if (!sign || !sign.value) {
|
|
169
|
-
return
|
|
175
|
+
return unmatched('', 'missing-token', {
|
|
170
176
|
expects: expects.filter(e => !specified.has(e.value)),
|
|
171
177
|
partName: 'time',
|
|
172
178
|
});
|
|
@@ -189,17 +195,16 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
189
195
|
}
|
|
190
196
|
specified.add(sign.value);
|
|
191
197
|
}
|
|
192
|
-
},
|
|
198
|
+
}, datetimeTokenCheck.extra);
|
|
193
199
|
if (!res.matched) {
|
|
194
|
-
|
|
200
|
+
log('Failed: %O', res);
|
|
195
201
|
}
|
|
196
202
|
return res;
|
|
197
203
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
(0, debug_1.log)('CHECK: duration-string (duration component list)');
|
|
204
|
+
export const checkDurationComponentListString = () => function checkDurationComponentListString(value) {
|
|
205
|
+
log('CHECK: duration-string (duration component list)');
|
|
201
206
|
if (!value) {
|
|
202
|
-
return
|
|
207
|
+
return unmatched('', 'empty-token', {
|
|
203
208
|
expects: [{ type: 'common', value: 'time' }],
|
|
204
209
|
});
|
|
205
210
|
}
|
|
@@ -222,16 +227,16 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
|
|
|
222
227
|
// 6. Zero or more ASCII whitespace.
|
|
223
228
|
/\s*/,
|
|
224
229
|
];
|
|
225
|
-
const tokens =
|
|
230
|
+
const tokens = TokenCollection.fromPatterns(value, patterns, { repeat: true });
|
|
226
231
|
const components = tokens.chunk(patterns.length);
|
|
227
232
|
const specified = new Set();
|
|
228
233
|
for (const component of components) {
|
|
229
|
-
|
|
234
|
+
log('Duration Component: "%s" => %O', component.value, component);
|
|
230
235
|
const [, , dpfp, , unit] = component;
|
|
231
236
|
const res = component.eachCheck(ws => { }, num => {
|
|
232
237
|
if (!num || !num.value) {
|
|
233
|
-
const reason =
|
|
234
|
-
return
|
|
238
|
+
const reason = dpfp?.value || unit?.value ? 'unexpected-token' : 'missing-token';
|
|
239
|
+
return unmatched('', reason, {
|
|
235
240
|
expects: [{ type: 'common', value: 'time' }],
|
|
236
241
|
});
|
|
237
242
|
}
|
|
@@ -253,9 +258,9 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
|
|
|
253
258
|
partName: 'unit',
|
|
254
259
|
});
|
|
255
260
|
}
|
|
256
|
-
const [, fp] =
|
|
261
|
+
const [, fp] = TokenCollection.fromPatterns(dpfp, [/\./, /[0-9]+/]);
|
|
257
262
|
if (!fp || !fp.value) {
|
|
258
|
-
return
|
|
263
|
+
return unmatched('', 'missing-token', {
|
|
259
264
|
expects: [{ type: 'common', value: 'fractional part' }],
|
|
260
265
|
partName: 'fractional part',
|
|
261
266
|
});
|
|
@@ -283,7 +288,7 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
|
|
|
283
288
|
{ type: 'const', value: 's' },
|
|
284
289
|
].filter(e => !specified.has(e.value));
|
|
285
290
|
if (!unit || !unit.value) {
|
|
286
|
-
return
|
|
291
|
+
return unmatched('', 'missing-token', {
|
|
287
292
|
expects,
|
|
288
293
|
partName: 'unit',
|
|
289
294
|
});
|
|
@@ -313,10 +318,9 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
|
|
|
313
318
|
specified.add(unitVal);
|
|
314
319
|
}, ws => { });
|
|
315
320
|
if (!res.matched) {
|
|
316
|
-
|
|
321
|
+
log('Failed: %O', res);
|
|
317
322
|
return res;
|
|
318
323
|
}
|
|
319
324
|
}
|
|
320
|
-
return
|
|
325
|
+
return matched();
|
|
321
326
|
};
|
|
322
|
-
exports.checkDurationComponentListString = checkDurationComponentListString;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const token_1 = require("../../token");
|
|
7
|
-
const datetime_tokens_1 = require("./datetime-tokens");
|
|
8
|
-
const time_zone_offset_string_1 = require("./time-zone-offset-string");
|
|
1
|
+
import { log } from '../../debug.js';
|
|
2
|
+
import { unmatched } from '../../match-result.js';
|
|
3
|
+
import { TokenCollection } from '../../token/index.js';
|
|
4
|
+
import { datetimeTokenCheck } from './datetime-tokens.js';
|
|
5
|
+
import { parseTimeZone } from './time-zone-offset-string.js';
|
|
9
6
|
/**
|
|
10
7
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#global-dates-and-times
|
|
11
8
|
*/
|
|
12
|
-
const checkGlobalDateAndTimeString = () => function checkGlobalDateAndTimeString(value) {
|
|
13
|
-
|
|
14
|
-
const tokens =
|
|
9
|
+
export const checkGlobalDateAndTimeString = () => function checkGlobalDateAndTimeString(value) {
|
|
10
|
+
log('CHECK: global-date-and-time-string');
|
|
11
|
+
const tokens = TokenCollection.fromPatterns(value, [
|
|
15
12
|
// YYYY
|
|
16
13
|
/[^-]*/,
|
|
17
14
|
// -
|
|
@@ -35,32 +32,31 @@ const checkGlobalDateAndTimeString = () => function checkGlobalDateAndTimeString
|
|
|
35
32
|
// time-zone
|
|
36
33
|
/.*/,
|
|
37
34
|
]);
|
|
38
|
-
|
|
39
|
-
const res = tokens.eachCheck(
|
|
35
|
+
log('Global Date and Time "%s" => %O', tokens.value, tokens);
|
|
36
|
+
const res = tokens.eachCheck(datetimeTokenCheck.year, datetimeTokenCheck.hyphen, datetimeTokenCheck.month, datetimeTokenCheck.hyphen, datetimeTokenCheck.date, datetimeTokenCheck.localDateTimeSeparator, datetimeTokenCheck.hour, datetimeTokenCheck.colon, datetimeTokenCheck.minute, second => {
|
|
40
37
|
if (!second || !second.value) {
|
|
41
38
|
return;
|
|
42
39
|
}
|
|
43
|
-
const secondTokens =
|
|
44
|
-
|
|
45
|
-
const res = secondTokens.eachCheck(
|
|
40
|
+
const secondTokens = TokenCollection.fromPatterns(second, [/:?/, /[0-9]*/, /\.?/, /[0-9]*/]);
|
|
41
|
+
log('Second Part: "%s" => %O', secondTokens.value, secondTokens);
|
|
42
|
+
const res = secondTokens.eachCheck(datetimeTokenCheck.colon, datetimeTokenCheck.second, datetimeTokenCheck.decimalPointOrEnd, datetimeTokenCheck.secondFractionalPart);
|
|
46
43
|
if (!res.matched) {
|
|
47
44
|
return res;
|
|
48
45
|
}
|
|
49
46
|
}, zone => {
|
|
50
47
|
if (!zone || !zone.value) {
|
|
51
|
-
return
|
|
48
|
+
return unmatched(value, 'missing-token', {
|
|
52
49
|
expects: [{ type: 'common', value: 'time-zone' }],
|
|
53
50
|
partName: 'time-zone',
|
|
54
51
|
});
|
|
55
52
|
}
|
|
56
|
-
const res =
|
|
53
|
+
const res = parseTimeZone(zone);
|
|
57
54
|
if (!res.matched) {
|
|
58
55
|
return res;
|
|
59
56
|
}
|
|
60
|
-
},
|
|
57
|
+
}, datetimeTokenCheck.extra);
|
|
61
58
|
if (!res.matched) {
|
|
62
|
-
|
|
59
|
+
log('Failed: %O', res);
|
|
63
60
|
}
|
|
64
61
|
return res;
|
|
65
62
|
};
|
|
66
|
-
exports.checkGlobalDateAndTimeString = checkGlobalDateAndTimeString;
|
|
@@ -1,35 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const week_string_1 = require("./week-string");
|
|
13
|
-
const year_string_1 = require("./year-string");
|
|
14
|
-
const yearless_date_string_1 = require("./yearless-date-string");
|
|
1
|
+
import { checkMultiTypes } from '../../check-multi-types.js';
|
|
2
|
+
import { checkDateString } from './date-string.js';
|
|
3
|
+
import { checkDurationComponentListString, checkDurationISO8601LikeString } from './duration-string.js';
|
|
4
|
+
import { checkGlobalDateAndTimeString } from './global-date-and-time-string.js';
|
|
5
|
+
import { checkLocalDateAndTimeString, checkNormalizedLocalDateAndTimeString } from './local-date-and-time-string.js';
|
|
6
|
+
import { checkMonthString } from './month-string.js';
|
|
7
|
+
import { checkTimeString } from './time-string.js';
|
|
8
|
+
import { checkTimeZoneOffsetString } from './time-zone-offset-string.js';
|
|
9
|
+
import { checkWeekString } from './week-string.js';
|
|
10
|
+
import { checkYearString } from './year-string.js';
|
|
11
|
+
import { checkYearlessDateString } from './yearless-date-string.js';
|
|
15
12
|
const checks = [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
checkDateString(),
|
|
14
|
+
checkTimeString(),
|
|
15
|
+
checkMonthString(),
|
|
16
|
+
checkYearlessDateString(),
|
|
17
|
+
checkLocalDateAndTimeString(),
|
|
18
|
+
checkNormalizedLocalDateAndTimeString(),
|
|
19
|
+
checkTimeZoneOffsetString(),
|
|
20
|
+
checkGlobalDateAndTimeString(),
|
|
21
|
+
checkWeekString(),
|
|
22
|
+
checkYearString(),
|
|
23
|
+
checkDurationISO8601LikeString(),
|
|
24
|
+
checkDurationComponentListString(),
|
|
28
25
|
];
|
|
29
26
|
/**
|
|
30
27
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates-and-times
|
|
31
28
|
*/
|
|
32
|
-
const checkDateTime = () => value => {
|
|
33
|
-
return
|
|
29
|
+
export const checkDateTime = () => value => {
|
|
30
|
+
return checkMultiTypes(value, checks);
|
|
34
31
|
};
|
|
35
|
-
exports.checkDateTime = checkDateTime;
|