@markuplint/types 3.12.0 → 4.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/LICENSE +1 -1
  2. package/lib/check-multi-types.d.ts +2 -5
  3. package/lib/check-multi-types.js +9 -14
  4. package/lib/check.d.ts +1 -1
  5. package/lib/check.js +20 -30
  6. package/lib/css-syntax.d.ts +1 -1
  7. package/lib/css-syntax.js +33 -33
  8. package/lib/debug.js +2 -6
  9. package/lib/defs.d.ts +2 -1
  10. package/lib/defs.js +188 -138
  11. package/lib/enum.d.ts +2 -2
  12. package/lib/enum.js +7 -12
  13. package/lib/get-candidate.d.ts +1 -4
  14. package/lib/get-candidate.js +5 -10
  15. package/lib/index.d.ts +3 -3
  16. package/lib/index.js +3 -6
  17. package/lib/keyword-type.d.ts +2 -2
  18. package/lib/keyword-type.js +20 -25
  19. package/lib/list.d.ts +2 -2
  20. package/lib/list.js +9 -14
  21. package/lib/match-result.d.ts +8 -21
  22. package/lib/match-result.js +6 -13
  23. package/lib/number.d.ts +3 -3
  24. package/lib/number.js +13 -17
  25. package/lib/primitive/index.d.ts +7 -7
  26. package/lib/primitive/index.js +7 -17
  27. package/lib/primitive/is-float.js +2 -6
  28. package/lib/primitive/is-int.js +2 -6
  29. package/lib/primitive/is-non-zero-uint.js +2 -6
  30. package/lib/primitive/is-quantity.d.ts +1 -5
  31. package/lib/primitive/is-quantity.js +9 -13
  32. package/lib/primitive/is-uint.d.ts +3 -6
  33. package/lib/primitive/is-uint.js +4 -8
  34. package/lib/primitive/range.js +3 -7
  35. package/lib/primitive/split-unit.d.ts +2 -2
  36. package/lib/primitive/split-unit.js +4 -8
  37. package/lib/rfc/is-bcp-47.d.ts +1 -1
  38. package/lib/rfc/is-bcp-47.js +3 -7
  39. package/lib/token/index.d.ts +2 -2
  40. package/lib/token/index.js +2 -7
  41. package/lib/token/token-collection.d.ts +58 -70
  42. package/lib/token/token-collection.js +47 -56
  43. package/lib/token/token.d.ts +54 -59
  44. package/lib/token/token.js +14 -20
  45. package/lib/token/types.js +1 -2
  46. package/lib/types.d.ts +58 -82
  47. package/lib/types.js +1 -2
  48. package/lib/types.schema.d.ts +31 -1087
  49. package/lib/types.schema.js +1 -2
  50. package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
  51. package/lib/w3c/check-serialized-permissions-policy.js +21 -25
  52. package/lib/whatwg/check-autocomplete.d.ts +1 -1
  53. package/lib/whatwg/check-autocomplete.js +34 -41
  54. package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
  55. package/lib/whatwg/check-datetime/date-string.js +12 -16
  56. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +2 -22
  57. package/lib/whatwg/check-datetime/datetime-tokens.js +58 -64
  58. package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
  59. package/lib/whatwg/check-datetime/duration-string.js +64 -69
  60. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
  61. package/lib/whatwg/check-datetime/global-date-and-time-string.js +24 -28
  62. package/lib/whatwg/check-datetime/index.d.ts +1 -1
  63. package/lib/whatwg/check-datetime/index.js +25 -29
  64. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
  65. package/lib/whatwg/check-datetime/local-date-and-time-string.js +37 -41
  66. package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
  67. package/lib/whatwg/check-datetime/month-string.js +9 -13
  68. package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
  69. package/lib/whatwg/check-datetime/time-string.js +13 -17
  70. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
  71. package/lib/whatwg/check-datetime/time-zone-offset-string.js +22 -28
  72. package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
  73. package/lib/whatwg/check-datetime/week-string.js +11 -15
  74. package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
  75. package/lib/whatwg/check-datetime/year-string.js +9 -13
  76. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
  77. package/lib/whatwg/check-datetime/yearless-date-string.js +11 -15
  78. package/lib/whatwg/check-mime-type.d.ts +5 -5
  79. package/lib/whatwg/check-mime-type.js +11 -17
  80. package/lib/whatwg/is-abs-url.d.ts +1 -1
  81. package/lib/whatwg/is-abs-url.js +8 -12
  82. package/lib/whatwg/is-browser-context-name.d.ts +1 -1
  83. package/lib/whatwg/is-browser-context-name.js +1 -5
  84. package/lib/whatwg/is-custom-element-name.d.ts +10 -5
  85. package/lib/whatwg/is-custom-element-name.js +22 -38
  86. package/lib/whatwg/is-itemprop-name.d.ts +1 -1
  87. package/lib/whatwg/is-itemprop-name.js +1 -5
  88. package/lib/whatwg/is-navigable-target-name.d.ts +1 -1
  89. package/lib/whatwg/is-navigable-target-name.js +1 -5
  90. package/package.json +17 -9
  91. package/test/check.spec.js +0 -89
  92. package/test/css-syntax.spec.js +0 -170
  93. package/test/list.spec.js +0 -133
  94. package/test/primitive/index.spec.js +0 -65
  95. package/test/rfc/is-bcp-47.spec.js +0 -23
  96. package/test/token/token-collection.spec.js +0 -146
  97. package/test/w3c/check-serialized-permissions-policy.spec.js +0 -36
  98. package/test/whatwg/check-autocomplete.spec.js +0 -387
  99. package/test/whatwg/check-datetime/index.spec.js +0 -336
  100. package/test/whatwg/check-mime-type.spec.js +0 -59
  101. package/test/whatwg/is-abs-url.spec.js +0 -8
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBCP47 = void 0;
4
- const bcp_47_1 = require("bcp-47");
1
+ import { parse } from 'bcp-47';
5
2
  /**
6
3
  * @see https://tools.ietf.org/rfc/bcp/bcp47.html
7
4
  */
8
- const isBCP47 = () => {
5
+ export const isBCP47 = () => {
9
6
  return value => {
10
- const { language } = (0, bcp_47_1.parse)(value);
7
+ const { language } = parse(value);
11
8
  return !!language;
12
9
  };
13
10
  };
14
- exports.isBCP47 = isBCP47;
@@ -1,2 +1,2 @@
1
- export { Token } from './token';
2
- export { TokenCollection } from './token-collection';
1
+ export { Token } from './token.js';
2
+ export { TokenCollection } from './token-collection.js';
@@ -1,7 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenCollection = exports.Token = void 0;
4
- var token_1 = require("./token");
5
- Object.defineProperty(exports, "Token", { enumerable: true, get: function () { return token_1.Token; } });
6
- var token_collection_1 = require("./token-collection");
7
- Object.defineProperty(exports, "TokenCollection", { enumerable: true, get: function () { return token_collection_1.TokenCollection; } });
1
+ export { Token } from './token.js';
2
+ export { TokenCollection } from './token-collection.js';
@@ -1,74 +1,62 @@
1
- import type { TokenValue } from './types';
2
- import type { UnmatchedResult } from '..';
3
- import type { Expect, Result, List } from '../types';
4
- import { Token } from './token';
5
- type TokenCollectionOptions = Partial<
6
- Omit<List, 'token'> & {
7
- specificSeparator: string | string[];
8
- }
9
- >;
1
+ import type { TokenValue } from './types.js';
2
+ import type { Expect, Result, List, UnmatchedResult } from '../types.js';
3
+ import { Token } from './token.js';
4
+ type TokenCollectionOptions = Partial<Omit<List, 'token'> & {
5
+ specificSeparator: string | string[];
6
+ }>;
10
7
  export type TokenEachCheck = (head: Readonly<Token> | null, tail: TokenCollection) => Result | void;
11
8
  export declare class TokenCollection extends Array<Token> {
12
- static fromPatterns(
13
- value: Readonly<Token> | string,
14
- patterns: readonly Readonly<RegExp>[],
15
- typeOptions?: Omit<TokenCollectionOptions, 'specificSeparator'> & {
16
- repeat?: boolean;
17
- },
18
- ): TokenCollection;
19
- static get [Symbol.species](): ArrayConstructor;
20
- readonly allowEmpty: NonNullable<List['allowEmpty']>;
21
- readonly caseInsensitive: NonNullable<List['caseInsensitive']>;
22
- readonly disallowToSurroundBySpaces: NonNullable<List['disallowToSurroundBySpaces']>;
23
- readonly number: List['number'];
24
- readonly ordered: NonNullable<List['ordered']>;
25
- readonly separator: NonNullable<List['separator']>;
26
- readonly unique: NonNullable<List['unique']>;
27
- constructor(value?: string, typeOptions?: TokenCollectionOptions);
28
- constructor(value?: number);
29
- get value(): string;
30
- check(options?: {
31
- expects?: Expect[];
32
- ref?: string;
33
- cache?: boolean;
34
- }): UnmatchedResult | import('..').MatchedResult;
35
- chunk(split: number): TokenCollection[];
36
- compareTokens(
37
- callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void,
38
- ): Readonly<Token> | null | undefined;
39
- divide(position: number): readonly [TokenCollection, TokenCollection];
40
- eachCheck(...callbacks: readonly TokenEachCheck[]): Result;
41
- filter(callback: Parameters<Array<Token>['filter']>[0]): TokenCollection;
42
- getConsecutiveToken(tokenType: number): Readonly<Token> | null;
43
- getDuplicated(): Token | null;
44
- getIdentTokens(): TokenCollection;
45
- /**
46
- *
47
- * @param value The token value or the token type or its list
48
- */
49
- has(value: TokenValue): boolean;
50
- headAndTail(): {
51
- head: Token | null;
52
- tail: TokenCollection;
53
- };
54
- /**
55
- *
56
- * @param value The token value or the token type or its list
57
- */
58
- search(value: TokenValue): Token | null;
59
- takeTurns(
60
- tokenNumbers: ReadonlyArray<number>,
61
- lastTokenNumber?: number,
62
- ): {
63
- unexpectedLastToken: boolean;
64
- expectedTokenNumber: number | undefined;
65
- token: Token;
66
- } | null;
67
- toJSON(): {
68
- type: number;
69
- value: string;
70
- offset: number;
71
- }[];
72
- private static _new;
9
+ static fromPatterns(value: Readonly<Token> | string, patterns: readonly Readonly<RegExp>[], typeOptions?: Omit<TokenCollectionOptions, 'specificSeparator'> & {
10
+ repeat?: boolean;
11
+ }): TokenCollection;
12
+ static get [Symbol.species](): ArrayConstructor;
13
+ readonly allowEmpty: NonNullable<List['allowEmpty']>;
14
+ readonly caseInsensitive: NonNullable<List['caseInsensitive']>;
15
+ readonly disallowToSurroundBySpaces: NonNullable<List['disallowToSurroundBySpaces']>;
16
+ readonly number: List['number'];
17
+ readonly ordered: NonNullable<List['ordered']>;
18
+ readonly separator: NonNullable<List['separator']>;
19
+ readonly unique: NonNullable<List['unique']>;
20
+ constructor(value?: string, typeOptions?: TokenCollectionOptions);
21
+ constructor(value?: number);
22
+ get value(): string;
23
+ check(options?: {
24
+ expects?: Expect[];
25
+ ref?: string;
26
+ cache?: boolean;
27
+ }): import("../types.js").MatchedResult | UnmatchedResult;
28
+ chunk(split: number): TokenCollection[];
29
+ compareTokens(callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void): Readonly<Token> | null | undefined;
30
+ divide(position: number): readonly [TokenCollection, TokenCollection];
31
+ eachCheck(...callbacks: readonly TokenEachCheck[]): Result;
32
+ filter(callback: Parameters<Array<Token>['filter']>[0]): TokenCollection;
33
+ getConsecutiveToken(tokenType: number): Readonly<Token> | null;
34
+ getDuplicated(): Token | null;
35
+ getIdentTokens(): TokenCollection;
36
+ /**
37
+ *
38
+ * @param value The token value or the token type or its list
39
+ */
40
+ has(value: TokenValue): boolean;
41
+ headAndTail(): {
42
+ head: Token | null;
43
+ tail: TokenCollection;
44
+ };
45
+ /**
46
+ *
47
+ * @param value The token value or the token type or its list
48
+ */
49
+ search(value: TokenValue): Token | null;
50
+ takeTurns(tokenNumbers: ReadonlyArray<number>, lastTokenNumber?: number): {
51
+ unexpectedLastToken: boolean;
52
+ expectedTokenNumber: number | undefined;
53
+ token: Token;
54
+ } | null;
55
+ toJSON(): {
56
+ type: number;
57
+ value: string;
58
+ offset: number;
59
+ }[];
60
+ private static _new;
73
61
  }
74
62
  export {};
@@ -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;
@@ -25,18 +21,18 @@ class TokenCollection extends Array {
25
21
  for (const pattern of patterns) {
26
22
  const res = pattern.exec(strings);
27
23
  let value;
28
- if (!res) {
29
- isBroken = true;
30
- value = '';
31
- }
32
- else {
33
- if (res.index !== 0) {
34
- value = strings.slice(res.index + res[0].length);
24
+ if (res) {
25
+ if (res.index === 0) {
26
+ value = res[0] ?? '';
35
27
  }
36
28
  else {
37
- value = (_c = res[0]) !== null && _c !== void 0 ? _c : '';
29
+ value = strings.slice(res.index + res[0].length);
38
30
  }
39
31
  }
32
+ else {
33
+ isBroken = true;
34
+ value = '';
35
+ }
40
36
  const token = addToken(value);
41
37
  // @ts-ignore
42
38
  token._ = pattern;
@@ -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
  }
@@ -84,7 +79,7 @@ class TokenCollection extends Array {
84
79
  separators.push(...typeOptions.specificSeparator);
85
80
  }
86
81
  }
87
- const chars = value.split('');
82
+ const chars = [...value];
88
83
  const values = [];
89
84
  let char;
90
85
  while ((char = chars.shift())) {
@@ -97,28 +92,26 @@ 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 {
105
- values.push(last);
106
- values.push(char);
100
+ values.push(last, char);
107
101
  }
108
102
  }
109
103
  let offset = 0;
110
- values.forEach(v => {
111
- const token = new token_1.Token(v, offset, value, separators);
104
+ for (const v of values) {
105
+ const token = new Token(v, offset, value, separators);
112
106
  this.push(token);
113
107
  offset += v.length;
114
- });
108
+ }
115
109
  }
116
110
  get value() {
117
111
  const value = this.map(t => t.value).join('');
118
112
  return value;
119
113
  }
120
114
  check(options = {}) {
121
- var _c;
122
115
  const { expects, ref } = options;
123
116
  if (this.disallowToSurroundBySpaces) {
124
117
  for (const token of this) {
@@ -132,8 +125,8 @@ class TokenCollection extends Array {
132
125
  }
133
126
  }
134
127
  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);
128
+ const tokensWithoutWP = this.filter(token => token.type !== Token.WhiteSpace);
129
+ const consecutiveComma = tokensWithoutWP.getConsecutiveToken(Token.Comma);
137
130
  if (consecutiveComma) {
138
131
  return consecutiveComma.unmatched({
139
132
  reason: 'unexpected-comma',
@@ -141,14 +134,14 @@ class TokenCollection extends Array {
141
134
  expects,
142
135
  });
143
136
  }
144
- if (tokensWithoutWP[0] && tokensWithoutWP[0].type === token_1.Token.Comma) {
137
+ if (tokensWithoutWP[0] && tokensWithoutWP[0].type === Token.Comma) {
145
138
  return tokensWithoutWP[0].unmatched({
146
139
  reason: 'unexpected-comma',
147
140
  ref,
148
141
  expects,
149
142
  });
150
143
  }
151
- const takeTurnsError = tokensWithoutWP.takeTurns([token_1.Token.Ident, token_1.Token.Comma], token_1.Token.Ident);
144
+ const takeTurnsError = tokensWithoutWP.takeTurns([Token.Ident, Token.Comma], Token.Ident);
152
145
  if (takeTurnsError) {
153
146
  if (takeTurnsError.unexpectedLastToken) {
154
147
  return takeTurnsError.token.unmatched({
@@ -174,9 +167,9 @@ class TokenCollection extends Array {
174
167
  }
175
168
  }
176
169
  const identTokens = this.getIdentTokens();
177
- const allowEmpty = (_c = this.allowEmpty) !== null && _c !== void 0 ? _c : true;
170
+ const allowEmpty = this.allowEmpty ?? true;
178
171
  if (!allowEmpty && identTokens.length === 0) {
179
- return (0, match_result_1.unmatched)(this.value, 'empty-token', {
172
+ return unmatched(this.value, 'empty-token', {
180
173
  ref,
181
174
  expects,
182
175
  });
@@ -192,7 +185,7 @@ class TokenCollection extends Array {
192
185
  });
193
186
  }
194
187
  }
195
- return (0, match_result_1.matched)();
188
+ return matched();
196
189
  }
197
190
  chunk(split) {
198
191
  const chunks = [];
@@ -228,7 +221,6 @@ class TokenCollection extends Array {
228
221
  return [a, b];
229
222
  }
230
223
  eachCheck(...callbacks) {
231
- var _c, _d;
232
224
  let headAndTail = this.headAndTail();
233
225
  let head = headAndTail.head;
234
226
  let tail = headAndTail.tail;
@@ -241,10 +233,10 @@ class TokenCollection extends Array {
241
233
  wait--;
242
234
  const result = callback.call(this, head, tail);
243
235
  if (result && !result.matched) {
244
- passCount += (_c = result.passCount) !== null && _c !== void 0 ? _c : 0;
236
+ passCount += result.passCount ?? 0;
245
237
  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 : {
238
+ const { offset, line, column } = Token.shiftLocation(prev, cumulativeOffset);
239
+ firstUnmatched = firstUnmatched ?? {
248
240
  ...result,
249
241
  offset,
250
242
  line,
@@ -252,7 +244,7 @@ class TokenCollection extends Array {
252
244
  };
253
245
  }
254
246
  if (!prev && this.value.length === 0) {
255
- firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : {
247
+ firstUnmatched = firstUnmatched ?? {
256
248
  ...result,
257
249
  reason: 'empty-token',
258
250
  expects: undefined,
@@ -269,17 +261,17 @@ class TokenCollection extends Array {
269
261
  }
270
262
  }
271
263
  }
272
- firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : result;
264
+ firstUnmatched = firstUnmatched ?? result;
273
265
  }
274
266
  else if (result && !firstUnmatched && result.matched) {
275
267
  return result;
276
268
  }
277
269
  else {
278
- if ((head === null || head === void 0 ? void 0 : head.value) && !head.match(/^\s*$/)) {
270
+ if (head?.value && !head.matches(/^\s*$/)) {
279
271
  passCount += 4 * wait;
280
272
  }
281
273
  }
282
- cumulativeOffset = (_d = head === null || head === void 0 ? void 0 : head.length) !== null && _d !== void 0 ? _d : 0;
274
+ cumulativeOffset = head?.length ?? 0;
283
275
  headAndTail = tail.headAndTail();
284
276
  prev = head;
285
277
  head = headAndTail.head;
@@ -292,7 +284,7 @@ class TokenCollection extends Array {
292
284
  };
293
285
  return res;
294
286
  }
295
- return (0, match_result_1.matched)();
287
+ return matched();
296
288
  }
297
289
  filter(callback) {
298
290
  return TokenCollection._new(super.filter(callback), this);
@@ -303,7 +295,7 @@ class TokenCollection extends Array {
303
295
  return current;
304
296
  }
305
297
  });
306
- return resultToken !== null && resultToken !== void 0 ? resultToken : null;
298
+ return resultToken ?? null;
307
299
  }
308
300
  getDuplicated() {
309
301
  const aList = this.slice();
@@ -327,20 +319,20 @@ class TokenCollection extends Array {
327
319
  return null;
328
320
  }
329
321
  getIdentTokens() {
330
- return this.filter(token => token.type === token_1.Token.Ident);
322
+ return this.filter(token => token.type === Token.Ident);
331
323
  }
332
324
  /**
333
325
  *
334
326
  * @param value The token value or the token type or its list
335
327
  */
336
328
  has(value) {
337
- return this.some(t => t.match(value));
329
+ return this.some(t => t.matches(value));
338
330
  }
339
331
  headAndTail() {
340
332
  const copy = this.slice();
341
333
  const head = copy.shift();
342
334
  if (!head) {
343
- return { head: head !== null && head !== void 0 ? head : null, tail: TokenCollection._new([], this) };
335
+ return { head: head ?? null, tail: TokenCollection._new([], this) };
344
336
  }
345
337
  const tail = TokenCollection._new(copy, this);
346
338
  return { head, tail };
@@ -393,4 +385,3 @@ class TokenCollection extends Array {
393
385
  return newCollection;
394
386
  }
395
387
  }
396
- exports.TokenCollection = TokenCollection;
@@ -1,61 +1,56 @@
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
- /**
5
- * @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
6
- */
7
- static readonly Comma = 18;
8
- static readonly Ident = 1;
9
- static readonly WhiteSpace = 13;
10
- /**
11
- * ASCII whitespace is
12
- * - U+0009 TAB
13
- * - U+000A LF
14
- * - U+000C FF
15
- * - U+000D CR
16
- * - U+0020 SPACE.
17
- *
18
- * @see https://infra.spec.whatwg.org/#ascii-whitespace
19
- */
20
- static readonly whitespace: ReadonlyArray<string>;
21
- static getCol(value: string, offset: number): number;
22
- static getLine(value: string, offset: number): number;
23
- static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
24
- static shiftLocation(
25
- token: Readonly<Token>,
26
- offset: number,
27
- ): {
28
- offset: number;
29
- line: number;
30
- column: number;
31
- };
32
- readonly offset: number;
33
- readonly originalValue: string;
34
- readonly type: number;
35
- readonly value: string;
36
- constructor(value: string, offset: number, originalValue: string, separators?: readonly string[]);
37
- get length(): number;
38
- clone(): Token;
39
- /**
40
- *
41
- * @param value The token value or the token type or its list
42
- */
43
- includes(value: TokenValue, caseInsensitive?: boolean): boolean;
44
- /**
45
- *
46
- * @param value The token value or the token type or its list
47
- */
48
- match(value: TokenValue, caseInsensitive?: boolean): boolean;
49
- toJSON(): {
50
- type: number;
51
- value: string;
52
- offset: number;
53
- };
54
- toNumber(): number;
55
- unmatched(
56
- options?: UnmatchedResultOptions & {
57
- readonly ref?: string;
58
- readonly reason?: UnmatchedResultReason;
59
- },
60
- ): UnmatchedResult;
4
+ /**
5
+ * @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
6
+ */
7
+ static readonly Comma = 18;
8
+ static readonly Ident = 1;
9
+ static readonly WhiteSpace = 13;
10
+ /**
11
+ * ASCII whitespace is
12
+ * - U+0009 TAB
13
+ * - U+000A LF
14
+ * - U+000C FF
15
+ * - U+000D CR
16
+ * - U+0020 SPACE.
17
+ *
18
+ * @see https://infra.spec.whatwg.org/#ascii-whitespace
19
+ */
20
+ static readonly whitespace: ReadonlyArray<string>;
21
+ static getCol(value: string, offset: number): number;
22
+ static getLine(value: string, offset: number): number;
23
+ static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
24
+ static shiftLocation(token: Readonly<Token>, offset: number): {
25
+ offset: number;
26
+ line: number;
27
+ column: number;
28
+ };
29
+ readonly offset: number;
30
+ readonly originalValue: string;
31
+ readonly type: number;
32
+ readonly value: string;
33
+ constructor(value: string, offset: number, originalValue: string, separators?: readonly string[]);
34
+ get length(): number;
35
+ clone(): Token;
36
+ /**
37
+ *
38
+ * @param value The token value or the token type or its list
39
+ */
40
+ includes(value: TokenValue, caseInsensitive?: boolean): boolean;
41
+ /**
42
+ *
43
+ * @param value The token value or the token type or its list
44
+ */
45
+ matches(value: TokenValue, caseInsensitive?: boolean): boolean;
46
+ toJSON(): {
47
+ type: number;
48
+ value: string;
49
+ offset: number;
50
+ };
51
+ toNumber(): number;
52
+ unmatched(options?: UnmatchedResultOptions & {
53
+ readonly ref?: string;
54
+ readonly reason?: UnmatchedResultReason;
55
+ }): UnmatchedResult;
61
56
  }
@@ -1,24 +1,20 @@
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
- const lines = value.slice(0, offset).split(/\n/g);
8
- return ((_a = lines[lines.length - 1]) !== null && _a !== void 0 ? _a : '').length + 1;
3
+ const lines = value.slice(0, offset).split(/\n/);
4
+ return (lines.at(-1) ?? '').length + 1;
9
5
  }
10
6
  static getLine(value, offset) {
11
- return value.slice(0, offset).split(/\n/g).length;
7
+ return value.slice(0, offset).split(/\n/).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
- case ',':
15
+ case ',': {
21
16
  return Token.Comma;
17
+ }
22
18
  }
23
19
  }
24
20
  return Token.Ident;
@@ -66,9 +62,9 @@ class Token {
66
62
  *
67
63
  * @param value The token value or the token type or its list
68
64
  */
69
- match(value, caseInsensitive) {
65
+ matches(value, caseInsensitive) {
70
66
  if (Array.isArray(value)) {
71
- return value.some(v => this.match(v));
67
+ return value.some(v => this.matches(v));
72
68
  }
73
69
  if (typeof value === 'string') {
74
70
  const a = caseInsensitive ? this.value.toLowerCase() : this.value;
@@ -89,25 +85,23 @@ class Token {
89
85
  };
90
86
  }
91
87
  toNumber() {
92
- const num = parseFloat(this.value);
93
- return isNaN(num) ? 0 : num;
88
+ const num = Number.parseFloat(this.value);
89
+ return Number.isNaN(num) ? 0 : num;
94
90
  }
95
91
  unmatched(options) {
96
- var _a, _b;
97
92
  return {
98
93
  ...options,
99
94
  matched: false,
100
- ref: (_a = options === null || options === void 0 ? void 0 : options.ref) !== null && _a !== void 0 ? _a : null,
95
+ ref: options?.ref ?? null,
101
96
  raw: this.value,
102
97
  offset: this.offset,
103
98
  length: this.value.length,
104
99
  line: Token.getLine(this.originalValue, this.offset),
105
100
  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',
101
+ reason: options?.reason ?? 'syntax-error',
107
102
  };
108
103
  }
109
104
  }
110
- exports.Token = Token;
111
105
  /**
112
106
  * @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
113
107
  */
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};