@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
package/lib/types.schema.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* This file was automatically generated by json-schema-to-typescript.
|
|
4
3
|
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
4
|
* and run json-schema-to-typescript to regenerate this file.
|
|
6
5
|
*/
|
|
7
|
-
|
|
6
|
+
export {};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../debug");
|
|
5
|
-
const match_result_1 = require("../match-result");
|
|
6
|
-
const token_1 = require("../token");
|
|
1
|
+
import { log } from '../debug.js';
|
|
2
|
+
import { matched, unmatched } from '../match-result.js';
|
|
3
|
+
import { TokenCollection } from '../token/index.js';
|
|
7
4
|
/**
|
|
8
5
|
* @see https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy
|
|
9
6
|
*
|
|
@@ -25,14 +22,13 @@ const token_1 = require("../token");
|
|
|
25
22
|
*
|
|
26
23
|
* `allow-list` is optional.
|
|
27
24
|
*/
|
|
28
|
-
const checkSerializedPermissionsPolicy = () => value => {
|
|
25
|
+
export const checkSerializedPermissionsPolicy = () => value => {
|
|
29
26
|
const res = _checkSerializedPermissionsPolicy(value);
|
|
30
27
|
if (!res.matched) {
|
|
31
|
-
|
|
28
|
+
log('Failed: %O', res);
|
|
32
29
|
}
|
|
33
30
|
return res;
|
|
34
31
|
};
|
|
35
|
-
exports.checkSerializedPermissionsPolicy = checkSerializedPermissionsPolicy;
|
|
36
32
|
function _checkSerializedPermissionsPolicy(value) {
|
|
37
33
|
/**
|
|
38
34
|
* The list of serialized-policy-directive
|
|
@@ -51,14 +47,14 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
51
47
|
*/
|
|
52
48
|
/;?/,
|
|
53
49
|
];
|
|
54
|
-
const tokens =
|
|
50
|
+
const tokens = TokenCollection.fromPatterns(value, patterns, { repeat: true });
|
|
55
51
|
const serializedPolicyDirectives = tokens.chunk(patterns.length);
|
|
56
|
-
|
|
52
|
+
log('Serialized Permissions Policy: %s => %O', value, serializedPolicyDirectives);
|
|
57
53
|
for (const [serializedPolicyDirective] of serializedPolicyDirectives) {
|
|
58
54
|
if (!serializedPolicyDirective || !serializedPolicyDirective.value) {
|
|
59
|
-
return
|
|
55
|
+
return unmatched('', 'empty-token');
|
|
60
56
|
}
|
|
61
|
-
const [aw, featureIdentifier, rws, allowListValue] =
|
|
57
|
+
const [aw, featureIdentifier, rws, allowListValue] = TokenCollection.fromPatterns(serializedPolicyDirective, [
|
|
62
58
|
/**
|
|
63
59
|
* Any whitespace
|
|
64
60
|
*/
|
|
@@ -70,7 +66,7 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
70
66
|
* > feature-identifier = 1*( ALPHA / DIGIT / "-")
|
|
71
67
|
* > ```
|
|
72
68
|
*/
|
|
73
|
-
|
|
69
|
+
/\S*/,
|
|
74
70
|
/**
|
|
75
71
|
* RWS (Required whitespace)
|
|
76
72
|
*
|
|
@@ -82,7 +78,7 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
82
78
|
*/
|
|
83
79
|
/.*/,
|
|
84
80
|
]);
|
|
85
|
-
|
|
81
|
+
log('Serialized Policy Directive: %s => %O', serializedPolicyDirective.value, {
|
|
86
82
|
aw,
|
|
87
83
|
featureIdentifier,
|
|
88
84
|
rws,
|
|
@@ -93,7 +89,7 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
93
89
|
* > feature-identifier = 1*( ALPHA / DIGIT / "-")
|
|
94
90
|
* > ```
|
|
95
91
|
*/
|
|
96
|
-
if (!featureIdentifier || !featureIdentifier.
|
|
92
|
+
if (!featureIdentifier || !featureIdentifier.matches(/^[\da-z-]+$/i)) {
|
|
97
93
|
return featureIdentifier.unmatched({
|
|
98
94
|
reason: 'unexpected-token',
|
|
99
95
|
expects: [{ type: 'common', value: 'feature-identifier' }],
|
|
@@ -116,16 +112,16 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
116
112
|
}
|
|
117
113
|
const allowListPatterns = [
|
|
118
114
|
// Value
|
|
119
|
-
|
|
115
|
+
/\S*/,
|
|
120
116
|
// Separator
|
|
121
117
|
/\s*/,
|
|
122
118
|
];
|
|
123
|
-
const allowListTokens =
|
|
119
|
+
const allowListTokens = TokenCollection.fromPatterns(allowListValue, allowListPatterns, { repeat: true });
|
|
124
120
|
const allowList = allowListTokens.chunk(allowListPatterns.length);
|
|
125
|
-
|
|
121
|
+
log('Allow List: %s => %O', allowListTokens.value, allowList);
|
|
126
122
|
for (const [allow] of allowList) {
|
|
127
123
|
if (!allow || !allow.value) {
|
|
128
|
-
return
|
|
124
|
+
return unmatched('', 'missing-token', {
|
|
129
125
|
expects: [
|
|
130
126
|
{ type: 'const', value: '*' },
|
|
131
127
|
{ type: 'const', value: "'self'" },
|
|
@@ -143,10 +139,10 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
143
139
|
if (origin.reason !== 'syntax-error') {
|
|
144
140
|
return origin;
|
|
145
141
|
}
|
|
146
|
-
if (allow.
|
|
142
|
+
if (allow.matches(['*', "'self'", "'src'", "'none'"], true)) {
|
|
147
143
|
continue;
|
|
148
144
|
}
|
|
149
|
-
if (allow.
|
|
145
|
+
if (allow.matches(['self', 'src', 'none'], true)) {
|
|
150
146
|
return allow.unmatched({
|
|
151
147
|
reason: 'missing-token',
|
|
152
148
|
expects: [{ type: 'common', value: 'single-quote' }],
|
|
@@ -166,7 +162,7 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
166
162
|
});
|
|
167
163
|
}
|
|
168
164
|
}
|
|
169
|
-
return
|
|
165
|
+
return matched();
|
|
170
166
|
}
|
|
171
167
|
/**
|
|
172
168
|
* serialized-origin
|
|
@@ -179,7 +175,7 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
179
175
|
*/
|
|
180
176
|
function checkSerializedOrigin(token) {
|
|
181
177
|
const url = parseUrl(token.value);
|
|
182
|
-
|
|
178
|
+
log('Parse URL: "%s" => %O', token.value, url);
|
|
183
179
|
if (!url) {
|
|
184
180
|
return token.unmatched({
|
|
185
181
|
expects: [{ type: 'common', value: 'serialized-origin' }],
|
|
@@ -254,7 +250,7 @@ function checkSerializedOrigin(token) {
|
|
|
254
250
|
partName: 'serialized-origin',
|
|
255
251
|
});
|
|
256
252
|
}
|
|
257
|
-
return
|
|
253
|
+
return matched();
|
|
258
254
|
}
|
|
259
255
|
function parseUrl(value) {
|
|
260
256
|
try {
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const match_result_1 = require("../match-result");
|
|
7
|
-
const token_1 = require("../token");
|
|
8
|
-
const acLog = debug_1.log.extend('autocomplete');
|
|
1
|
+
import { log } from '../debug.js';
|
|
2
|
+
import { getCandidate } from '../get-candidate.js';
|
|
3
|
+
import { matched } from '../match-result.js';
|
|
4
|
+
import { TokenCollection } from '../token/index.js';
|
|
5
|
+
const acLog = log.extend('autocomplete');
|
|
9
6
|
/**
|
|
10
7
|
* https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-section
|
|
11
8
|
*/
|
|
@@ -95,11 +92,11 @@ const URL_CONTACTABLE_FIELD = 'https://html.spec.whatwg.org/multipage/form-contr
|
|
|
95
92
|
/**
|
|
96
93
|
* @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete
|
|
97
94
|
*/
|
|
98
|
-
const checkAutoComplete = () => value => {
|
|
95
|
+
export const checkAutoComplete = () => value => {
|
|
99
96
|
let hasNamedGroup = false;
|
|
100
97
|
let hasPartOfAddress = false;
|
|
101
98
|
let hasContactingToken = false;
|
|
102
|
-
const tokens = new
|
|
99
|
+
const tokens = new TokenCollection(value, {
|
|
103
100
|
disallowToSurroundBySpaces: false,
|
|
104
101
|
allowEmpty: false,
|
|
105
102
|
ordered: true,
|
|
@@ -131,7 +128,7 @@ const checkAutoComplete = () => value => {
|
|
|
131
128
|
// > an ordered set of space-separated tokens consisting of
|
|
132
129
|
// > just autofill detail tokens
|
|
133
130
|
// > (i.e. the "on" and "off" keywords are not allowed).
|
|
134
|
-
if (head.
|
|
131
|
+
if (head.matches(['on', 'off'], true)) {
|
|
135
132
|
if (tail[0]) {
|
|
136
133
|
acLog('[Unmatched ("%s")] Unexpected pair with "on" or "off": "%s"', value, tail.value);
|
|
137
134
|
return tail[0].unmatched({
|
|
@@ -145,12 +142,12 @@ const checkAutoComplete = () => value => {
|
|
|
145
142
|
ref: URL_ON_OFF,
|
|
146
143
|
});
|
|
147
144
|
}
|
|
148
|
-
return
|
|
145
|
+
return matched();
|
|
149
146
|
}
|
|
150
147
|
// > Optionally, a token whose first eight characters are
|
|
151
148
|
// > an ASCII case-insensitive match for the string "section-",
|
|
152
149
|
// > meaning that the field belongs to the named group.
|
|
153
|
-
if (head.
|
|
150
|
+
if (head.matches(namedGroup, true)) {
|
|
154
151
|
hasNamedGroup = true;
|
|
155
152
|
const sectionToken = tail.search(namedGroup);
|
|
156
153
|
if (sectionToken) {
|
|
@@ -166,14 +163,14 @@ const checkAutoComplete = () => value => {
|
|
|
166
163
|
tail = headAndTail2.tail;
|
|
167
164
|
if (!head) {
|
|
168
165
|
// Missing autofill field name but it is valid
|
|
169
|
-
return
|
|
166
|
+
return matched();
|
|
170
167
|
}
|
|
171
168
|
}
|
|
172
169
|
// > Optionally, a token that is an ASCII case-insensitive match for
|
|
173
170
|
// > one of the following strings:
|
|
174
171
|
// > - "shipping", meaning the field is part of the shipping address or contact information
|
|
175
172
|
// > - "billing", meaning the field is part of the billing address or contact information
|
|
176
|
-
if (head.
|
|
173
|
+
if (head.matches(partOfAddress, true)) {
|
|
177
174
|
hasPartOfAddress = true;
|
|
178
175
|
const partToken = tail.search(partOfAddress);
|
|
179
176
|
if (partToken) {
|
|
@@ -194,18 +191,18 @@ const checkAutoComplete = () => value => {
|
|
|
194
191
|
tail = headAndTail3.tail;
|
|
195
192
|
if (!head) {
|
|
196
193
|
// Missing autofill field name but it is valid
|
|
197
|
-
return
|
|
194
|
+
return matched();
|
|
198
195
|
}
|
|
199
196
|
}
|
|
200
|
-
if (head.
|
|
197
|
+
if (head.matches(contactingTokens, true)) {
|
|
201
198
|
hasContactingToken = true;
|
|
202
199
|
const contactableFiledToken = tail[0];
|
|
203
200
|
if (!contactableFiledToken) {
|
|
204
201
|
// Missing autofill field name but it is valid
|
|
205
|
-
return
|
|
202
|
+
return matched();
|
|
206
203
|
}
|
|
207
|
-
if (!contactableFiledToken.
|
|
208
|
-
const candidate =
|
|
204
|
+
if (!contactableFiledToken.matches(contactableFieldNames, true)) {
|
|
205
|
+
const candidate = getCandidate(contactableFiledToken.value, contactableFieldNames);
|
|
209
206
|
acLog('[Unmatched ("%s")] Unexpected token: "%s"', value, contactableFiledToken.value);
|
|
210
207
|
return contactableFiledToken.unmatched({
|
|
211
208
|
reason: 'unexpected-token',
|
|
@@ -218,10 +215,10 @@ const checkAutoComplete = () => value => {
|
|
|
218
215
|
});
|
|
219
216
|
}
|
|
220
217
|
if (tail[1]) {
|
|
221
|
-
if (tail[1].
|
|
222
|
-
return
|
|
218
|
+
if (tail[1].matches(webauthnFieldNames)) {
|
|
219
|
+
return matched();
|
|
223
220
|
}
|
|
224
|
-
const candidate =
|
|
221
|
+
const candidate = getCandidate(tail[1].value, webauthnFieldNames);
|
|
225
222
|
if (candidate) {
|
|
226
223
|
acLog('[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ', value, tail[1].value, candidate);
|
|
227
224
|
}
|
|
@@ -239,14 +236,14 @@ const checkAutoComplete = () => value => {
|
|
|
239
236
|
ref: URL_AUTOFILL_FIELD,
|
|
240
237
|
});
|
|
241
238
|
}
|
|
242
|
-
return
|
|
239
|
+
return matched();
|
|
243
240
|
}
|
|
244
|
-
if (head.
|
|
241
|
+
if (head.matches([...autofillFieldNames, ...contactableFieldNames], true)) {
|
|
245
242
|
if (tail[0]) {
|
|
246
|
-
if (tail[0].
|
|
247
|
-
return
|
|
243
|
+
if (tail[0].matches(webauthnFieldNames)) {
|
|
244
|
+
return matched();
|
|
248
245
|
}
|
|
249
|
-
const candidate =
|
|
246
|
+
const candidate = getCandidate(tail[0].value, webauthnFieldNames);
|
|
250
247
|
if (candidate) {
|
|
251
248
|
acLog('[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ', value, tail[0].value, candidate);
|
|
252
249
|
}
|
|
@@ -264,10 +261,10 @@ const checkAutoComplete = () => value => {
|
|
|
264
261
|
ref: URL_AUTOFILL_FIELD,
|
|
265
262
|
});
|
|
266
263
|
}
|
|
267
|
-
return
|
|
264
|
+
return matched();
|
|
268
265
|
}
|
|
269
|
-
if (head.
|
|
270
|
-
return
|
|
266
|
+
if (head.matches(webauthnFieldNames)) {
|
|
267
|
+
return matched();
|
|
271
268
|
}
|
|
272
269
|
const expects = [
|
|
273
270
|
{
|
|
@@ -283,29 +280,26 @@ const checkAutoComplete = () => value => {
|
|
|
283
280
|
});
|
|
284
281
|
// Potentially typo a named group
|
|
285
282
|
const [prefix, namedGroupStr] = head.value.split('-');
|
|
286
|
-
const candidatePrefix =
|
|
283
|
+
const candidatePrefix = getCandidate(prefix, 'section');
|
|
287
284
|
if (candidatePrefix) {
|
|
288
|
-
candidate = `${candidatePrefix}-${namedGroupStr
|
|
285
|
+
candidate = `${candidatePrefix}-${namedGroupStr ?? ''}`;
|
|
289
286
|
}
|
|
290
287
|
}
|
|
291
288
|
else if (!hasPartOfAddress) {
|
|
292
|
-
expects.unshift(...partOfAddress
|
|
293
|
-
.slice()
|
|
294
|
-
.reverse()
|
|
295
|
-
.map(token => ({
|
|
289
|
+
expects.unshift(...[...partOfAddress].reverse().map(token => ({
|
|
296
290
|
type: 'const',
|
|
297
291
|
value: token,
|
|
298
292
|
})));
|
|
299
|
-
candidate =
|
|
293
|
+
candidate = getCandidate(head.value, partOfAddress, autofillFieldNames, contactingTokens, contactableFieldNames);
|
|
300
294
|
}
|
|
301
295
|
else if (!hasContactingToken) {
|
|
302
296
|
expects.push(...contactingTokens.map(token => ({
|
|
303
297
|
type: 'const',
|
|
304
298
|
value: token,
|
|
305
299
|
})));
|
|
306
|
-
candidate =
|
|
300
|
+
candidate = getCandidate(head.value, autofillFieldNames, contactingTokens, contactableFieldNames);
|
|
307
301
|
}
|
|
308
|
-
candidate = candidate
|
|
302
|
+
candidate = candidate ?? getCandidate(head.value, autofillFieldNames);
|
|
309
303
|
if (candidate) {
|
|
310
304
|
acLog('[Unmatched ("%s")] Unexpected token: "%s", Do you mean "%s"? ', value, head.value, candidate);
|
|
311
305
|
}
|
|
@@ -319,4 +313,3 @@ const checkAutoComplete = () => value => {
|
|
|
319
313
|
ref: URL_AUTOFILL_FIELD,
|
|
320
314
|
});
|
|
321
315
|
};
|
|
322
|
-
exports.checkAutoComplete = checkAutoComplete;
|
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../../debug");
|
|
5
|
-
const token_1 = require("../../token");
|
|
6
|
-
const datetime_tokens_1 = require("./datetime-tokens");
|
|
1
|
+
import { log } from '../../debug.js';
|
|
2
|
+
import { TokenCollection } from '../../token/index.js';
|
|
3
|
+
import { datetimeTokenCheck } from './datetime-tokens.js';
|
|
7
4
|
/**
|
|
8
5
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates
|
|
9
6
|
*/
|
|
10
|
-
const checkDateString = () => function checkDateString(value) {
|
|
11
|
-
|
|
12
|
-
const tokens =
|
|
7
|
+
export const checkDateString = () => function checkDateString(value) {
|
|
8
|
+
log('CHECK: date-string');
|
|
9
|
+
const tokens = TokenCollection.fromPatterns(value, [
|
|
13
10
|
// YYYY
|
|
14
11
|
/[^-]*/,
|
|
15
12
|
// -
|
|
16
|
-
|
|
13
|
+
/\D?/,
|
|
17
14
|
// MM
|
|
18
15
|
/[^-]*/,
|
|
19
16
|
// -
|
|
20
|
-
|
|
17
|
+
/\D/,
|
|
21
18
|
// DD
|
|
22
|
-
|
|
19
|
+
/.\d*/,
|
|
23
20
|
]);
|
|
24
|
-
|
|
25
|
-
const res = tokens.eachCheck(
|
|
21
|
+
log('Date: "%s" => %O', tokens.value, tokens);
|
|
22
|
+
const res = tokens.eachCheck(datetimeTokenCheck.year, datetimeTokenCheck.hyphen, datetimeTokenCheck.month, datetimeTokenCheck.hyphen, datetimeTokenCheck.date, datetimeTokenCheck.extra);
|
|
26
23
|
if (!res.matched) {
|
|
27
|
-
|
|
24
|
+
log('Failed: %O', res);
|
|
28
25
|
}
|
|
29
26
|
return res;
|
|
30
27
|
};
|
|
31
|
-
exports.checkDateString = checkDateString;
|
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
import type { TokenEachCheck } from '../../token/token-collection';
|
|
2
|
-
export declare const datetimeTokenCheck: Record<
|
|
3
|
-
| 'year'
|
|
4
|
-
| 'month'
|
|
5
|
-
| 'date'
|
|
6
|
-
| 'hour'
|
|
7
|
-
| 'minute'
|
|
8
|
-
| 'second'
|
|
9
|
-
| 'secondFractionalPart'
|
|
10
|
-
| 'week'
|
|
11
|
-
| 'hyphen'
|
|
12
|
-
| 'colon'
|
|
13
|
-
| 'extra'
|
|
14
|
-
| 'colonOrEnd'
|
|
15
|
-
| 'decimalPointOrEnd'
|
|
16
|
-
| 'localDateTimeSeparator'
|
|
17
|
-
| 'normalizedlocalDateTimeSeparator'
|
|
18
|
-
| 'plusOrMinusSign'
|
|
19
|
-
| 'weekSign',
|
|
20
|
-
TokenEachCheck
|
|
21
|
-
> &
|
|
22
|
-
Record<'_year' | '_month', number | null>;
|
|
1
|
+
import type { TokenEachCheck } from '../../token/token-collection.js';
|
|
2
|
+
export declare const datetimeTokenCheck: Record<'year' | 'month' | 'date' | 'hour' | 'minute' | 'second' | 'secondFractionalPart' | 'week' | 'hyphen' | 'colon' | 'extra' | 'colonOrEnd' | 'decimalPointOrEnd' | 'localDateTimeSeparator' | 'normalizedlocalDateTimeSeparator' | 'plusOrMinusSign' | 'weekSign', TokenEachCheck> & Record<'_year' | '_month', number | null>;
|
|
23
3
|
export declare function getMaxWeekNum(year: number): number;
|