@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
@@ -1,19 +1,15 @@
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,
8
5
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
9
6
  typeOptions) {
10
- var _c;
11
7
  const originalValue = typeof value === 'string' ? value : value.originalValue;
12
8
  let strings = typeof value === 'string' ? value : value.value;
13
9
  let cumulativeOffset = typeof value === 'string' ? 0 : value.offset;
14
10
  const tokens = [];
15
11
  function addToken(tokenValue) {
16
- const token = new token_1.Token(tokenValue, cumulativeOffset, originalValue);
12
+ const token = new Token(tokenValue, cumulativeOffset, originalValue);
17
13
  tokens.push(token);
18
14
  strings = strings.slice(tokenValue.length);
19
15
  cumulativeOffset += tokenValue.length;
@@ -34,7 +30,7 @@ class TokenCollection extends Array {
34
30
  value = strings.slice(res.index + res[0].length);
35
31
  }
36
32
  else {
37
- value = (_c = res[0]) !== null && _c !== void 0 ? _c : '';
33
+ value = res[0] ?? '';
38
34
  }
39
35
  }
40
36
  const token = addToken(value);
@@ -44,7 +40,7 @@ class TokenCollection extends Array {
44
40
  if (isBroken) {
45
41
  addToken(strings);
46
42
  }
47
- } while ((typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.repeat) && strings);
43
+ } while (typeOptions?.repeat && strings);
48
44
  if (strings) {
49
45
  addToken(strings);
50
46
  }
@@ -56,15 +52,14 @@ class TokenCollection extends Array {
56
52
  constructor(value,
57
53
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
58
54
  typeOptions) {
59
- var _c, _d, _e, _f, _g, _h;
60
55
  super();
61
- this.disallowToSurroundBySpaces = (_c = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.disallowToSurroundBySpaces) !== null && _c !== void 0 ? _c : false;
62
- this.allowEmpty = (_d = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.allowEmpty) !== null && _d !== void 0 ? _d : true;
63
- this.ordered = (_e = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.ordered) !== null && _e !== void 0 ? _e : false;
64
- this.unique = (_f = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.unique) !== null && _f !== void 0 ? _f : false;
65
- this.caseInsensitive = (_g = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.caseInsensitive) !== null && _g !== void 0 ? _g : true;
66
- this.number = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.number;
67
- this.separator = (_h = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.separator) !== null && _h !== void 0 ? _h : 'space';
56
+ this.disallowToSurroundBySpaces = typeOptions?.disallowToSurroundBySpaces ?? false;
57
+ this.allowEmpty = typeOptions?.allowEmpty ?? true;
58
+ this.ordered = typeOptions?.ordered ?? false;
59
+ this.unique = typeOptions?.unique ?? false;
60
+ this.caseInsensitive = typeOptions?.caseInsensitive ?? true;
61
+ this.number = typeOptions?.number;
62
+ this.separator = typeOptions?.separator ?? 'space';
68
63
  if (typeof value === 'number') {
69
64
  this.length = value;
70
65
  return;
@@ -76,7 +71,7 @@ class TokenCollection extends Array {
76
71
  if (this.separator === 'comma') {
77
72
  separators.push(',');
78
73
  }
79
- if ((typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.specificSeparator) != null) {
74
+ if (typeOptions?.specificSeparator != null) {
80
75
  if (typeof typeOptions.specificSeparator === 'string') {
81
76
  separators.push(typeOptions.specificSeparator);
82
77
  }
@@ -97,8 +92,8 @@ class TokenCollection extends Array {
97
92
  if (lastChar &&
98
93
  !separators.includes(char) &&
99
94
  !separators.includes(lastChar) &&
100
- ((token_1.Token.whitespace.includes(lastChar) && token_1.Token.whitespace.includes(char)) ||
101
- (!token_1.Token.whitespace.includes(lastChar) && !token_1.Token.whitespace.includes(char)))) {
95
+ ((Token.whitespace.includes(lastChar) && Token.whitespace.includes(char)) ||
96
+ (!Token.whitespace.includes(lastChar) && !Token.whitespace.includes(char)))) {
102
97
  values.push(last + char);
103
98
  }
104
99
  else {
@@ -108,7 +103,7 @@ class TokenCollection extends Array {
108
103
  }
109
104
  let offset = 0;
110
105
  values.forEach(v => {
111
- const token = new token_1.Token(v, offset, value, separators);
106
+ const token = new Token(v, offset, value, separators);
112
107
  this.push(token);
113
108
  offset += v.length;
114
109
  });
@@ -118,7 +113,6 @@ class TokenCollection extends Array {
118
113
  return value;
119
114
  }
120
115
  check(options = {}) {
121
- var _c;
122
116
  const { expects, ref } = options;
123
117
  if (this.disallowToSurroundBySpaces) {
124
118
  for (const token of this) {
@@ -132,8 +126,8 @@ class TokenCollection extends Array {
132
126
  }
133
127
  }
134
128
  if (this.separator === 'comma') {
135
- const tokensWithoutWP = this.filter(token => token.type !== token_1.Token.WhiteSpace);
136
- const consecutiveComma = tokensWithoutWP.getConsecutiveToken(token_1.Token.Comma);
129
+ const tokensWithoutWP = this.filter(token => token.type !== Token.WhiteSpace);
130
+ const consecutiveComma = tokensWithoutWP.getConsecutiveToken(Token.Comma);
137
131
  if (consecutiveComma) {
138
132
  return consecutiveComma.unmatched({
139
133
  reason: 'unexpected-comma',
@@ -141,14 +135,14 @@ class TokenCollection extends Array {
141
135
  expects,
142
136
  });
143
137
  }
144
- if (tokensWithoutWP[0] && tokensWithoutWP[0].type === token_1.Token.Comma) {
138
+ if (tokensWithoutWP[0] && tokensWithoutWP[0].type === Token.Comma) {
145
139
  return tokensWithoutWP[0].unmatched({
146
140
  reason: 'unexpected-comma',
147
141
  ref,
148
142
  expects,
149
143
  });
150
144
  }
151
- const takeTurnsError = tokensWithoutWP.takeTurns([token_1.Token.Ident, token_1.Token.Comma], token_1.Token.Ident);
145
+ const takeTurnsError = tokensWithoutWP.takeTurns([Token.Ident, Token.Comma], Token.Ident);
152
146
  if (takeTurnsError) {
153
147
  if (takeTurnsError.unexpectedLastToken) {
154
148
  return takeTurnsError.token.unmatched({
@@ -174,9 +168,9 @@ class TokenCollection extends Array {
174
168
  }
175
169
  }
176
170
  const identTokens = this.getIdentTokens();
177
- const allowEmpty = (_c = this.allowEmpty) !== null && _c !== void 0 ? _c : true;
171
+ const allowEmpty = this.allowEmpty ?? true;
178
172
  if (!allowEmpty && identTokens.length === 0) {
179
- return (0, match_result_1.unmatched)(this.value, 'empty-token', {
173
+ return unmatched(this.value, 'empty-token', {
180
174
  ref,
181
175
  expects,
182
176
  });
@@ -192,7 +186,7 @@ class TokenCollection extends Array {
192
186
  });
193
187
  }
194
188
  }
195
- return (0, match_result_1.matched)();
189
+ return matched();
196
190
  }
197
191
  chunk(split) {
198
192
  const chunks = [];
@@ -228,7 +222,6 @@ class TokenCollection extends Array {
228
222
  return [a, b];
229
223
  }
230
224
  eachCheck(...callbacks) {
231
- var _c, _d;
232
225
  let headAndTail = this.headAndTail();
233
226
  let head = headAndTail.head;
234
227
  let tail = headAndTail.tail;
@@ -241,10 +234,10 @@ class TokenCollection extends Array {
241
234
  wait--;
242
235
  const result = callback.call(this, head, tail);
243
236
  if (result && !result.matched) {
244
- passCount += (_c = result.passCount) !== null && _c !== void 0 ? _c : 0;
237
+ passCount += result.passCount ?? 0;
245
238
  if (prev && result.offset === 0 && result.length === 0) {
246
- const { offset, line, column } = token_1.Token.shiftLocation(prev, cumulativeOffset);
247
- firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : {
239
+ const { offset, line, column } = Token.shiftLocation(prev, cumulativeOffset);
240
+ firstUnmatched = firstUnmatched ?? {
248
241
  ...result,
249
242
  offset,
250
243
  line,
@@ -252,7 +245,7 @@ class TokenCollection extends Array {
252
245
  };
253
246
  }
254
247
  if (!prev && this.value.length === 0) {
255
- firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : {
248
+ firstUnmatched = firstUnmatched ?? {
256
249
  ...result,
257
250
  reason: 'empty-token',
258
251
  expects: undefined,
@@ -269,17 +262,17 @@ class TokenCollection extends Array {
269
262
  }
270
263
  }
271
264
  }
272
- firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : result;
265
+ firstUnmatched = firstUnmatched ?? result;
273
266
  }
274
267
  else if (result && !firstUnmatched && result.matched) {
275
268
  return result;
276
269
  }
277
270
  else {
278
- if ((head === null || head === void 0 ? void 0 : head.value) && !head.match(/^\s*$/)) {
271
+ if (head?.value && !head.match(/^\s*$/)) {
279
272
  passCount += 4 * wait;
280
273
  }
281
274
  }
282
- cumulativeOffset = (_d = head === null || head === void 0 ? void 0 : head.length) !== null && _d !== void 0 ? _d : 0;
275
+ cumulativeOffset = head?.length ?? 0;
283
276
  headAndTail = tail.headAndTail();
284
277
  prev = head;
285
278
  head = headAndTail.head;
@@ -292,7 +285,7 @@ class TokenCollection extends Array {
292
285
  };
293
286
  return res;
294
287
  }
295
- return (0, match_result_1.matched)();
288
+ return matched();
296
289
  }
297
290
  filter(callback) {
298
291
  return TokenCollection._new(super.filter(callback), this);
@@ -303,7 +296,7 @@ class TokenCollection extends Array {
303
296
  return current;
304
297
  }
305
298
  });
306
- return resultToken !== null && resultToken !== void 0 ? resultToken : null;
299
+ return resultToken ?? null;
307
300
  }
308
301
  getDuplicated() {
309
302
  const aList = this.slice();
@@ -327,7 +320,7 @@ class TokenCollection extends Array {
327
320
  return null;
328
321
  }
329
322
  getIdentTokens() {
330
- return this.filter(token => token.type === token_1.Token.Ident);
323
+ return this.filter(token => token.type === Token.Ident);
331
324
  }
332
325
  /**
333
326
  *
@@ -340,7 +333,7 @@ class TokenCollection extends Array {
340
333
  const copy = this.slice();
341
334
  const head = copy.shift();
342
335
  if (!head) {
343
- return { head: head !== null && head !== void 0 ? head : null, tail: TokenCollection._new([], this) };
336
+ return { head: head ?? null, tail: TokenCollection._new([], this) };
344
337
  }
345
338
  const tail = TokenCollection._new(copy, this);
346
339
  return { head, tail };
@@ -393,4 +386,3 @@ class TokenCollection extends Array {
393
386
  return newCollection;
394
387
  }
395
388
  }
396
- 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
@@ -20,7 +20,7 @@ export declare class Token {
20
20
  static readonly whitespace: ReadonlyArray<string>;
21
21
  static getCol(value: string, offset: number): number;
22
22
  static getLine(value: string, offset: number): number;
23
- static getType(value: string, separators?: readonly string[]): 1 | 18 | 13;
23
+ static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
24
24
  static shiftLocation(token: Readonly<Token>, offset: number): {
25
25
  offset: number;
26
26
  line: number;
@@ -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;