@markuplint/types 3.12.0 → 4.0.0-alpha.10
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/LICENSE +1 -1
- package/lib/check-multi-types.d.ts +2 -5
- package/lib/check-multi-types.js +9 -14
- package/lib/check.d.ts +1 -1
- package/lib/check.js +20 -30
- package/lib/css-syntax.d.ts +1 -1
- package/lib/css-syntax.js +33 -33
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +2 -1
- package/lib/defs.js +188 -138
- package/lib/enum.d.ts +2 -2
- package/lib/enum.js +7 -12
- package/lib/get-candidate.d.ts +1 -4
- package/lib/get-candidate.js +5 -10
- 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 +20 -25
- package/lib/list.d.ts +2 -2
- package/lib/list.js +9 -14
- package/lib/match-result.d.ts +8 -21
- package/lib/match-result.js +6 -13
- package/lib/number.d.ts +3 -3
- package/lib/number.js +13 -17
- package/lib/primitive/index.d.ts +7 -7
- package/lib/primitive/index.js +7 -17
- package/lib/primitive/is-float.js +2 -6
- package/lib/primitive/is-int.js +2 -6
- package/lib/primitive/is-non-zero-uint.js +2 -6
- package/lib/primitive/is-quantity.d.ts +1 -5
- package/lib/primitive/is-quantity.js +9 -13
- package/lib/primitive/is-uint.d.ts +3 -6
- package/lib/primitive/is-uint.js +4 -8
- package/lib/primitive/range.js +3 -7
- package/lib/primitive/split-unit.d.ts +2 -2
- package/lib/primitive/split-unit.js +4 -8
- 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 +58 -70
- package/lib/token/token-collection.js +47 -56
- package/lib/token/token.d.ts +54 -59
- package/lib/token/token.js +14 -20
- package/lib/token/types.js +1 -2
- package/lib/types.d.ts +58 -82
- package/lib/types.js +1 -2
- package/lib/types.schema.d.ts +31 -1087
- package/lib/types.schema.js +1 -2
- package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
- package/lib/w3c/check-serialized-permissions-policy.js +21 -25
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +34 -41
- package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/date-string.js +12 -16
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +2 -22
- package/lib/whatwg/check-datetime/datetime-tokens.js +58 -64
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +64 -69
- 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 +24 -28
- 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 +37 -41
- 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 +13 -17
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +22 -28
- package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/week-string.js +11 -15
- 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 +11 -15
- package/lib/whatwg/check-mime-type.d.ts +5 -5
- package/lib/whatwg/check-mime-type.js +11 -17
- package/lib/whatwg/is-abs-url.d.ts +1 -1
- package/lib/whatwg/is-abs-url.js +8 -12
- package/lib/whatwg/is-browser-context-name.d.ts +1 -1
- package/lib/whatwg/is-browser-context-name.js +1 -5
- package/lib/whatwg/is-custom-element-name.d.ts +10 -5
- package/lib/whatwg/is-custom-element-name.js +22 -38
- package/lib/whatwg/is-itemprop-name.d.ts +1 -1
- package/lib/whatwg/is-itemprop-name.js +1 -5
- package/lib/whatwg/is-navigable-target-name.d.ts +1 -1
- package/lib/whatwg/is-navigable-target-name.js +1 -5
- package/package.json +17 -9
- package/test/check.spec.js +0 -89
- package/test/css-syntax.spec.js +0 -170
- package/test/list.spec.js +0 -133
- package/test/primitive/index.spec.js +0 -65
- package/test/rfc/is-bcp-47.spec.js +0 -23
- package/test/token/token-collection.spec.js +0 -146
- package/test/w3c/check-serialized-permissions-policy.spec.js +0 -36
- package/test/whatwg/check-autocomplete.spec.js +0 -387
- package/test/whatwg/check-datetime/index.spec.js +0 -336
- package/test/whatwg/check-mime-type.spec.js +0 -59
- package/test/whatwg/is-abs-url.spec.js +0 -8
|
@@ -1,35 +1,32 @@
|
|
|
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
|
+
/[^\dT]?/,
|
|
17
14
|
// date part
|
|
18
15
|
/[^T]*/,
|
|
19
16
|
// Time sign T
|
|
20
|
-
|
|
17
|
+
/\D?/,
|
|
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
|
});
|
|
31
28
|
}
|
|
32
|
-
if (!p.
|
|
29
|
+
if (!p.matches('P', false)) {
|
|
33
30
|
return p.unmatched({
|
|
34
31
|
reason: 'unexpected-token',
|
|
35
32
|
expects: [{ type: 'const', value: 'P' }],
|
|
@@ -40,12 +37,12 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
40
37
|
if (!d || !d.value) {
|
|
41
38
|
return;
|
|
42
39
|
}
|
|
43
|
-
const [num, sign, extra] =
|
|
40
|
+
const [num, sign, extra] = TokenCollection.fromPatterns(d, [/\d+/, /./]);
|
|
44
41
|
if (!num) {
|
|
45
42
|
return;
|
|
46
43
|
}
|
|
47
|
-
|
|
48
|
-
if (!num.
|
|
44
|
+
log('Date part: "%s" => %O', d.value, { num, sign });
|
|
45
|
+
if (!num.matches(/^\d+$/)) {
|
|
49
46
|
return num.unmatched({
|
|
50
47
|
reason: 'unexpected-token',
|
|
51
48
|
expects: [],
|
|
@@ -53,12 +50,12 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
53
50
|
});
|
|
54
51
|
}
|
|
55
52
|
if (!sign || !sign.value) {
|
|
56
|
-
return
|
|
53
|
+
return unmatched('', 'missing-token', {
|
|
57
54
|
expects: [{ type: 'const', value: 'D' }],
|
|
58
55
|
partName: 'date',
|
|
59
56
|
});
|
|
60
57
|
}
|
|
61
|
-
if (!sign.
|
|
58
|
+
if (!sign.matches('D', false)) {
|
|
62
59
|
return sign.unmatched({
|
|
63
60
|
reason: 'unexpected-token',
|
|
64
61
|
expects: [{ type: 'const', value: 'D' }],
|
|
@@ -73,20 +70,19 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
73
70
|
}
|
|
74
71
|
}, t => {
|
|
75
72
|
if (!t || !t.value) {
|
|
76
|
-
return
|
|
73
|
+
return unmatched('', 'missing-token', {
|
|
77
74
|
expects: [{ type: 'const', value: 'T' }],
|
|
78
75
|
});
|
|
79
76
|
}
|
|
80
|
-
if (!t.
|
|
77
|
+
if (!t.matches('T', false)) {
|
|
81
78
|
return t.unmatched({
|
|
82
79
|
reason: 'unexpected-token',
|
|
83
80
|
expects: [{ type: 'const', value: 'T' }],
|
|
84
81
|
});
|
|
85
82
|
}
|
|
86
83
|
}, time => {
|
|
87
|
-
var _a, _b, _c;
|
|
88
84
|
if (!time) {
|
|
89
|
-
return
|
|
85
|
+
return unmatched('', 'missing-token', {
|
|
90
86
|
expects: [
|
|
91
87
|
{ type: 'common', value: 'hour' },
|
|
92
88
|
{ type: 'common', value: 'minute' },
|
|
@@ -95,18 +91,18 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
95
91
|
partName: 'time',
|
|
96
92
|
});
|
|
97
93
|
}
|
|
98
|
-
const timeTokens =
|
|
94
|
+
const timeTokens = TokenCollection.fromPatterns(time, [
|
|
99
95
|
// Hour part
|
|
100
|
-
|
|
96
|
+
/\d+(\.\d*)?\D?/,
|
|
101
97
|
// Minute part
|
|
102
|
-
|
|
98
|
+
/\d+(\.\d*)?\D?/,
|
|
103
99
|
// Second part
|
|
104
|
-
|
|
100
|
+
/\d+(\.\d*)?\D?/,
|
|
105
101
|
]);
|
|
106
|
-
|
|
102
|
+
log('Time part: "%s" => %O', timeTokens.value, timeTokens);
|
|
107
103
|
const [h, m, s] = timeTokens;
|
|
108
|
-
if ((
|
|
109
|
-
return
|
|
104
|
+
if ((h?.value ?? '') + (m?.value ?? '') + (s?.value ?? '') === '') {
|
|
105
|
+
return unmatched('', 'missing-token', {
|
|
110
106
|
expects: [
|
|
111
107
|
{ type: 'common', value: 'hour' },
|
|
112
108
|
{ type: 'common', value: 'minute' },
|
|
@@ -124,12 +120,12 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
124
120
|
reason: 'extra-token',
|
|
125
121
|
});
|
|
126
122
|
}
|
|
127
|
-
const [num, dpfp, sign] =
|
|
123
|
+
const [num, dpfp, sign] = TokenCollection.fromPatterns(t, [/\d+/, /(\.\d*)?/, /\D+/]);
|
|
128
124
|
if (!num) {
|
|
129
125
|
continue;
|
|
130
126
|
}
|
|
131
|
-
|
|
132
|
-
if (!num.
|
|
127
|
+
log('Time part (h|m|s): "%s" => %O', t.value, { num, dpfp, sign });
|
|
128
|
+
if (!num.matches(/^\d+$/)) {
|
|
133
129
|
return num.unmatched({
|
|
134
130
|
reason: 'unexpected-token',
|
|
135
131
|
expects: [{ type: 'common', value: 'number' }],
|
|
@@ -137,12 +133,12 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
137
133
|
});
|
|
138
134
|
}
|
|
139
135
|
if (dpfp && dpfp.value) {
|
|
140
|
-
const [dp, fp] =
|
|
136
|
+
const [dp, fp] = TokenCollection.fromPatterns(dpfp, [/\./, /\d+/]);
|
|
141
137
|
if (!dp) {
|
|
142
138
|
continue;
|
|
143
139
|
}
|
|
144
|
-
|
|
145
|
-
if (!dp.
|
|
140
|
+
log('Second fractional part (h|m|s): "%s" => %O', dpfp.value, { dp, fp });
|
|
141
|
+
if (!dp.matches('.')) {
|
|
146
142
|
return dp.unmatched({
|
|
147
143
|
reason: 'unexpected-token',
|
|
148
144
|
expects: [],
|
|
@@ -150,19 +146,19 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
150
146
|
});
|
|
151
147
|
}
|
|
152
148
|
if (!fp || !fp.value) {
|
|
153
|
-
return
|
|
149
|
+
return unmatched('', 'missing-token', {
|
|
154
150
|
expects: [{ type: 'common', value: 'fractional part' }],
|
|
155
151
|
partName: 'second',
|
|
156
152
|
});
|
|
157
153
|
}
|
|
158
|
-
if (!fp.
|
|
154
|
+
if (!fp.matches(/^\d+$/)) {
|
|
159
155
|
return fp.unmatched({
|
|
160
156
|
reason: 'unexpected-token',
|
|
161
157
|
expects: [],
|
|
162
158
|
partName: 'fractional part',
|
|
163
159
|
});
|
|
164
160
|
}
|
|
165
|
-
if (!(
|
|
161
|
+
if (!(fp.length > 0 && fp.length <= 3)) {
|
|
166
162
|
return fp.unmatched({
|
|
167
163
|
reason: { type: 'out-of-range-length-digit', gte: 1, lte: 3 },
|
|
168
164
|
expects: [],
|
|
@@ -176,21 +172,21 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
176
172
|
{ type: 'const', value: 'S' },
|
|
177
173
|
];
|
|
178
174
|
if (!sign || !sign.value) {
|
|
179
|
-
return
|
|
175
|
+
return unmatched('', 'missing-token', {
|
|
180
176
|
expects: expects.filter(e => !specified.has(e.value)),
|
|
181
177
|
partName: 'time',
|
|
182
178
|
});
|
|
183
179
|
}
|
|
184
|
-
if (specified.has('M') && sign.
|
|
180
|
+
if (specified.has('M') && sign.matches('H', false)) {
|
|
185
181
|
return sign.unmatched({
|
|
186
182
|
reason: 'unexpected-token',
|
|
187
183
|
expects: [{ type: 'const', value: 'S' }],
|
|
188
184
|
partName: 'time',
|
|
189
185
|
});
|
|
190
186
|
}
|
|
191
|
-
if (!sign.
|
|
192
|
-
(sign.
|
|
193
|
-
(sign.
|
|
187
|
+
if (!sign.matches(['H', 'M', 'S'], false) ||
|
|
188
|
+
(sign.matches('H', false) && specified.has('H')) ||
|
|
189
|
+
(sign.matches('M', false) && specified.has('M'))) {
|
|
194
190
|
return sign.unmatched({
|
|
195
191
|
reason: 'unexpected-token',
|
|
196
192
|
expects: expects.filter(e => !specified.has(e.value)),
|
|
@@ -199,17 +195,16 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
|
|
|
199
195
|
}
|
|
200
196
|
specified.add(sign.value);
|
|
201
197
|
}
|
|
202
|
-
},
|
|
198
|
+
}, datetimeTokenCheck.extra);
|
|
203
199
|
if (!res.matched) {
|
|
204
|
-
|
|
200
|
+
log('Failed: %O', res);
|
|
205
201
|
}
|
|
206
202
|
return res;
|
|
207
203
|
};
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
(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)');
|
|
211
206
|
if (!value) {
|
|
212
|
-
return
|
|
207
|
+
return unmatched('', 'empty-token', {
|
|
213
208
|
expects: [{ type: 'common', value: 'time' }],
|
|
214
209
|
});
|
|
215
210
|
}
|
|
@@ -219,29 +214,30 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
|
|
|
219
214
|
// 2. One or more ASCII digits, representing a number of time units,
|
|
220
215
|
// scaled by the duration time component scale specified (see below)
|
|
221
216
|
// to represent a number of seconds.
|
|
222
|
-
|
|
217
|
+
/\d+/,
|
|
223
218
|
// 3. If the duration time component scale specified is 1 (i.e. the units are seconds),
|
|
224
219
|
// then, optionally, a U+002E FULL STOP character (.) followed by
|
|
225
220
|
// one, two, or three ASCII digits, representing a fraction of a second.
|
|
226
|
-
/(
|
|
221
|
+
/(\.\d*)?/,
|
|
227
222
|
// 4. Zero or more ASCII whitespace.
|
|
228
223
|
/\s*/,
|
|
229
224
|
// 5. One of the following characters, representing the duration time component scale
|
|
230
225
|
// of the time unit used in the numeric part of the duration time component:
|
|
231
|
-
|
|
226
|
+
/\D/,
|
|
232
227
|
// 6. Zero or more ASCII whitespace.
|
|
233
228
|
/\s*/,
|
|
234
229
|
];
|
|
235
|
-
const tokens =
|
|
230
|
+
const tokens = TokenCollection.fromPatterns(value, patterns, { repeat: true });
|
|
236
231
|
const components = tokens.chunk(patterns.length);
|
|
237
232
|
const specified = new Set();
|
|
238
233
|
for (const component of components) {
|
|
239
|
-
|
|
240
|
-
const
|
|
234
|
+
log('Duration Component: "%s" => %O', component.value, component);
|
|
235
|
+
const dpfp = component[2];
|
|
236
|
+
const unit = component[4];
|
|
241
237
|
const res = component.eachCheck(ws => { }, num => {
|
|
242
238
|
if (!num || !num.value) {
|
|
243
|
-
const reason =
|
|
244
|
-
return
|
|
239
|
+
const reason = dpfp?.value || unit?.value ? 'unexpected-token' : 'missing-token';
|
|
240
|
+
return unmatched('', reason, {
|
|
245
241
|
expects: [{ type: 'common', value: 'time' }],
|
|
246
242
|
});
|
|
247
243
|
}
|
|
@@ -263,21 +259,21 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
|
|
|
263
259
|
partName: 'unit',
|
|
264
260
|
});
|
|
265
261
|
}
|
|
266
|
-
const [, fp] =
|
|
262
|
+
const [, fp] = TokenCollection.fromPatterns(dpfp, [/\./, /\d+/]);
|
|
267
263
|
if (!fp || !fp.value) {
|
|
268
|
-
return
|
|
264
|
+
return unmatched('', 'missing-token', {
|
|
269
265
|
expects: [{ type: 'common', value: 'fractional part' }],
|
|
270
266
|
partName: 'fractional part',
|
|
271
267
|
});
|
|
272
268
|
}
|
|
273
|
-
if (!fp.
|
|
269
|
+
if (!fp.matches(/\d+/)) {
|
|
274
270
|
return fp.unmatched({
|
|
275
271
|
reason: 'unexpected-token',
|
|
276
272
|
expects: [{ type: 'common', value: 'fractional part' }],
|
|
277
273
|
partName: 'fractional part',
|
|
278
274
|
});
|
|
279
275
|
}
|
|
280
|
-
if (!(
|
|
276
|
+
if (!(fp.length > 0 && fp.length <= 3)) {
|
|
281
277
|
return fp.unmatched({
|
|
282
278
|
reason: { type: 'out-of-range-length-digit', gte: 1, lte: 3 },
|
|
283
279
|
expects: [],
|
|
@@ -293,7 +289,7 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
|
|
|
293
289
|
{ type: 'const', value: 's' },
|
|
294
290
|
].filter(e => !specified.has(e.value));
|
|
295
291
|
if (!unit || !unit.value) {
|
|
296
|
-
return
|
|
292
|
+
return unmatched('', 'missing-token', {
|
|
297
293
|
expects,
|
|
298
294
|
partName: 'unit',
|
|
299
295
|
});
|
|
@@ -306,14 +302,14 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
|
|
|
306
302
|
partName: 'unit',
|
|
307
303
|
});
|
|
308
304
|
}
|
|
309
|
-
if (dpfp && dpfp.value && unit.
|
|
305
|
+
if (dpfp && dpfp.value && unit.matches(['w', 'd', 'h', 'm'])) {
|
|
310
306
|
return unit.unmatched({
|
|
311
307
|
reason: 'unexpected-token',
|
|
312
308
|
expects: [{ type: 'const', value: 's' }],
|
|
313
309
|
partName: 'unit',
|
|
314
310
|
});
|
|
315
311
|
}
|
|
316
|
-
if (!unit.
|
|
312
|
+
if (!unit.matches(['w', 'd', 'h', 'm', 's'])) {
|
|
317
313
|
return unit.unmatched({
|
|
318
314
|
reason: 'unexpected-token',
|
|
319
315
|
expects,
|
|
@@ -323,10 +319,9 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
|
|
|
323
319
|
specified.add(unitVal);
|
|
324
320
|
}, ws => { });
|
|
325
321
|
if (!res.matched) {
|
|
326
|
-
|
|
322
|
+
log('Failed: %O', res);
|
|
327
323
|
return res;
|
|
328
324
|
}
|
|
329
325
|
}
|
|
330
|
-
return
|
|
326
|
+
return matched();
|
|
331
327
|
};
|
|
332
|
-
exports.checkDurationComponentListString = checkDurationComponentListString;
|
|
@@ -1,66 +1,62 @@
|
|
|
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
|
// -
|
|
18
|
-
|
|
15
|
+
/\D?/,
|
|
19
16
|
// MM
|
|
20
17
|
/[^-]*/,
|
|
21
18
|
// -
|
|
22
|
-
|
|
19
|
+
/\D?/,
|
|
23
20
|
// DD
|
|
24
|
-
/[
|
|
21
|
+
/[^\sT]*/,
|
|
25
22
|
// T \s
|
|
26
|
-
|
|
23
|
+
/\D?/,
|
|
27
24
|
// hh
|
|
28
25
|
/[^:]*/,
|
|
29
26
|
// :
|
|
30
|
-
|
|
27
|
+
/\D?/,
|
|
31
28
|
// mm
|
|
32
|
-
/[
|
|
29
|
+
/[^+:Z-]*/,
|
|
33
30
|
// :ss.sss
|
|
34
|
-
/(:[
|
|
31
|
+
/(:[^+Z-]*)?/,
|
|
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, [/:?/, /\d*/, /\.?/, /\d*/]);
|
|
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;
|