@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.
Files changed (93) 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 +82 -85
  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 +1 -1
  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 +2 -2
  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/package.json +13 -8
  83. package/test/check.spec.js +0 -89
  84. package/test/css-syntax.spec.js +0 -170
  85. package/test/list.spec.js +0 -133
  86. package/test/primitive/index.spec.js +0 -65
  87. package/test/rfc/is-bcp-47.spec.js +0 -23
  88. package/test/token/token-collection.spec.js +0 -146
  89. package/test/w3c/check-serialized-permissions-policy.spec.js +0 -36
  90. package/test/whatwg/check-autocomplete.spec.js +0 -387
  91. package/test/whatwg/check-datetime/index.spec.js +0 -336
  92. package/test/whatwg/check-mime-type.spec.js +0 -59
  93. package/test/whatwg/is-abs-url.spec.js +0 -8
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenCollection = void 0;
4
- const match_result_1 = require("../match-result");
5
- const token_1 = require("./token");
6
- class TokenCollection extends Array {
1
+ import { matched, unmatched } from '../match-result.js';
2
+ import { Token } from './token.js';
3
+ export class TokenCollection extends Array {
7
4
  static fromPatterns(value, patterns, typeOptions) {
8
- var _c;
9
5
  const originalValue = typeof value === 'string' ? value : value.originalValue;
10
6
  let strings = typeof value === 'string' ? value : value.value;
11
7
  let cumulativeOffset = typeof value === 'string' ? 0 : value.offset;
12
8
  const tokens = [];
13
9
  function addToken(tokenValue) {
14
- const token = new token_1.Token(tokenValue, cumulativeOffset, originalValue);
10
+ const token = new Token(tokenValue, cumulativeOffset, originalValue);
15
11
  tokens.push(token);
16
12
  strings = strings.slice(tokenValue.length);
17
13
  cumulativeOffset += tokenValue.length;
@@ -32,7 +28,7 @@ class TokenCollection extends Array {
32
28
  value = strings.slice(res.index + res[0].length);
33
29
  }
34
30
  else {
35
- value = (_c = res[0]) !== null && _c !== void 0 ? _c : '';
31
+ value = res[0] ?? '';
36
32
  }
37
33
  }
38
34
  const token = addToken(value);
@@ -42,7 +38,7 @@ class TokenCollection extends Array {
42
38
  if (isBroken) {
43
39
  addToken(strings);
44
40
  }
45
- } while ((typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.repeat) && strings);
41
+ } while (typeOptions?.repeat && strings);
46
42
  if (strings) {
47
43
  addToken(strings);
48
44
  }
@@ -52,15 +48,14 @@ class TokenCollection extends Array {
52
48
  return Array;
53
49
  }
54
50
  constructor(value, typeOptions) {
55
- var _c, _d, _e, _f, _g, _h;
56
51
  super();
57
- this.disallowToSurroundBySpaces = (_c = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.disallowToSurroundBySpaces) !== null && _c !== void 0 ? _c : false;
58
- this.allowEmpty = (_d = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.allowEmpty) !== null && _d !== void 0 ? _d : true;
59
- this.ordered = (_e = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.ordered) !== null && _e !== void 0 ? _e : false;
60
- this.unique = (_f = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.unique) !== null && _f !== void 0 ? _f : false;
61
- this.caseInsensitive = (_g = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.caseInsensitive) !== null && _g !== void 0 ? _g : true;
62
- this.number = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.number;
63
- this.separator = (_h = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.separator) !== null && _h !== void 0 ? _h : 'space';
52
+ this.disallowToSurroundBySpaces = typeOptions?.disallowToSurroundBySpaces ?? false;
53
+ this.allowEmpty = typeOptions?.allowEmpty ?? true;
54
+ this.ordered = typeOptions?.ordered ?? false;
55
+ this.unique = typeOptions?.unique ?? false;
56
+ this.caseInsensitive = typeOptions?.caseInsensitive ?? true;
57
+ this.number = typeOptions?.number;
58
+ this.separator = typeOptions?.separator ?? 'space';
64
59
  if (typeof value === 'number') {
65
60
  this.length = value;
66
61
  return;
@@ -72,7 +67,7 @@ class TokenCollection extends Array {
72
67
  if (this.separator === 'comma') {
73
68
  separators.push(',');
74
69
  }
75
- if ((typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.specificSeparator) != null) {
70
+ if (typeOptions?.specificSeparator != null) {
76
71
  if (typeof typeOptions.specificSeparator === 'string') {
77
72
  separators.push(typeOptions.specificSeparator);
78
73
  }
@@ -93,8 +88,8 @@ class TokenCollection extends Array {
93
88
  if (lastChar &&
94
89
  !separators.includes(char) &&
95
90
  !separators.includes(lastChar) &&
96
- ((token_1.Token.whitespace.includes(lastChar) && token_1.Token.whitespace.includes(char)) ||
97
- (!token_1.Token.whitespace.includes(lastChar) && !token_1.Token.whitespace.includes(char)))) {
91
+ ((Token.whitespace.includes(lastChar) && Token.whitespace.includes(char)) ||
92
+ (!Token.whitespace.includes(lastChar) && !Token.whitespace.includes(char)))) {
98
93
  values.push(last + char);
99
94
  }
100
95
  else {
@@ -104,7 +99,7 @@ class TokenCollection extends Array {
104
99
  }
105
100
  let offset = 0;
106
101
  values.forEach(v => {
107
- const token = new token_1.Token(v, offset, value, separators);
102
+ const token = new Token(v, offset, value, separators);
108
103
  this.push(token);
109
104
  offset += v.length;
110
105
  });
@@ -114,7 +109,6 @@ class TokenCollection extends Array {
114
109
  return value;
115
110
  }
116
111
  check(options = {}) {
117
- var _c;
118
112
  const { expects, ref } = options;
119
113
  if (this.disallowToSurroundBySpaces) {
120
114
  for (const token of this) {
@@ -128,8 +122,8 @@ class TokenCollection extends Array {
128
122
  }
129
123
  }
130
124
  if (this.separator === 'comma') {
131
- const tokensWithoutWP = this.filter(token => token.type !== token_1.Token.WhiteSpace);
132
- const consecutiveComma = tokensWithoutWP.getConsecutiveToken(token_1.Token.Comma);
125
+ const tokensWithoutWP = this.filter(token => token.type !== Token.WhiteSpace);
126
+ const consecutiveComma = tokensWithoutWP.getConsecutiveToken(Token.Comma);
133
127
  if (consecutiveComma) {
134
128
  return consecutiveComma.unmatched({
135
129
  reason: 'unexpected-comma',
@@ -137,14 +131,14 @@ class TokenCollection extends Array {
137
131
  expects,
138
132
  });
139
133
  }
140
- if (tokensWithoutWP[0] && tokensWithoutWP[0].type === token_1.Token.Comma) {
134
+ if (tokensWithoutWP[0] && tokensWithoutWP[0].type === Token.Comma) {
141
135
  return tokensWithoutWP[0].unmatched({
142
136
  reason: 'unexpected-comma',
143
137
  ref,
144
138
  expects,
145
139
  });
146
140
  }
147
- const takeTurnsError = tokensWithoutWP.takeTurns([token_1.Token.Ident, token_1.Token.Comma], token_1.Token.Ident);
141
+ const takeTurnsError = tokensWithoutWP.takeTurns([Token.Ident, Token.Comma], Token.Ident);
148
142
  if (takeTurnsError) {
149
143
  if (takeTurnsError.unexpectedLastToken) {
150
144
  return takeTurnsError.token.unmatched({
@@ -170,9 +164,9 @@ class TokenCollection extends Array {
170
164
  }
171
165
  }
172
166
  const identTokens = this.getIdentTokens();
173
- const allowEmpty = (_c = this.allowEmpty) !== null && _c !== void 0 ? _c : true;
167
+ const allowEmpty = this.allowEmpty ?? true;
174
168
  if (!allowEmpty && identTokens.length === 0) {
175
- return (0, match_result_1.unmatched)(this.value, 'empty-token', {
169
+ return unmatched(this.value, 'empty-token', {
176
170
  ref,
177
171
  expects,
178
172
  });
@@ -188,7 +182,7 @@ class TokenCollection extends Array {
188
182
  });
189
183
  }
190
184
  }
191
- return (0, match_result_1.matched)();
185
+ return matched();
192
186
  }
193
187
  chunk(split) {
194
188
  const chunks = [];
@@ -224,7 +218,6 @@ class TokenCollection extends Array {
224
218
  return [a, b];
225
219
  }
226
220
  eachCheck(...callbacks) {
227
- var _c, _d;
228
221
  let headAndTail = this.headAndTail();
229
222
  let head = headAndTail.head;
230
223
  let tail = headAndTail.tail;
@@ -237,10 +230,10 @@ class TokenCollection extends Array {
237
230
  wait--;
238
231
  const result = callback.call(this, head, tail);
239
232
  if (result && !result.matched) {
240
- passCount += (_c = result.passCount) !== null && _c !== void 0 ? _c : 0;
233
+ passCount += result.passCount ?? 0;
241
234
  if (prev && result.offset === 0 && result.length === 0) {
242
- const { offset, line, column } = token_1.Token.shiftLocation(prev, cumulativeOffset);
243
- firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : {
235
+ const { offset, line, column } = Token.shiftLocation(prev, cumulativeOffset);
236
+ firstUnmatched = firstUnmatched ?? {
244
237
  ...result,
245
238
  offset,
246
239
  line,
@@ -248,7 +241,7 @@ class TokenCollection extends Array {
248
241
  };
249
242
  }
250
243
  if (!prev && this.value.length === 0) {
251
- firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : {
244
+ firstUnmatched = firstUnmatched ?? {
252
245
  ...result,
253
246
  reason: 'empty-token',
254
247
  expects: undefined,
@@ -265,17 +258,17 @@ class TokenCollection extends Array {
265
258
  }
266
259
  }
267
260
  }
268
- firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : result;
261
+ firstUnmatched = firstUnmatched ?? result;
269
262
  }
270
263
  else if (result && !firstUnmatched && result.matched) {
271
264
  return result;
272
265
  }
273
266
  else {
274
- if ((head === null || head === void 0 ? void 0 : head.value) && !head.match(/^\s*$/)) {
267
+ if (head?.value && !head.match(/^\s*$/)) {
275
268
  passCount += 4 * wait;
276
269
  }
277
270
  }
278
- cumulativeOffset = (_d = head === null || head === void 0 ? void 0 : head.length) !== null && _d !== void 0 ? _d : 0;
271
+ cumulativeOffset = head?.length ?? 0;
279
272
  headAndTail = tail.headAndTail();
280
273
  prev = head;
281
274
  head = headAndTail.head;
@@ -288,7 +281,7 @@ class TokenCollection extends Array {
288
281
  };
289
282
  return res;
290
283
  }
291
- return (0, match_result_1.matched)();
284
+ return matched();
292
285
  }
293
286
  filter(callback) {
294
287
  return TokenCollection._new(super.filter(callback), this);
@@ -299,7 +292,7 @@ class TokenCollection extends Array {
299
292
  return current;
300
293
  }
301
294
  });
302
- return resultToken !== null && resultToken !== void 0 ? resultToken : null;
295
+ return resultToken ?? null;
303
296
  }
304
297
  getDuplicated() {
305
298
  const aList = this.slice();
@@ -323,7 +316,7 @@ class TokenCollection extends Array {
323
316
  return null;
324
317
  }
325
318
  getIdentTokens() {
326
- return this.filter(token => token.type === token_1.Token.Ident);
319
+ return this.filter(token => token.type === Token.Ident);
327
320
  }
328
321
  /**
329
322
  *
@@ -336,7 +329,7 @@ class TokenCollection extends Array {
336
329
  const copy = this.slice();
337
330
  const head = copy.shift();
338
331
  if (!head) {
339
- return { head: head !== null && head !== void 0 ? head : null, tail: TokenCollection._new([], this) };
332
+ return { head: head ?? null, tail: TokenCollection._new([], this) };
340
333
  }
341
334
  const tail = TokenCollection._new(copy, this);
342
335
  return { head, tail };
@@ -387,4 +380,3 @@ class TokenCollection extends Array {
387
380
  return newCollection;
388
381
  }
389
382
  }
390
- exports.TokenCollection = TokenCollection;
@@ -1,5 +1,5 @@
1
- import type { TokenValue } from './types';
2
- import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
1
+ import type { TokenValue } from './types.js';
2
+ import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types.js';
3
3
  export declare class Token {
4
4
  /**
5
5
  * @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
@@ -1,21 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Token = void 0;
4
- class Token {
1
+ export class Token {
5
2
  static getCol(value, offset) {
6
- var _a;
7
3
  const lines = value.slice(0, offset).split(/\n/g);
8
- return ((_a = lines[lines.length - 1]) !== null && _a !== void 0 ? _a : '').length + 1;
4
+ return (lines[lines.length - 1] ?? '').length + 1;
9
5
  }
10
6
  static getLine(value, offset) {
11
7
  return value.slice(0, offset).split(/\n/g).length;
12
8
  }
13
9
  static getType(value, separators) {
14
- var _a, _b;
15
- if (Token.whitespace.includes((_a = value[0]) !== null && _a !== void 0 ? _a : '')) {
10
+ if (Token.whitespace.includes(value[0] ?? '')) {
16
11
  return Token.WhiteSpace;
17
12
  }
18
- if (separators === null || separators === void 0 ? void 0 : separators.includes((_b = value[0]) !== null && _b !== void 0 ? _b : '')) {
13
+ if (separators?.includes(value[0] ?? '')) {
19
14
  switch (value[0]) {
20
15
  case ',':
21
16
  return Token.Comma;
@@ -93,21 +88,19 @@ class Token {
93
88
  return isNaN(num) ? 0 : num;
94
89
  }
95
90
  unmatched(options) {
96
- var _a, _b;
97
91
  return {
98
92
  ...options,
99
93
  matched: false,
100
- ref: (_a = options === null || options === void 0 ? void 0 : options.ref) !== null && _a !== void 0 ? _a : null,
94
+ ref: options?.ref ?? null,
101
95
  raw: this.value,
102
96
  offset: this.offset,
103
97
  length: this.value.length,
104
98
  line: Token.getLine(this.originalValue, this.offset),
105
99
  column: Token.getCol(this.originalValue, this.offset),
106
- reason: (_b = options === null || options === void 0 ? void 0 : options.reason) !== null && _b !== void 0 ? _b : 'syntax-error',
100
+ reason: options?.reason ?? 'syntax-error',
107
101
  };
108
102
  }
109
103
  }
110
- exports.Token = Token;
111
104
  /**
112
105
  * @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
113
106
  */
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/lib/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { cssSyntaxMatch } from './css-syntax';
2
- export type { Type, List, Enum, CssSyntax, KeywordDefinedType, Number } from './types.schema';
1
+ import type { cssSyntaxMatch } from './css-syntax.js';
2
+ export type { Type, List, Enum, CssSyntax, KeywordDefinedType, Number } from './types.schema.js';
3
3
  export type Result = UnmatchedResult | MatchedResult;
4
4
  export type UnmatchedResult = {
5
5
  readonly matched: false;
package/lib/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -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
- Object.defineProperty(exports, "__esModule", { value: true });
6
+ export {};
@@ -1,4 +1,4 @@
1
- import type { CustomSyntaxChecker } from '../types';
1
+ import type { CustomSyntaxChecker } from '../types.js';
2
2
  /**
3
3
  * @see https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy
4
4
  *
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkSerializedPermissionsPolicy = void 0;
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
- (0, debug_1.log)('Failed: %O', res);
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 = token_1.TokenCollection.fromPatterns(value, patterns, { repeat: true });
50
+ const tokens = TokenCollection.fromPatterns(value, patterns, { repeat: true });
55
51
  const serializedPolicyDirectives = tokens.chunk(patterns.length);
56
- (0, debug_1.log)('Serialized Permissions Policy: %s => %O', value, serializedPolicyDirectives);
52
+ log('Serialized Permissions Policy: %s => %O', value, serializedPolicyDirectives);
57
53
  for (const [serializedPolicyDirective] of serializedPolicyDirectives) {
58
54
  if (!serializedPolicyDirective || !serializedPolicyDirective.value) {
59
- return (0, match_result_1.unmatched)('', 'empty-token');
55
+ return unmatched('', 'empty-token');
60
56
  }
61
- const [aw, featureIdentifier, rws, allowListValue] = token_1.TokenCollection.fromPatterns(serializedPolicyDirective, [
57
+ const [aw, featureIdentifier, rws, allowListValue] = TokenCollection.fromPatterns(serializedPolicyDirective, [
62
58
  /**
63
59
  * Any whitespace
64
60
  */
@@ -82,7 +78,7 @@ function _checkSerializedPermissionsPolicy(value) {
82
78
  */
83
79
  /.*/,
84
80
  ]);
85
- (0, debug_1.log)('Serialized Policy Directive: %s => %O', serializedPolicyDirective.value, {
81
+ log('Serialized Policy Directive: %s => %O', serializedPolicyDirective.value, {
86
82
  aw,
87
83
  featureIdentifier,
88
84
  rws,
@@ -120,12 +116,12 @@ function _checkSerializedPermissionsPolicy(value) {
120
116
  // Separator
121
117
  /\s*/,
122
118
  ];
123
- const allowListTokens = token_1.TokenCollection.fromPatterns(allowListValue, allowListPatterns, { repeat: true });
119
+ const allowListTokens = TokenCollection.fromPatterns(allowListValue, allowListPatterns, { repeat: true });
124
120
  const allowList = allowListTokens.chunk(allowListPatterns.length);
125
- (0, debug_1.log)('Allow List: %s => %O', allowListTokens.value, allowList);
121
+ log('Allow List: %s => %O', allowListTokens.value, allowList);
126
122
  for (const [allow] of allowList) {
127
123
  if (!allow || !allow.value) {
128
- return (0, match_result_1.unmatched)('', 'missing-token', {
124
+ return unmatched('', 'missing-token', {
129
125
  expects: [
130
126
  { type: 'const', value: '*' },
131
127
  { type: 'const', value: "'self'" },
@@ -166,7 +162,7 @@ function _checkSerializedPermissionsPolicy(value) {
166
162
  });
167
163
  }
168
164
  }
169
- return (0, match_result_1.matched)();
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
- (0, debug_1.log)('Parse URL: "%s" => %O', token.value, url);
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 (0, match_result_1.matched)();
253
+ return matched();
258
254
  }
259
255
  function parseUrl(value) {
260
256
  try {
@@ -1,4 +1,4 @@
1
- import type { CustomSyntaxChecker } from '../types';
1
+ import type { CustomSyntaxChecker } from '../types.js';
2
2
  /**
3
3
  * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete
4
4
  */
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkAutoComplete = void 0;
4
- const debug_1 = require("../debug");
5
- const get_candidate_1 = require("../get-candidate");
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 token_1.TokenCollection(value, {
99
+ const tokens = new TokenCollection(value, {
103
100
  disallowToSurroundBySpaces: false,
104
101
  allowEmpty: false,
105
102
  ordered: true,
@@ -145,7 +142,7 @@ const checkAutoComplete = () => value => {
145
142
  ref: URL_ON_OFF,
146
143
  });
147
144
  }
148
- return (0, match_result_1.matched)();
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-",
@@ -166,7 +163,7 @@ const checkAutoComplete = () => value => {
166
163
  tail = headAndTail2.tail;
167
164
  if (!head) {
168
165
  // Missing autofill field name but it is valid
169
- return (0, match_result_1.matched)();
166
+ return matched();
170
167
  }
171
168
  }
172
169
  // > Optionally, a token that is an ASCII case-insensitive match for
@@ -194,7 +191,7 @@ const checkAutoComplete = () => value => {
194
191
  tail = headAndTail3.tail;
195
192
  if (!head) {
196
193
  // Missing autofill field name but it is valid
197
- return (0, match_result_1.matched)();
194
+ return matched();
198
195
  }
199
196
  }
200
197
  if (head.match(contactingTokens, true)) {
@@ -202,10 +199,10 @@ const checkAutoComplete = () => value => {
202
199
  const contactableFiledToken = tail[0];
203
200
  if (!contactableFiledToken) {
204
201
  // Missing autofill field name but it is valid
205
- return (0, match_result_1.matched)();
202
+ return matched();
206
203
  }
207
204
  if (!contactableFiledToken.match(contactableFieldNames, true)) {
208
- const candidate = (0, get_candidate_1.getCandidate)(contactableFiledToken.value, contactableFieldNames);
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',
@@ -219,9 +216,9 @@ const checkAutoComplete = () => value => {
219
216
  }
220
217
  if (tail[1]) {
221
218
  if (tail[1].match(webauthnFieldNames)) {
222
- return (0, match_result_1.matched)();
219
+ return matched();
223
220
  }
224
- const candidate = (0, get_candidate_1.getCandidate)(tail[1].value, webauthnFieldNames);
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 (0, match_result_1.matched)();
239
+ return matched();
243
240
  }
244
241
  if (head.match([...autofillFieldNames, ...contactableFieldNames], true)) {
245
242
  if (tail[0]) {
246
243
  if (tail[0].match(webauthnFieldNames)) {
247
- return (0, match_result_1.matched)();
244
+ return matched();
248
245
  }
249
- const candidate = (0, get_candidate_1.getCandidate)(tail[0].value, webauthnFieldNames);
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 (0, match_result_1.matched)();
264
+ return matched();
268
265
  }
269
266
  if (head.match(webauthnFieldNames)) {
270
- return (0, match_result_1.matched)();
267
+ return matched();
271
268
  }
272
269
  const expects = [
273
270
  {
@@ -283,9 +280,9 @@ const checkAutoComplete = () => value => {
283
280
  });
284
281
  // Potentially typo a named group
285
282
  const [prefix, namedGroupStr] = head.value.split('-');
286
- const candidatePrefix = (0, get_candidate_1.getCandidate)(prefix, 'section');
283
+ const candidatePrefix = getCandidate(prefix, 'section');
287
284
  if (candidatePrefix) {
288
- candidate = `${candidatePrefix}-${namedGroupStr !== null && namedGroupStr !== void 0 ? namedGroupStr : ''}`;
285
+ candidate = `${candidatePrefix}-${namedGroupStr ?? ''}`;
289
286
  }
290
287
  }
291
288
  else if (!hasPartOfAddress) {
@@ -296,16 +293,16 @@ const checkAutoComplete = () => value => {
296
293
  type: 'const',
297
294
  value: token,
298
295
  })));
299
- candidate = (0, get_candidate_1.getCandidate)(head.value, partOfAddress, autofillFieldNames, contactingTokens, contactableFieldNames);
296
+ candidate = getCandidate(head.value, partOfAddress, autofillFieldNames, contactingTokens, contactableFieldNames);
300
297
  }
301
298
  else if (!hasContactingToken) {
302
299
  expects.push(...contactingTokens.map(token => ({
303
300
  type: 'const',
304
301
  value: token,
305
302
  })));
306
- candidate = (0, get_candidate_1.getCandidate)(head.value, autofillFieldNames, contactingTokens, contactableFieldNames);
303
+ candidate = getCandidate(head.value, autofillFieldNames, contactingTokens, contactableFieldNames);
307
304
  }
308
- candidate = candidate !== null && candidate !== void 0 ? candidate : (0, get_candidate_1.getCandidate)(head.value, autofillFieldNames);
305
+ candidate = candidate ?? getCandidate(head.value, autofillFieldNames);
309
306
  if (candidate) {
310
307
  acLog('[Unmatched ("%s")] Unexpected token: "%s", Do you mean "%s"? ', value, head.value, candidate);
311
308
  }
@@ -319,4 +316,3 @@ const checkAutoComplete = () => value => {
319
316
  ref: URL_AUTOFILL_FIELD,
320
317
  });
321
318
  };
322
- exports.checkAutoComplete = checkAutoComplete;
@@ -1,4 +1,4 @@
1
- import type { CustomSyntaxChecker } from '../../types';
1
+ import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
3
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates
4
4
  */
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkDateString = void 0;
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
- (0, debug_1.log)('CHECK: date-string');
12
- const tokens = token_1.TokenCollection.fromPatterns(value, [
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
  // -
@@ -21,11 +18,10 @@ const checkDateString = () => function checkDateString(value) {
21
18
  // DD
22
19
  /.[0-9]*/,
23
20
  ]);
24
- (0, debug_1.log)('Date: "%s" => %O', tokens.value, tokens);
25
- const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.month, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.date, datetime_tokens_1.datetimeTokenCheck.extra);
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
- (0, debug_1.log)('Failed: %O', res);
24
+ log('Failed: %O', res);
28
25
  }
29
26
  return res;
30
27
  };
31
- exports.checkDateString = checkDateString;
@@ -1,3 +1,3 @@
1
- import type { TokenEachCheck } from '../../token/token-collection';
1
+ import type { TokenEachCheck } from '../../token/token-collection.js';
2
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>;
3
3
  export declare function getMaxWeekNum(year: number): number;