@markuplint/types 3.10.0 → 4.0.0-alpha.2

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.
Files changed (95) hide show
  1. package/lib/check-multi-types.d.ts +2 -2
  2. package/lib/check-multi-types.js +9 -14
  3. package/lib/check.d.ts +1 -1
  4. package/lib/check.js +20 -30
  5. package/lib/css-syntax.d.ts +1 -1
  6. package/lib/css-syntax.js +18 -23
  7. package/lib/debug.js +2 -6
  8. package/lib/defs.d.ts +1 -1
  9. package/lib/defs.js +91 -94
  10. package/lib/enum.d.ts +2 -2
  11. package/lib/enum.js +6 -11
  12. package/lib/get-candidate.js +3 -8
  13. package/lib/index.d.ts +3 -3
  14. package/lib/index.js +3 -6
  15. package/lib/keyword-type.d.ts +2 -2
  16. package/lib/keyword-type.js +17 -22
  17. package/lib/list.d.ts +2 -2
  18. package/lib/list.js +9 -14
  19. package/lib/match-result.d.ts +2 -2
  20. package/lib/match-result.js +6 -13
  21. package/lib/number.d.ts +2 -2
  22. package/lib/number.js +11 -15
  23. package/lib/primitive/index.d.ts +7 -7
  24. package/lib/primitive/index.js +7 -17
  25. package/lib/primitive/is-float.js +1 -5
  26. package/lib/primitive/is-int.js +1 -5
  27. package/lib/primitive/is-non-zero-uint.js +1 -5
  28. package/lib/primitive/is-quantity.js +9 -13
  29. package/lib/primitive/is-uint.js +1 -5
  30. package/lib/primitive/range.js +1 -5
  31. package/lib/primitive/split-unit.js +3 -7
  32. package/lib/rfc/is-bcp-47.d.ts +1 -1
  33. package/lib/rfc/is-bcp-47.js +3 -7
  34. package/lib/token/index.d.ts +2 -2
  35. package/lib/token/index.js +2 -7
  36. package/lib/token/token-collection.d.ts +4 -5
  37. package/lib/token/token-collection.js +35 -43
  38. package/lib/token/token.d.ts +3 -3
  39. package/lib/token/token.js +6 -13
  40. package/lib/token/types.js +1 -2
  41. package/lib/types.d.ts +2 -2
  42. package/lib/types.js +1 -2
  43. package/lib/types.schema.js +1 -2
  44. package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
  45. package/lib/w3c/check-serialized-permissions-policy.js +16 -20
  46. package/lib/whatwg/check-autocomplete.d.ts +1 -1
  47. package/lib/whatwg/check-autocomplete.js +24 -28
  48. package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
  49. package/lib/whatwg/check-datetime/date-string.js +9 -13
  50. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -1
  51. package/lib/whatwg/check-datetime/datetime-tokens.js +40 -46
  52. package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
  53. package/lib/whatwg/check-datetime/duration-string.js +38 -44
  54. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
  55. package/lib/whatwg/check-datetime/global-date-and-time-string.js +17 -21
  56. package/lib/whatwg/check-datetime/index.d.ts +1 -1
  57. package/lib/whatwg/check-datetime/index.js +25 -29
  58. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
  59. package/lib/whatwg/check-datetime/local-date-and-time-string.js +20 -25
  60. package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
  61. package/lib/whatwg/check-datetime/month-string.js +9 -13
  62. package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
  63. package/lib/whatwg/check-datetime/time-string.js +9 -13
  64. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
  65. package/lib/whatwg/check-datetime/time-zone-offset-string.js +16 -22
  66. package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
  67. package/lib/whatwg/check-datetime/week-string.js +9 -13
  68. package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
  69. package/lib/whatwg/check-datetime/year-string.js +9 -13
  70. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
  71. package/lib/whatwg/check-datetime/yearless-date-string.js +9 -13
  72. package/lib/whatwg/check-mime-type.d.ts +1 -1
  73. package/lib/whatwg/check-mime-type.js +11 -17
  74. package/lib/whatwg/is-abs-url.d.ts +1 -1
  75. package/lib/whatwg/is-abs-url.js +1 -5
  76. package/lib/whatwg/is-browser-context-name.d.ts +1 -1
  77. package/lib/whatwg/is-browser-context-name.js +1 -5
  78. package/lib/whatwg/is-custom-element-name.d.ts +1 -1
  79. package/lib/whatwg/is-custom-element-name.js +1 -5
  80. package/lib/whatwg/is-itemprop-name.d.ts +1 -1
  81. package/lib/whatwg/is-itemprop-name.js +1 -5
  82. package/lib/whatwg/is-navigable-target-name.d.ts +1 -1
  83. package/lib/whatwg/is-navigable-target-name.js +1 -5
  84. package/package.json +12 -7
  85. package/test/check.spec.js +0 -89
  86. package/test/css-syntax.spec.js +0 -170
  87. package/test/list.spec.js +0 -133
  88. package/test/primitive/index.spec.js +0 -65
  89. package/test/rfc/is-bcp-47.spec.js +0 -23
  90. package/test/token/token-collection.spec.js +0 -146
  91. package/test/w3c/check-serialized-permissions-policy.spec.js +0 -36
  92. package/test/whatwg/check-autocomplete.spec.js +0 -387
  93. package/test/whatwg/check-datetime/index.spec.js +0 -336
  94. package/test/whatwg/check-mime-type.spec.js +0 -59
  95. package/test/whatwg/is-abs-url.spec.js +0 -8
package/lib/defs.js CHANGED
@@ -1,34 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tokenizers = exports.types = void 0;
4
- const check_multi_types_1 = require("./check-multi-types");
5
- const get_candidate_1 = require("./get-candidate");
6
- const match_result_1 = require("./match-result");
7
- const primitive_1 = require("./primitive");
8
- const is_bcp_47_1 = require("./rfc/is-bcp-47");
9
- const token_1 = require("./token");
10
- const check_serialized_permissions_policy_1 = require("./w3c/check-serialized-permissions-policy");
11
- const check_autocomplete_1 = require("./whatwg/check-autocomplete");
12
- const check_datetime_1 = require("./whatwg/check-datetime");
13
- const check_mime_type_1 = require("./whatwg/check-mime-type");
14
- const is_abs_url_1 = require("./whatwg/is-abs-url");
15
- const is_browser_context_name_1 = require("./whatwg/is-browser-context-name");
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
- const is_navigable_target_name_1 = require("./whatwg/is-navigable-target-name");
19
- 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
+ import { isNavigableTargetName } from './whatwg/is-navigable-target-name.js';
16
+ export const types = {
20
17
  Any: {
21
18
  ref: '',
22
- is: () => (0, match_result_1.matched)(),
19
+ is: () => matched(),
23
20
  },
24
21
  NoEmptyAny: {
25
22
  ref: '',
26
- is: value => (0 < value.length ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'empty-token')),
23
+ is: value => (0 < value.length ? matched() : unmatched(value, 'empty-token')),
27
24
  },
28
25
  OneLineAny: {
29
26
  ref: '',
30
27
  is: value => {
31
- const tokens = new token_1.TokenCollection(value);
28
+ const tokens = new TokenCollection(value);
32
29
  /**
33
30
  * @see https://infra.spec.whatwg.org/#ascii-tab-or-newline
34
31
  */
@@ -39,7 +36,7 @@ exports.types = {
39
36
  reason: 'unexpected-newline',
40
37
  });
41
38
  }
42
- return (0, match_result_1.matched)();
39
+ return matched();
43
40
  },
44
41
  },
45
42
  Zero: {
@@ -50,7 +47,7 @@ exports.types = {
50
47
  value: 'zero',
51
48
  },
52
49
  ],
53
- is: value => (value === '0' ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'syntax-error')),
50
+ is: value => (value === '0' ? matched() : unmatched(value, 'syntax-error')),
54
51
  },
55
52
  Number: {
56
53
  ref: '',
@@ -60,7 +57,7 @@ exports.types = {
60
57
  value: 'number',
61
58
  },
62
59
  ],
63
- is: value => ((0, primitive_1.isFloat)(value) ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
60
+ is: value => (isFloat(value) ? matched() : unmatched(value, 'unexpected-token')),
64
61
  },
65
62
  Int: {
66
63
  ref: '',
@@ -70,7 +67,7 @@ exports.types = {
70
67
  value: 'integer',
71
68
  },
72
69
  ],
73
- is: value => ((0, primitive_1.isInt)(value) ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
70
+ is: value => (isInt(value) ? matched() : unmatched(value, 'unexpected-token')),
74
71
  },
75
72
  Uint: {
76
73
  ref: '',
@@ -80,7 +77,7 @@ exports.types = {
80
77
  value: 'non-negative integer',
81
78
  },
82
79
  ],
83
- is: value => ((0, primitive_1.isUint)(value) ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
80
+ is: value => (isUint(value) ? matched() : unmatched(value, 'unexpected-token')),
84
81
  },
85
82
  XMLName: {
86
83
  ref: 'https://www.w3.org/TR/xml/#NT-Name',
@@ -97,7 +94,7 @@ exports.types = {
97
94
  const nameCharTail = /-|[.0-9\u00B7]|[\u0300-\u036F\u203F-\u2040]/;
98
95
  // Name ::= NameStartChar (NameChar)*
99
96
  const name = RegExp(`(?:${nameStartChar.source})(?:${nameCharTail})*`, 'u');
100
- return name.test(value) ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token');
97
+ return name.test(value) ? matched() : unmatched(value, 'unexpected-token');
101
98
  },
102
99
  },
103
100
  DOMID: {
@@ -109,17 +106,17 @@ exports.types = {
109
106
  },
110
107
  ],
111
108
  is: value => {
112
- const tokens = new token_1.TokenCollection(value);
113
- const ws = tokens.search(token_1.Token.WhiteSpace);
109
+ const tokens = new TokenCollection(value);
110
+ const ws = tokens.search(Token.WhiteSpace);
114
111
  if (ws) {
115
112
  return ws.unmatched({
116
113
  reason: 'unexpected-space',
117
114
  });
118
115
  }
119
116
  if (tokens.length === 0) {
120
- return (0, match_result_1.unmatched)(value, 'empty-token');
117
+ return unmatched(value, 'empty-token');
121
118
  }
122
- return (0, match_result_1.matched)();
119
+ return matched();
123
120
  },
124
121
  },
125
122
  FunctionBody: {
@@ -131,7 +128,7 @@ exports.types = {
131
128
  },
132
129
  ],
133
130
  // **NO IMPLEMENT PLAN NOW**
134
- is: () => (0, match_result_1.matched)(),
131
+ is: () => matched(),
135
132
  },
136
133
  Pattern: {
137
134
  ref: 'https://html.spec.whatwg.org/multipage/input.html#compiled-pattern-regular-expression',
@@ -146,9 +143,9 @@ exports.types = {
146
143
  new RegExp(`^(?:${value})$`);
147
144
  }
148
145
  catch {
149
- return (0, match_result_1.unmatched)(value);
146
+ return unmatched(value);
150
147
  }
151
- return (0, match_result_1.matched)();
148
+ return matched();
152
149
  },
153
150
  },
154
151
  DateTime: {
@@ -159,7 +156,7 @@ exports.types = {
159
156
  value: 'date time',
160
157
  },
161
158
  ],
162
- is: (0, check_datetime_1.checkDateTime)(),
159
+ is: checkDateTime(),
163
160
  },
164
161
  /**
165
162
  * It doesn't check the meaningless number less than -1
@@ -182,7 +179,7 @@ exports.types = {
182
179
  },
183
180
  ],
184
181
  ref: 'https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex',
185
- is: (0, match_result_1.matches)(value => (0, primitive_1.isInt)(value)),
182
+ is: matches(value => isInt(value)),
186
183
  },
187
184
  BCP47: {
188
185
  expects: [
@@ -192,7 +189,7 @@ exports.types = {
192
189
  },
193
190
  ],
194
191
  ref: 'https://tools.ietf.org/rfc/bcp/bcp47.html',
195
- is: (0, match_result_1.matches)((0, is_bcp_47_1.isBCP47)(), { reason: 'unexpected-token' }),
192
+ is: matches(isBCP47(), { reason: 'unexpected-token' }),
196
193
  },
197
194
  /**
198
195
  * **NO IMPLEMENT NEVER**
@@ -209,7 +206,7 @@ exports.types = {
209
206
  */
210
207
  URL: {
211
208
  ref: 'https://html.spec.whatwg.org/multipage/urls-and-fetching.html#valid-url-potentially-surrounded-by-spaces',
212
- is: () => (0, match_result_1.matched)(),
209
+ is: () => matched(),
213
210
  },
214
211
  /**
215
212
  * Fail if it inclides "data" or "javascript" scheme.
@@ -225,14 +222,14 @@ exports.types = {
225
222
  is(value) {
226
223
  value = value.toLowerCase().trim();
227
224
  if (value.startsWith('data:') || value.startsWith('javascript:')) {
228
- return (0, match_result_1.unmatched)(value, 'unexpected-token');
225
+ return unmatched(value, 'unexpected-token');
229
226
  }
230
- return (0, match_result_1.matched)();
227
+ return matched();
231
228
  },
232
229
  },
233
230
  AbsoluteURL: {
234
231
  ref: 'https://url.spec.whatwg.org/#syntax-url-absolute',
235
- is: (0, match_result_1.matches)((0, is_abs_url_1.isAbsURL)()),
232
+ is: matches(isAbsURL()),
236
233
  },
237
234
  HashName: {
238
235
  ref: 'https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-hash-name-reference',
@@ -242,7 +239,7 @@ exports.types = {
242
239
  value: 'hash name',
243
240
  },
244
241
  ],
245
- is: value => (value[0] === '#' ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
242
+ is: value => (value[0] === '#' ? matched() : unmatched(value, 'unexpected-token')),
246
243
  },
247
244
  OneCodePointChar: {
248
245
  ref: 'https://html.spec.whatwg.org/multipage/interaction.html#the-accesskey-attribute',
@@ -252,7 +249,7 @@ exports.types = {
252
249
  value: 'one code point character',
253
250
  },
254
251
  ],
255
- is: value => (value.length === 1 ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
252
+ is: value => (value.length === 1 ? matched() : unmatched(value, 'unexpected-token')),
256
253
  },
257
254
  CustomElementName: {
258
255
  ref: 'https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name',
@@ -262,7 +259,7 @@ exports.types = {
262
259
  value: 'custom element name',
263
260
  },
264
261
  ],
265
- is: (0, match_result_1.matches)((0, is_custom_element_name_1.isCustomElementName)()),
262
+ is: matches(isCustomElementName()),
266
263
  },
267
264
  NavigableTargetName: {
268
265
  ref: 'https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name',
@@ -273,7 +270,7 @@ exports.types = {
273
270
  },
274
271
  ],
275
272
  // <iframe name="[HERE]">
276
- is: (0, match_result_1.matches)((0, is_navigable_target_name_1.isNavigableTargetName)()),
273
+ is: matches(isNavigableTargetName()),
277
274
  },
278
275
  /**
279
276
  * @deprecated Use {@link types.NavigableTargetName} instead.
@@ -286,7 +283,7 @@ exports.types = {
286
283
  value: 'browsing context name',
287
284
  },
288
285
  ],
289
- is: (0, match_result_1.matches)((0, is_browser_context_name_1.isBrowserContextName)()),
286
+ is: matches(isBrowserContextName()),
290
287
  },
291
288
  NavigableTargetNameOrKeyword: {
292
289
  ref: 'https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name-or-keyword',
@@ -305,17 +302,17 @@ exports.types = {
305
302
  value = value.toLowerCase();
306
303
  const keywords = ['_blank', '_self', '_parent', '_top'];
307
304
  if (keywords.includes(value)) {
308
- return (0, match_result_1.matched)();
305
+ return matched();
309
306
  }
310
307
  if (value[0] === '_') {
311
- const candidate = (0, get_candidate_1.getCandidate)(value, keywords);
312
- return (0, match_result_1.unmatched)(value, 'unexpected-token', { candidate });
308
+ const candidate = getCandidate(value, keywords);
309
+ return unmatched(value, 'unexpected-token', { candidate });
313
310
  }
314
- const res = (0, match_result_1.matches)((0, is_navigable_target_name_1.isNavigableTargetName)())(value);
311
+ const res = matches(isNavigableTargetName())(value);
315
312
  if (!res.matched) {
316
313
  // @see https://html.spec.whatwg.org/multipage/semantics.html#get-an-element's-target
317
314
  // > If target is not null, and contains an ASCII tab or newline and a U+003C (<), then set target to "_blank".
318
- return (0, match_result_1.unmatched)(value, 'unexpected-token', { fallbackTo: '_blank' });
315
+ return unmatched(value, 'unexpected-token', { fallbackTo: '_blank' });
319
316
  }
320
317
  return res;
321
318
  },
@@ -339,13 +336,13 @@ exports.types = {
339
336
  value = value.toLowerCase();
340
337
  const keywords = ['_blank', '_self', '_parent', '_top'];
341
338
  if (keywords.includes(value)) {
342
- return (0, match_result_1.matched)();
339
+ return matched();
343
340
  }
344
341
  if (value[0] === '_') {
345
- const candidate = (0, get_candidate_1.getCandidate)(value, keywords);
346
- return (0, match_result_1.unmatched)(value, 'unexpected-token', { candidate });
342
+ const candidate = getCandidate(value, keywords);
343
+ return unmatched(value, 'unexpected-token', { candidate });
347
344
  }
348
- return (0, match_result_1.matches)((0, is_browser_context_name_1.isBrowserContextName)())(value);
345
+ return matches(isBrowserContextName())(value);
349
346
  },
350
347
  },
351
348
  HTTPSchemaURL: {
@@ -357,13 +354,13 @@ exports.types = {
357
354
  },
358
355
  ],
359
356
  is(value) {
360
- if ((0, is_abs_url_1.isAbsURL)()(value)) {
361
- return (0, match_result_1.unmatched)(value, 'unexpected-token');
357
+ if (isAbsURL()(value)) {
358
+ return unmatched(value, 'unexpected-token');
362
359
  }
363
360
  if (/^https?/i.test(value)) {
364
- return (0, match_result_1.matched)();
361
+ return matched();
365
362
  }
366
- return (0, match_result_1.unmatched)(value, 'unexpected-token', {
363
+ return unmatched(value, 'unexpected-token', {
367
364
  expects: [
368
365
  {
369
366
  type: 'format',
@@ -381,7 +378,7 @@ exports.types = {
381
378
  value: 'MIME Type',
382
379
  },
383
380
  ],
384
- is: (0, check_mime_type_1.checkMIMEType)(),
381
+ is: checkMIMEType(),
385
382
  },
386
383
  ItemProp: {
387
384
  ref: 'https://html.spec.whatwg.org/multipage/microdata.html#names:-the-itemprop-attribute',
@@ -396,11 +393,11 @@ exports.types = {
396
393
  },
397
394
  ],
398
395
  is(value) {
399
- const _matched = (0, match_result_1.matched)();
400
- const _unmatched = (0, match_result_1.unmatched)(value, 'unexpected-token');
401
- return (0, check_multi_types_1.checkMultiTypes)(value, [
402
- value => ((0, is_abs_url_1.isAbsURL)()(value) ? _matched : _unmatched),
403
- value => ((0, is_itemprop_name_1.isItempropName)()(value) ? _matched : _unmatched),
396
+ const _matched = matched();
397
+ const _unmatched = unmatched(value, 'unexpected-token');
398
+ return checkMultiTypes(value, [
399
+ value => (isAbsURL()(value) ? _matched : _unmatched),
400
+ value => (isItempropName()(value) ? _matched : _unmatched),
404
401
  ]);
405
402
  },
406
403
  },
@@ -428,11 +425,11 @@ exports.types = {
428
425
  if (!token) {
429
426
  return 0;
430
427
  }
431
- const { num, unit } = (0, primitive_1.splitUnit)(token.value);
428
+ const { num, unit } = splitUnit(token.value);
432
429
  if (unit !== 'w') {
433
430
  return 0;
434
431
  }
435
- if (!(0, primitive_1.isUint)(num)) {
432
+ if (!isUint(num)) {
436
433
  return 0;
437
434
  }
438
435
  return 1;
@@ -441,11 +438,11 @@ exports.types = {
441
438
  if (!token) {
442
439
  return 0;
443
440
  }
444
- const { num, unit } = (0, primitive_1.splitUnit)(token.value);
441
+ const { num, unit } = splitUnit(token.value);
445
442
  if (unit !== 'x') {
446
443
  return 0;
447
444
  }
448
- if (!(0, primitive_1.isFloat)(num)) {
445
+ if (!isFloat(num)) {
449
446
  return 0;
450
447
  }
451
448
  return 1;
@@ -493,12 +490,12 @@ exports.types = {
493
490
  is(value) {
494
491
  value = value.toLowerCase();
495
492
  if (value === 'any') {
496
- return (0, match_result_1.matched)();
493
+ return matched();
497
494
  }
498
- const tokens = new token_1.TokenCollection(value, { specificSeparator: 'x' });
495
+ const tokens = new TokenCollection(value, { specificSeparator: 'x' });
499
496
  const [width, sep, height, ...tail] = tokens;
500
497
  if (!width) {
501
- return (0, match_result_1.unmatched)(value, 'unexpected-token');
498
+ return unmatched(value, 'unexpected-token');
502
499
  }
503
500
  if (!sep) {
504
501
  return width.unmatched({ reason: 'unexpected-token' });
@@ -509,7 +506,7 @@ exports.types = {
509
506
  if (tail[0]) {
510
507
  return tail[0].unmatched({ reason: 'extra-token' });
511
508
  }
512
- if (!(0, primitive_1.isUint)(width.value)) {
509
+ if (!isUint(width.value)) {
513
510
  return width.unmatched({ reason: 'unexpected-token' });
514
511
  }
515
512
  if (width.value === '0') {
@@ -518,18 +515,18 @@ exports.types = {
518
515
  if (sep.value !== 'x') {
519
516
  return sep.unmatched({ reason: 'out-of-range' });
520
517
  }
521
- if (!(0, primitive_1.isUint)(height.value)) {
518
+ if (!isUint(height.value)) {
522
519
  return height.unmatched({ reason: 'unexpected-token' });
523
520
  }
524
521
  if (height.value === '0') {
525
522
  return height.unmatched({ reason: 'out-of-range' });
526
523
  }
527
- return (0, match_result_1.matched)();
524
+ return matched();
528
525
  },
529
526
  },
530
527
  AutoComplete: {
531
528
  ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete',
532
- is: (0, check_autocomplete_1.checkAutoComplete)(),
529
+ is: checkAutoComplete(),
533
530
  },
534
531
  Accept: {
535
532
  ref: 'https://html.spec.whatwg.org/multipage/input.html#attr-input-accept',
@@ -559,18 +556,18 @@ exports.types = {
559
556
  is(value) {
560
557
  const extMap = ['audio/*', 'video/*', 'image/*'];
561
558
  if (extMap.includes(value))
562
- return (0, match_result_1.matched)();
559
+ return matched();
563
560
  // A valid MIME type string with no parameters
564
- const mimeMatched = (0, check_mime_type_1.checkMIMEType)({ withoutParameters: true })(value);
561
+ const mimeMatched = checkMIMEType({ withoutParameters: true })(value);
565
562
  if (mimeMatched.matched)
566
- return (0, match_result_1.matched)();
563
+ return matched();
567
564
  // A string whose first character is a U+002E FULL STOP character (.)
568
- return value[0] === '.' && value[1] ? (0, match_result_1.matched)() : mimeMatched;
565
+ return value[0] === '.' && value[1] ? matched() : mimeMatched;
569
566
  },
570
567
  },
571
568
  SerializedPermissionsPolicy: {
572
569
  ref: 'https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy',
573
- is: (0, check_serialized_permissions_policy_1.checkSerializedPermissionsPolicy)(),
570
+ is: checkSerializedPermissionsPolicy(),
574
571
  },
575
572
  '<css-declaration-list>': {
576
573
  ref: 'https://drafts.csswg.org/css-style-attr/#syntax',
@@ -594,52 +591,52 @@ exports.types = {
594
591
  '<svg-font-size>': {
595
592
  ref: 'https://drafts.csswg.org/css-fonts-5/#descdef-font-face-font-size',
596
593
  // TODO:
597
- is: () => (0, match_result_1.matched)(),
594
+ is: () => matched(),
598
595
  },
599
596
  '<svg-font-size-adjust>': {
600
597
  ref: 'https://drafts.csswg.org/css-fonts-5/#propdef-font-size-adjust',
601
598
  // TODO:
602
- is: () => (0, match_result_1.matched)(),
599
+ is: () => matched(),
603
600
  },
604
601
  "<'color-profile'>": {
605
602
  ref: 'https://www.w3.org/TR/SVG11/color.html#ColorProfileProperty',
606
603
  // TODO:
607
- is: () => (0, match_result_1.matched)(),
604
+ is: () => matched(),
608
605
  },
609
606
  "<'color-rendering'>": {
610
607
  ref: 'https://www.w3.org/TR/SVG11/painting.html#ColorRenderingProperty',
611
608
  // TODO:
612
- is: () => (0, match_result_1.matched)(),
609
+ is: () => matched(),
613
610
  },
614
611
  "<'enable-background'>": {
615
612
  ref: 'https://www.w3.org/TR/SVG11/filters.html#EnableBackgroundProperty',
616
613
  // TODO:
617
- is: () => (0, match_result_1.matched)(),
614
+ is: () => matched(),
618
615
  },
619
616
  '<list-of-svg-feature-string>': {
620
617
  ref: 'https://www.w3.org/TR/SVG11/feature.html',
621
618
  // TODO:
622
- is: () => (0, match_result_1.matched)(),
619
+ is: () => matched(),
623
620
  },
624
621
  '<animatable-value>': {
625
622
  ref: 'https://svgwg.org/specs/animations/#FromAttribute',
626
623
  // TODO:
627
- is: () => (0, match_result_1.matched)(),
624
+ is: () => matched(),
628
625
  },
629
626
  '<begin-value-list>': {
630
627
  ref: 'https://svgwg.org/specs/animations/#BeginValueListSyntax',
631
628
  // TODO:
632
- is: () => (0, match_result_1.matched)(),
629
+ is: () => matched(),
633
630
  },
634
631
  '<end-value-list>': {
635
632
  ref: 'https://svgwg.org/specs/animations/#EndValueListSyntax',
636
633
  // TODO:
637
- is: () => (0, match_result_1.matched)(),
634
+ is: () => matched(),
638
635
  },
639
636
  '<list-of-value>': {
640
637
  ref: 'https://svgwg.org/specs/animations/#ValuesAttribute',
641
638
  // TODO:
642
- is: () => (0, match_result_1.matched)(),
639
+ is: () => matched(),
643
640
  },
644
641
  '<clock-value>': {
645
642
  ref: 'https://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-ClockValueSyntax',
@@ -816,13 +813,13 @@ exports.types = {
816
813
  },
817
814
  },
818
815
  };
819
- exports.tokenizers = {
816
+ export const tokenizers = {
820
817
  // RFC
821
818
  // https://tools.ietf.org/rfc/bcp/bcp47.html
822
819
  'bcp-47'(token) {
823
820
  if (!token) {
824
821
  return 0;
825
822
  }
826
- return (0, is_bcp_47_1.isBCP47)()(token.value) ? 1 : 0;
823
+ return isBCP47()(token.value) ? 1 : 0;
827
824
  },
828
825
  };
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkEnum = void 0;
4
- const match_result_1 = require("./match-result");
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 (0, match_result_1.matched)();
15
+ return matched();
20
16
  }
21
- return (0, match_result_1.unmatched)(value, 'doesnt-exist-in-enum', {
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;
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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 = (0, leven_1.default)(value.trim().toLowerCase(), word.trim().toLowerCase());
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
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';
@@ -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;