@markuplint/types 3.9.0 → 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/check-multi-types.d.ts +2 -2
- 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 +18 -23
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +1 -1
- package/lib/defs.js +82 -85
- package/lib/enum.d.ts +2 -2
- package/lib/enum.js +6 -11
- 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 -22
- package/lib/list.d.ts +2 -2
- package/lib/list.js +9 -14
- package/lib/match-result.d.ts +1 -1
- package/lib/match-result.js +6 -13
- package/lib/number.d.ts +2 -2
- 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.js +9 -13
- 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 +4 -5
- package/lib/token/token-collection.js +35 -43
- package/lib/token/token.d.ts +2 -2
- package/lib/token/token.js +6 -13
- package/lib/token/types.js +1 -2
- package/lib/types.d.ts +2 -2
- package/lib/types.js +1 -2
- 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 +16 -20
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +24 -28
- 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 +40 -46
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +38 -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 +20 -25
- 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 -22
- 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 +11 -17
- 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 +1 -1
- package/lib/whatwg/is-browser-context-name.js +1 -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 +1 -5
- package/package.json +13 -8
- 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/defs.js
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const is_custom_element_name_1 = require("./whatwg/is-custom-element-name");
|
|
17
|
-
const is_itemprop_name_1 = require("./whatwg/is-itemprop-name");
|
|
18
|
-
exports.types = {
|
|
1
|
+
import { checkMultiTypes } from './check-multi-types.js';
|
|
2
|
+
import { getCandidate } from './get-candidate.js';
|
|
3
|
+
import { matched, matches, unmatched } from './match-result.js';
|
|
4
|
+
import { splitUnit, isFloat, isUint, isInt } from './primitive/index.js';
|
|
5
|
+
import { isBCP47 } from './rfc/is-bcp-47.js';
|
|
6
|
+
import { Token, TokenCollection } from './token/index.js';
|
|
7
|
+
import { checkSerializedPermissionsPolicy } from './w3c/check-serialized-permissions-policy.js';
|
|
8
|
+
import { checkAutoComplete } from './whatwg/check-autocomplete.js';
|
|
9
|
+
import { checkDateTime } from './whatwg/check-datetime/index.js';
|
|
10
|
+
import { checkMIMEType } from './whatwg/check-mime-type.js';
|
|
11
|
+
import { isAbsURL } from './whatwg/is-abs-url.js';
|
|
12
|
+
import { isBrowserContextName } from './whatwg/is-browser-context-name.js';
|
|
13
|
+
import { isCustomElementName } from './whatwg/is-custom-element-name.js';
|
|
14
|
+
import { isItempropName } from './whatwg/is-itemprop-name.js';
|
|
15
|
+
export const types = {
|
|
19
16
|
Any: {
|
|
20
17
|
ref: '',
|
|
21
|
-
is: () =>
|
|
18
|
+
is: () => matched(),
|
|
22
19
|
},
|
|
23
20
|
NoEmptyAny: {
|
|
24
21
|
ref: '',
|
|
25
|
-
is: value => (0 < value.length ?
|
|
22
|
+
is: value => (0 < value.length ? matched() : unmatched(value, 'empty-token')),
|
|
26
23
|
},
|
|
27
24
|
OneLineAny: {
|
|
28
25
|
ref: '',
|
|
29
26
|
is: value => {
|
|
30
|
-
const tokens = new
|
|
27
|
+
const tokens = new TokenCollection(value);
|
|
31
28
|
/**
|
|
32
29
|
* @see https://infra.spec.whatwg.org/#ascii-tab-or-newline
|
|
33
30
|
*/
|
|
@@ -38,7 +35,7 @@ exports.types = {
|
|
|
38
35
|
reason: 'unexpected-newline',
|
|
39
36
|
});
|
|
40
37
|
}
|
|
41
|
-
return
|
|
38
|
+
return matched();
|
|
42
39
|
},
|
|
43
40
|
},
|
|
44
41
|
Zero: {
|
|
@@ -49,7 +46,7 @@ exports.types = {
|
|
|
49
46
|
value: 'zero',
|
|
50
47
|
},
|
|
51
48
|
],
|
|
52
|
-
is: value => (value === '0' ?
|
|
49
|
+
is: value => (value === '0' ? matched() : unmatched(value, 'syntax-error')),
|
|
53
50
|
},
|
|
54
51
|
Number: {
|
|
55
52
|
ref: '',
|
|
@@ -59,7 +56,7 @@ exports.types = {
|
|
|
59
56
|
value: 'number',
|
|
60
57
|
},
|
|
61
58
|
],
|
|
62
|
-
is: value => (
|
|
59
|
+
is: value => (isFloat(value) ? matched() : unmatched(value, 'unexpected-token')),
|
|
63
60
|
},
|
|
64
61
|
Int: {
|
|
65
62
|
ref: '',
|
|
@@ -69,7 +66,7 @@ exports.types = {
|
|
|
69
66
|
value: 'integer',
|
|
70
67
|
},
|
|
71
68
|
],
|
|
72
|
-
is: value => (
|
|
69
|
+
is: value => (isInt(value) ? matched() : unmatched(value, 'unexpected-token')),
|
|
73
70
|
},
|
|
74
71
|
Uint: {
|
|
75
72
|
ref: '',
|
|
@@ -79,7 +76,7 @@ exports.types = {
|
|
|
79
76
|
value: 'non-negative integer',
|
|
80
77
|
},
|
|
81
78
|
],
|
|
82
|
-
is: value => (
|
|
79
|
+
is: value => (isUint(value) ? matched() : unmatched(value, 'unexpected-token')),
|
|
83
80
|
},
|
|
84
81
|
XMLName: {
|
|
85
82
|
ref: 'https://www.w3.org/TR/xml/#NT-Name',
|
|
@@ -96,7 +93,7 @@ exports.types = {
|
|
|
96
93
|
const nameCharTail = /-|[.0-9\u00B7]|[\u0300-\u036F\u203F-\u2040]/;
|
|
97
94
|
// Name ::= NameStartChar (NameChar)*
|
|
98
95
|
const name = RegExp(`(?:${nameStartChar.source})(?:${nameCharTail})*`, 'u');
|
|
99
|
-
return name.test(value) ?
|
|
96
|
+
return name.test(value) ? matched() : unmatched(value, 'unexpected-token');
|
|
100
97
|
},
|
|
101
98
|
},
|
|
102
99
|
DOMID: {
|
|
@@ -108,17 +105,17 @@ exports.types = {
|
|
|
108
105
|
},
|
|
109
106
|
],
|
|
110
107
|
is: value => {
|
|
111
|
-
const tokens = new
|
|
112
|
-
const ws = tokens.search(
|
|
108
|
+
const tokens = new TokenCollection(value);
|
|
109
|
+
const ws = tokens.search(Token.WhiteSpace);
|
|
113
110
|
if (ws) {
|
|
114
111
|
return ws.unmatched({
|
|
115
112
|
reason: 'unexpected-space',
|
|
116
113
|
});
|
|
117
114
|
}
|
|
118
115
|
if (tokens.length === 0) {
|
|
119
|
-
return
|
|
116
|
+
return unmatched(value, 'empty-token');
|
|
120
117
|
}
|
|
121
|
-
return
|
|
118
|
+
return matched();
|
|
122
119
|
},
|
|
123
120
|
},
|
|
124
121
|
FunctionBody: {
|
|
@@ -130,7 +127,7 @@ exports.types = {
|
|
|
130
127
|
},
|
|
131
128
|
],
|
|
132
129
|
// **NO IMPLEMENT PLAN NOW**
|
|
133
|
-
is: () =>
|
|
130
|
+
is: () => matched(),
|
|
134
131
|
},
|
|
135
132
|
Pattern: {
|
|
136
133
|
ref: 'https://html.spec.whatwg.org/multipage/input.html#compiled-pattern-regular-expression',
|
|
@@ -145,9 +142,9 @@ exports.types = {
|
|
|
145
142
|
new RegExp(`^(?:${value})$`);
|
|
146
143
|
}
|
|
147
144
|
catch {
|
|
148
|
-
return
|
|
145
|
+
return unmatched(value);
|
|
149
146
|
}
|
|
150
|
-
return
|
|
147
|
+
return matched();
|
|
151
148
|
},
|
|
152
149
|
},
|
|
153
150
|
DateTime: {
|
|
@@ -158,7 +155,7 @@ exports.types = {
|
|
|
158
155
|
value: 'date time',
|
|
159
156
|
},
|
|
160
157
|
],
|
|
161
|
-
is:
|
|
158
|
+
is: checkDateTime(),
|
|
162
159
|
},
|
|
163
160
|
/**
|
|
164
161
|
* It doesn't check the meaningless number less than -1
|
|
@@ -181,7 +178,7 @@ exports.types = {
|
|
|
181
178
|
},
|
|
182
179
|
],
|
|
183
180
|
ref: 'https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex',
|
|
184
|
-
is:
|
|
181
|
+
is: matches(value => isInt(value)),
|
|
185
182
|
},
|
|
186
183
|
BCP47: {
|
|
187
184
|
expects: [
|
|
@@ -191,7 +188,7 @@ exports.types = {
|
|
|
191
188
|
},
|
|
192
189
|
],
|
|
193
190
|
ref: 'https://tools.ietf.org/rfc/bcp/bcp47.html',
|
|
194
|
-
is:
|
|
191
|
+
is: matches(isBCP47(), { reason: 'unexpected-token' }),
|
|
195
192
|
},
|
|
196
193
|
/**
|
|
197
194
|
* **NO IMPLEMENT NEVER**
|
|
@@ -208,11 +205,11 @@ exports.types = {
|
|
|
208
205
|
*/
|
|
209
206
|
URL: {
|
|
210
207
|
ref: 'https://html.spec.whatwg.org/multipage/urls-and-fetching.html#valid-url-potentially-surrounded-by-spaces',
|
|
211
|
-
is: () =>
|
|
208
|
+
is: () => matched(),
|
|
212
209
|
},
|
|
213
210
|
AbsoluteURL: {
|
|
214
211
|
ref: 'https://url.spec.whatwg.org/#syntax-url-absolute',
|
|
215
|
-
is:
|
|
212
|
+
is: matches(isAbsURL()),
|
|
216
213
|
},
|
|
217
214
|
HashName: {
|
|
218
215
|
ref: 'https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-hash-name-reference',
|
|
@@ -222,7 +219,7 @@ exports.types = {
|
|
|
222
219
|
value: 'hash name',
|
|
223
220
|
},
|
|
224
221
|
],
|
|
225
|
-
is: value => (value[0] === '#' ?
|
|
222
|
+
is: value => (value[0] === '#' ? matched() : unmatched(value, 'unexpected-token')),
|
|
226
223
|
},
|
|
227
224
|
OneCodePointChar: {
|
|
228
225
|
ref: 'https://html.spec.whatwg.org/multipage/interaction.html#the-accesskey-attribute',
|
|
@@ -232,7 +229,7 @@ exports.types = {
|
|
|
232
229
|
value: 'one code point character',
|
|
233
230
|
},
|
|
234
231
|
],
|
|
235
|
-
is: value => (value.length === 1 ?
|
|
232
|
+
is: value => (value.length === 1 ? matched() : unmatched(value, 'unexpected-token')),
|
|
236
233
|
},
|
|
237
234
|
CustomElementName: {
|
|
238
235
|
ref: 'https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name',
|
|
@@ -242,7 +239,7 @@ exports.types = {
|
|
|
242
239
|
value: 'custom element name',
|
|
243
240
|
},
|
|
244
241
|
],
|
|
245
|
-
is:
|
|
242
|
+
is: matches(isCustomElementName()),
|
|
246
243
|
},
|
|
247
244
|
BrowsingContextName: {
|
|
248
245
|
ref: 'https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-names',
|
|
@@ -253,7 +250,7 @@ exports.types = {
|
|
|
253
250
|
},
|
|
254
251
|
],
|
|
255
252
|
// <iframe name="[HERE]">
|
|
256
|
-
is:
|
|
253
|
+
is: matches(isBrowserContextName()),
|
|
257
254
|
},
|
|
258
255
|
BrowsingContextNameOrKeyword: {
|
|
259
256
|
ref: 'https://html.spec.whatwg.org/multipage/browsers.html#valid-browsing-context-name-or-keyword',
|
|
@@ -272,13 +269,13 @@ exports.types = {
|
|
|
272
269
|
value = value.toLowerCase();
|
|
273
270
|
const keywords = ['_blank', '_self', '_parent', '_top'];
|
|
274
271
|
if (keywords.includes(value)) {
|
|
275
|
-
return
|
|
272
|
+
return matched();
|
|
276
273
|
}
|
|
277
274
|
if (value[0] === '_') {
|
|
278
|
-
const candidate =
|
|
279
|
-
return
|
|
275
|
+
const candidate = getCandidate(value, keywords);
|
|
276
|
+
return unmatched(value, 'unexpected-token', { candidate });
|
|
280
277
|
}
|
|
281
|
-
return
|
|
278
|
+
return matches(isBrowserContextName())(value);
|
|
282
279
|
},
|
|
283
280
|
},
|
|
284
281
|
HTTPSchemaURL: {
|
|
@@ -290,13 +287,13 @@ exports.types = {
|
|
|
290
287
|
},
|
|
291
288
|
],
|
|
292
289
|
is(value) {
|
|
293
|
-
if (
|
|
294
|
-
return
|
|
290
|
+
if (isAbsURL()(value)) {
|
|
291
|
+
return unmatched(value, 'unexpected-token');
|
|
295
292
|
}
|
|
296
293
|
if (/^https?/i.test(value)) {
|
|
297
|
-
return
|
|
294
|
+
return matched();
|
|
298
295
|
}
|
|
299
|
-
return
|
|
296
|
+
return unmatched(value, 'unexpected-token', {
|
|
300
297
|
expects: [
|
|
301
298
|
{
|
|
302
299
|
type: 'format',
|
|
@@ -314,7 +311,7 @@ exports.types = {
|
|
|
314
311
|
value: 'MIME Type',
|
|
315
312
|
},
|
|
316
313
|
],
|
|
317
|
-
is:
|
|
314
|
+
is: checkMIMEType(),
|
|
318
315
|
},
|
|
319
316
|
ItemProp: {
|
|
320
317
|
ref: 'https://html.spec.whatwg.org/multipage/microdata.html#names:-the-itemprop-attribute',
|
|
@@ -329,11 +326,11 @@ exports.types = {
|
|
|
329
326
|
},
|
|
330
327
|
],
|
|
331
328
|
is(value) {
|
|
332
|
-
const _matched =
|
|
333
|
-
const _unmatched =
|
|
334
|
-
return
|
|
335
|
-
value => (
|
|
336
|
-
value => (
|
|
329
|
+
const _matched = matched();
|
|
330
|
+
const _unmatched = unmatched(value, 'unexpected-token');
|
|
331
|
+
return checkMultiTypes(value, [
|
|
332
|
+
value => (isAbsURL()(value) ? _matched : _unmatched),
|
|
333
|
+
value => (isItempropName()(value) ? _matched : _unmatched),
|
|
337
334
|
]);
|
|
338
335
|
},
|
|
339
336
|
},
|
|
@@ -361,11 +358,11 @@ exports.types = {
|
|
|
361
358
|
if (!token) {
|
|
362
359
|
return 0;
|
|
363
360
|
}
|
|
364
|
-
const { num, unit } =
|
|
361
|
+
const { num, unit } = splitUnit(token.value);
|
|
365
362
|
if (unit !== 'w') {
|
|
366
363
|
return 0;
|
|
367
364
|
}
|
|
368
|
-
if (!
|
|
365
|
+
if (!isUint(num)) {
|
|
369
366
|
return 0;
|
|
370
367
|
}
|
|
371
368
|
return 1;
|
|
@@ -374,11 +371,11 @@ exports.types = {
|
|
|
374
371
|
if (!token) {
|
|
375
372
|
return 0;
|
|
376
373
|
}
|
|
377
|
-
const { num, unit } =
|
|
374
|
+
const { num, unit } = splitUnit(token.value);
|
|
378
375
|
if (unit !== 'x') {
|
|
379
376
|
return 0;
|
|
380
377
|
}
|
|
381
|
-
if (!
|
|
378
|
+
if (!isFloat(num)) {
|
|
382
379
|
return 0;
|
|
383
380
|
}
|
|
384
381
|
return 1;
|
|
@@ -426,12 +423,12 @@ exports.types = {
|
|
|
426
423
|
is(value) {
|
|
427
424
|
value = value.toLowerCase();
|
|
428
425
|
if (value === 'any') {
|
|
429
|
-
return
|
|
426
|
+
return matched();
|
|
430
427
|
}
|
|
431
|
-
const tokens = new
|
|
428
|
+
const tokens = new TokenCollection(value, { specificSeparator: 'x' });
|
|
432
429
|
const [width, sep, height, ...tail] = tokens;
|
|
433
430
|
if (!width) {
|
|
434
|
-
return
|
|
431
|
+
return unmatched(value, 'unexpected-token');
|
|
435
432
|
}
|
|
436
433
|
if (!sep) {
|
|
437
434
|
return width.unmatched({ reason: 'unexpected-token' });
|
|
@@ -442,7 +439,7 @@ exports.types = {
|
|
|
442
439
|
if (tail[0]) {
|
|
443
440
|
return tail[0].unmatched({ reason: 'extra-token' });
|
|
444
441
|
}
|
|
445
|
-
if (!
|
|
442
|
+
if (!isUint(width.value)) {
|
|
446
443
|
return width.unmatched({ reason: 'unexpected-token' });
|
|
447
444
|
}
|
|
448
445
|
if (width.value === '0') {
|
|
@@ -451,18 +448,18 @@ exports.types = {
|
|
|
451
448
|
if (sep.value !== 'x') {
|
|
452
449
|
return sep.unmatched({ reason: 'out-of-range' });
|
|
453
450
|
}
|
|
454
|
-
if (!
|
|
451
|
+
if (!isUint(height.value)) {
|
|
455
452
|
return height.unmatched({ reason: 'unexpected-token' });
|
|
456
453
|
}
|
|
457
454
|
if (height.value === '0') {
|
|
458
455
|
return height.unmatched({ reason: 'out-of-range' });
|
|
459
456
|
}
|
|
460
|
-
return
|
|
457
|
+
return matched();
|
|
461
458
|
},
|
|
462
459
|
},
|
|
463
460
|
AutoComplete: {
|
|
464
461
|
ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete',
|
|
465
|
-
is:
|
|
462
|
+
is: checkAutoComplete(),
|
|
466
463
|
},
|
|
467
464
|
Accept: {
|
|
468
465
|
ref: 'https://html.spec.whatwg.org/multipage/input.html#attr-input-accept',
|
|
@@ -492,18 +489,18 @@ exports.types = {
|
|
|
492
489
|
is(value) {
|
|
493
490
|
const extMap = ['audio/*', 'video/*', 'image/*'];
|
|
494
491
|
if (extMap.includes(value))
|
|
495
|
-
return
|
|
492
|
+
return matched();
|
|
496
493
|
// A valid MIME type string with no parameters
|
|
497
|
-
const mimeMatched =
|
|
494
|
+
const mimeMatched = checkMIMEType({ withoutParameters: true })(value);
|
|
498
495
|
if (mimeMatched.matched)
|
|
499
|
-
return
|
|
496
|
+
return matched();
|
|
500
497
|
// A string whose first character is a U+002E FULL STOP character (.)
|
|
501
|
-
return value[0] === '.' && value[1] ?
|
|
498
|
+
return value[0] === '.' && value[1] ? matched() : mimeMatched;
|
|
502
499
|
},
|
|
503
500
|
},
|
|
504
501
|
SerializedPermissionsPolicy: {
|
|
505
502
|
ref: 'https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy',
|
|
506
|
-
is:
|
|
503
|
+
is: checkSerializedPermissionsPolicy(),
|
|
507
504
|
},
|
|
508
505
|
'<css-declaration-list>': {
|
|
509
506
|
ref: 'https://drafts.csswg.org/css-style-attr/#syntax',
|
|
@@ -527,52 +524,52 @@ exports.types = {
|
|
|
527
524
|
'<svg-font-size>': {
|
|
528
525
|
ref: 'https://drafts.csswg.org/css-fonts-5/#descdef-font-face-font-size',
|
|
529
526
|
// TODO:
|
|
530
|
-
is: () =>
|
|
527
|
+
is: () => matched(),
|
|
531
528
|
},
|
|
532
529
|
'<svg-font-size-adjust>': {
|
|
533
530
|
ref: 'https://drafts.csswg.org/css-fonts-5/#propdef-font-size-adjust',
|
|
534
531
|
// TODO:
|
|
535
|
-
is: () =>
|
|
532
|
+
is: () => matched(),
|
|
536
533
|
},
|
|
537
534
|
"<'color-profile'>": {
|
|
538
535
|
ref: 'https://www.w3.org/TR/SVG11/color.html#ColorProfileProperty',
|
|
539
536
|
// TODO:
|
|
540
|
-
is: () =>
|
|
537
|
+
is: () => matched(),
|
|
541
538
|
},
|
|
542
539
|
"<'color-rendering'>": {
|
|
543
540
|
ref: 'https://www.w3.org/TR/SVG11/painting.html#ColorRenderingProperty',
|
|
544
541
|
// TODO:
|
|
545
|
-
is: () =>
|
|
542
|
+
is: () => matched(),
|
|
546
543
|
},
|
|
547
544
|
"<'enable-background'>": {
|
|
548
545
|
ref: 'https://www.w3.org/TR/SVG11/filters.html#EnableBackgroundProperty',
|
|
549
546
|
// TODO:
|
|
550
|
-
is: () =>
|
|
547
|
+
is: () => matched(),
|
|
551
548
|
},
|
|
552
549
|
'<list-of-svg-feature-string>': {
|
|
553
550
|
ref: 'https://www.w3.org/TR/SVG11/feature.html',
|
|
554
551
|
// TODO:
|
|
555
|
-
is: () =>
|
|
552
|
+
is: () => matched(),
|
|
556
553
|
},
|
|
557
554
|
'<animatable-value>': {
|
|
558
555
|
ref: 'https://svgwg.org/specs/animations/#FromAttribute',
|
|
559
556
|
// TODO:
|
|
560
|
-
is: () =>
|
|
557
|
+
is: () => matched(),
|
|
561
558
|
},
|
|
562
559
|
'<begin-value-list>': {
|
|
563
560
|
ref: 'https://svgwg.org/specs/animations/#BeginValueListSyntax',
|
|
564
561
|
// TODO:
|
|
565
|
-
is: () =>
|
|
562
|
+
is: () => matched(),
|
|
566
563
|
},
|
|
567
564
|
'<end-value-list>': {
|
|
568
565
|
ref: 'https://svgwg.org/specs/animations/#EndValueListSyntax',
|
|
569
566
|
// TODO:
|
|
570
|
-
is: () =>
|
|
567
|
+
is: () => matched(),
|
|
571
568
|
},
|
|
572
569
|
'<list-of-value>': {
|
|
573
570
|
ref: 'https://svgwg.org/specs/animations/#ValuesAttribute',
|
|
574
571
|
// TODO:
|
|
575
|
-
is: () =>
|
|
572
|
+
is: () => matched(),
|
|
576
573
|
},
|
|
577
574
|
'<clock-value>': {
|
|
578
575
|
ref: 'https://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-ClockValueSyntax',
|
|
@@ -749,13 +746,13 @@ exports.types = {
|
|
|
749
746
|
},
|
|
750
747
|
},
|
|
751
748
|
};
|
|
752
|
-
|
|
749
|
+
export const tokenizers = {
|
|
753
750
|
// RFC
|
|
754
751
|
// https://tools.ietf.org/rfc/bcp/bcp47.html
|
|
755
752
|
'bcp-47'(token) {
|
|
756
753
|
if (!token) {
|
|
757
754
|
return 0;
|
|
758
755
|
}
|
|
759
|
-
return
|
|
756
|
+
return isBCP47()(token.value) ? 1 : 0;
|
|
760
757
|
},
|
|
761
758
|
};
|
package/lib/enum.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Result } from './types';
|
|
2
|
-
import type { Enum } from './types.schema';
|
|
1
|
+
import type { Result } from './types.js';
|
|
2
|
+
import type { Enum } from './types.schema.js';
|
|
3
3
|
import type { ReadonlyDeep } from 'type-fest';
|
|
4
4
|
export declare function checkEnum(value: string, type: ReadonlyDeep<Enum>, ref?: string): Result;
|
package/lib/enum.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
function checkEnum(value, type, ref) {
|
|
6
|
-
var _a, _b;
|
|
7
|
-
const disallowToSurroundBySpaces = (_a = type.disallowToSurroundBySpaces) !== null && _a !== void 0 ? _a : true;
|
|
8
|
-
const caseInsensitive = (_b = type.caseInsensitive) !== null && _b !== void 0 ? _b : true;
|
|
1
|
+
import { matched, unmatched } from './match-result.js';
|
|
2
|
+
export function checkEnum(value, type, ref) {
|
|
3
|
+
const disallowToSurroundBySpaces = type.disallowToSurroundBySpaces ?? true;
|
|
4
|
+
const caseInsensitive = type.caseInsensitive ?? true;
|
|
9
5
|
if (!disallowToSurroundBySpaces) {
|
|
10
6
|
value = value.trim();
|
|
11
7
|
}
|
|
@@ -16,11 +12,10 @@ function checkEnum(value, type, ref) {
|
|
|
16
12
|
}
|
|
17
13
|
const res = values.includes(value);
|
|
18
14
|
if (res) {
|
|
19
|
-
return
|
|
15
|
+
return matched();
|
|
20
16
|
}
|
|
21
|
-
return
|
|
17
|
+
return unmatched(value, 'doesnt-exist-in-enum', {
|
|
22
18
|
ref,
|
|
23
19
|
expects: type.enum.map(value => ({ type: 'const', value })),
|
|
24
20
|
});
|
|
25
21
|
}
|
|
26
|
-
exports.checkEnum = checkEnum;
|
package/lib/get-candidate.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getCandidate = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const leven_1 = tslib_1.__importDefault(require("leven"));
|
|
6
|
-
function getCandidate(value, ...candidates) {
|
|
1
|
+
import leven from 'leven';
|
|
2
|
+
export function getCandidate(value, ...candidates) {
|
|
7
3
|
if (!value) {
|
|
8
4
|
return;
|
|
9
5
|
}
|
|
@@ -11,7 +7,7 @@ function getCandidate(value, ...candidates) {
|
|
|
11
7
|
let candidate;
|
|
12
8
|
let maxRatio = 0;
|
|
13
9
|
list.forEach(word => {
|
|
14
|
-
const dist = (
|
|
10
|
+
const dist = leven(value.trim().toLowerCase(), word.trim().toLowerCase());
|
|
15
11
|
const ratio = 1 - dist / word.length;
|
|
16
12
|
if (0.5 <= ratio && maxRatio < ratio) {
|
|
17
13
|
candidate = word;
|
|
@@ -23,4 +19,3 @@ function getCandidate(value, ...candidates) {
|
|
|
23
19
|
}
|
|
24
20
|
return candidate;
|
|
25
21
|
}
|
|
26
|
-
exports.getCandidate = getCandidate;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './whatwg/is-custom-element-name';
|
|
2
|
-
export * from './check';
|
|
3
|
-
export * from './types';
|
|
1
|
+
export * from './whatwg/is-custom-element-name.js';
|
|
2
|
+
export * from './check.js';
|
|
3
|
+
export * from './types.js';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./whatwg/is-custom-element-name"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./check"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
1
|
+
export * from './whatwg/is-custom-element-name.js';
|
|
2
|
+
export * from './check.js';
|
|
3
|
+
export * from './types.js';
|
package/lib/keyword-type.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Result } from './types';
|
|
2
|
-
import type { KeywordDefinedType } from './types.schema';
|
|
1
|
+
import type { Result } from './types.js';
|
|
2
|
+
import type { KeywordDefinedType } from './types.schema.js';
|
|
3
3
|
export declare function checkKeywordType(value: string, type: KeywordDefinedType, cache?: boolean): Result;
|
package/lib/keyword-type.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const debug_1 = require("./debug");
|
|
7
|
-
const defs_1 = require("./defs");
|
|
8
|
-
const match_result_1 = require("./match-result");
|
|
1
|
+
import { isCSSSyntax } from './check.js';
|
|
2
|
+
import { cssSyntaxMatch } from './css-syntax.js';
|
|
3
|
+
import { log } from './debug.js';
|
|
4
|
+
import { types } from './defs.js';
|
|
5
|
+
import { matched } from './match-result.js';
|
|
9
6
|
const resultCache = new Map();
|
|
10
7
|
const CACHE_KEY_PREFIX = '@markuplint/types/checkKeywordType/cache:::';
|
|
11
|
-
function checkKeywordType(value, type, cache = true) {
|
|
8
|
+
export function checkKeywordType(value, type, cache = true) {
|
|
12
9
|
const key = `${CACHE_KEY_PREFIX}${value}${type}`;
|
|
13
10
|
if (cache) {
|
|
14
11
|
const cachedResult = resultCache.get(key);
|
|
15
12
|
if (cachedResult) {
|
|
16
|
-
|
|
13
|
+
log('Restore cache: %s / %s', value, type);
|
|
17
14
|
return cachedResult;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
17
|
const result = _checkKeywordType(value, type);
|
|
21
18
|
if (cache) {
|
|
22
19
|
resultCache.set(key, result);
|
|
23
|
-
if (
|
|
24
|
-
|
|
20
|
+
if (log.enabled) {
|
|
21
|
+
log('Cache checking: %O', {
|
|
25
22
|
input: value,
|
|
26
23
|
type,
|
|
27
24
|
key,
|
|
@@ -31,29 +28,27 @@ function checkKeywordType(value, type, cache = true) {
|
|
|
31
28
|
}
|
|
32
29
|
return result;
|
|
33
30
|
}
|
|
34
|
-
exports.checkKeywordType = checkKeywordType;
|
|
35
31
|
function _checkKeywordType(value, type) {
|
|
36
|
-
|
|
37
|
-
const def = defs_1.types[type];
|
|
32
|
+
const def = types[type];
|
|
38
33
|
if (!def) {
|
|
39
|
-
|
|
34
|
+
log('The "%s" type is not defined in custom type identifier markuplint specified', type);
|
|
40
35
|
try {
|
|
41
|
-
return
|
|
36
|
+
return cssSyntaxMatch(value, type);
|
|
42
37
|
}
|
|
43
38
|
catch (e) {
|
|
44
39
|
if (e instanceof Error && e.message === 'MARKUPLINT_TYPE_NO_EXIST') {
|
|
45
|
-
|
|
46
|
-
return
|
|
40
|
+
log("Allow all of any value because the type doesn't exist");
|
|
41
|
+
return matched();
|
|
47
42
|
}
|
|
48
43
|
throw e;
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
|
-
const matches =
|
|
46
|
+
const matches = isCSSSyntax(def) ? cssSyntaxMatch(value, def) : def.is(value);
|
|
52
47
|
if (!matches.matched) {
|
|
53
48
|
return {
|
|
54
49
|
...matches,
|
|
55
|
-
ref:
|
|
56
|
-
expects:
|
|
50
|
+
ref: matches.ref ?? def.ref,
|
|
51
|
+
expects: matches.expects ?? def.expects,
|
|
57
52
|
};
|
|
58
53
|
}
|
|
59
54
|
return matches;
|
package/lib/list.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Result } from './types';
|
|
2
|
-
import type { List } from './types.schema';
|
|
1
|
+
import type { Result } from './types.js';
|
|
2
|
+
import type { List } from './types.schema.js';
|
|
3
3
|
import type { ReadonlyDeep } from 'type-fest';
|
|
4
4
|
export declare function checkList(value: string, type: ReadonlyDeep<List>, ref?: string, cache?: boolean): Result;
|