@markuplint/types 3.0.0-alpha.6 → 3.0.0-dev.176

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 (107) hide show
  1. package/README.md +12 -8
  2. package/lib/check-multi-types.d.ts +1 -1
  3. package/lib/check-multi-types.js +5 -4
  4. package/lib/check.d.ts +6 -5
  5. package/lib/check.spec.js +64 -58
  6. package/lib/css-syntax.js +49 -47
  7. package/lib/css-syntax.spec.js +152 -149
  8. package/lib/defs.js +2 -2
  9. package/lib/enum.d.ts +2 -1
  10. package/lib/enum.js +1 -1
  11. package/lib/get-candidate.d.ts +1 -1
  12. package/lib/keyword-type.js +3 -2
  13. package/lib/list.d.ts +2 -1
  14. package/lib/list.js +2 -1
  15. package/lib/list.spec.js +118 -117
  16. package/lib/match-result.d.ts +3 -3
  17. package/lib/match-result.js +2 -1
  18. package/lib/number.d.ts +1 -1
  19. package/lib/primitive/index.spec.js +53 -52
  20. package/lib/primitive/is-quantity.d.ts +5 -1
  21. package/lib/primitive/is-uint.d.ts +1 -1
  22. package/lib/primitive/split-unit.js +2 -2
  23. package/lib/rfc/is-bcp-47.spec.js +9 -8
  24. package/lib/token/token-collection.d.ts +20 -14
  25. package/lib/token/token-collection.js +30 -23
  26. package/lib/token/token-collection.spec.js +156 -134
  27. package/lib/token/token.d.ts +10 -9
  28. package/lib/token/token.js +19 -20
  29. package/lib/token/types.d.ts +3 -0
  30. package/lib/token/types.js +2 -0
  31. package/lib/types.d.ts +44 -44
  32. package/lib/types.schema.d.ts +369 -318
  33. package/lib/w3c/check-serialized-permissions-policy.spec.js +30 -28
  34. package/lib/whatwg/check-autocomplete.js +6 -6
  35. package/lib/whatwg/check-autocomplete.spec.js +361 -360
  36. package/lib/whatwg/check-datetime/datetime-tokens.js +9 -6
  37. package/lib/whatwg/check-datetime/duration-string.js +12 -2
  38. package/lib/whatwg/check-datetime/index.spec.js +277 -276
  39. package/lib/whatwg/check-datetime/local-date-and-time-string.js +6 -2
  40. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +1 -1
  41. package/lib/whatwg/check-datetime/time-zone-offset-string.js +3 -2
  42. package/lib/whatwg/check-mime-type.js +1 -1
  43. package/lib/whatwg/check-mime-type.spec.js +53 -52
  44. package/lib/whatwg/is-abs-url.spec.js +6 -5
  45. package/lib/whatwg/is-itemprop-name.js +1 -1
  46. package/package.json +13 -11
  47. package/{src/check.spec.ts → test/check.spec.js} +7 -1
  48. package/{src/css-syntax.spec.ts → test/css-syntax.spec.js} +10 -12
  49. package/{src/list.spec.ts → test/list.spec.js} +7 -7
  50. package/{src/primitive/index.spec.ts → test/primitive/index.spec.js} +1 -1
  51. package/{src/rfc/is-bcp-47.spec.ts → test/rfc/is-bcp-47.spec.js} +1 -1
  52. package/{src/token/token-collection.spec.ts → test/token/token-collection.spec.js} +2 -3
  53. package/{src/w3c/check-serialized-permissions-policy.spec.ts → test/w3c/check-serialized-permissions-policy.spec.js} +1 -3
  54. package/{src/whatwg/check-autocomplete.spec.ts → test/whatwg/check-autocomplete.spec.js} +1 -1
  55. package/{src/whatwg/check-datetime/index.spec.ts → test/whatwg/check-datetime/index.spec.js} +18 -15
  56. package/{src/whatwg/check-mime-type.spec.ts → test/whatwg/check-mime-type.spec.js} +1 -1
  57. package/{src/whatwg/is-abs-url.spec.ts → test/whatwg/is-abs-url.spec.js} +1 -1
  58. package/types.schema.json +369 -318
  59. package/gen/specific-schema.json +0 -98
  60. package/gen/types.ts +0 -66
  61. package/src/check-multi-types.ts +0 -35
  62. package/src/check.ts +0 -48
  63. package/src/css-syntax.ts +0 -188
  64. package/src/debug.ts +0 -3
  65. package/src/defs.ts +0 -811
  66. package/src/enum.ts +0 -25
  67. package/src/get-candidate.ts +0 -24
  68. package/src/index.ts +0 -3
  69. package/src/keyword-type.ts +0 -64
  70. package/src/list.ts +0 -34
  71. package/src/match-result.ts +0 -49
  72. package/src/number.ts +0 -46
  73. package/src/primitive/index.ts +0 -7
  74. package/src/primitive/is-float.ts +0 -8
  75. package/src/primitive/is-int.ts +0 -8
  76. package/src/primitive/is-non-zero-uint.ts +0 -8
  77. package/src/primitive/is-quantity.ts +0 -38
  78. package/src/primitive/is-uint.ts +0 -15
  79. package/src/primitive/range.ts +0 -14
  80. package/src/primitive/split-unit.ts +0 -20
  81. package/src/rfc/is-bcp-47.ts +0 -13
  82. package/src/token/index.ts +0 -2
  83. package/src/token/token-collection.ts +0 -444
  84. package/src/token/token.ts +0 -144
  85. package/src/types.schema.ts +0 -1062
  86. package/src/types.ts +0 -118
  87. package/src/w3c/check-serialized-permissions-policy.ts +0 -303
  88. package/src/whatwg/check-autocomplete.ts +0 -380
  89. package/src/whatwg/check-datetime/date-string.ts +0 -44
  90. package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
  91. package/src/whatwg/check-datetime/duration-string.ts +0 -399
  92. package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
  93. package/src/whatwg/check-datetime/index.ts +0 -36
  94. package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
  95. package/src/whatwg/check-datetime/month-string.ts +0 -31
  96. package/src/whatwg/check-datetime/time-string.ts +0 -49
  97. package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
  98. package/src/whatwg/check-datetime/week-string.ts +0 -41
  99. package/src/whatwg/check-datetime/year-string.ts +0 -26
  100. package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
  101. package/src/whatwg/check-mime-type.ts +0 -46
  102. package/src/whatwg/is-abs-url.ts +0 -31
  103. package/src/whatwg/is-browser-context-name.ts +0 -16
  104. package/src/whatwg/is-custom-element-name.ts +0 -76
  105. package/src/whatwg/is-itemprop-name.ts +0 -17
  106. package/tsconfig.test.json +0 -3
  107. package/tsconfig.tsbuildinfo +0 -1
@@ -5,12 +5,13 @@ const match_result_1 = require("../match-result");
5
5
  const token_1 = require("./token");
6
6
  class TokenCollection extends Array {
7
7
  static fromPatterns(value, patterns, typeOptions) {
8
- const origin = typeof value === 'string' ? value : value.origin;
8
+ var _c;
9
+ const originalValue = typeof value === 'string' ? value : value.originalValue;
9
10
  let strings = typeof value === 'string' ? value : value.value;
10
11
  let cumulativeOffset = typeof value === 'string' ? 0 : value.offset;
11
12
  const tokens = [];
12
13
  function addToken(tokenValue) {
13
- const token = new token_1.Token(tokenValue, cumulativeOffset, origin);
14
+ const token = new token_1.Token(tokenValue, cumulativeOffset, originalValue);
14
15
  tokens.push(token);
15
16
  strings = strings.slice(tokenValue.length);
16
17
  cumulativeOffset += tokenValue.length;
@@ -31,7 +32,7 @@ class TokenCollection extends Array {
31
32
  value = strings.slice(res.index + res[0].length);
32
33
  }
33
34
  else {
34
- value = res[0] || '';
35
+ value = (_c = res[0]) !== null && _c !== void 0 ? _c : '';
35
36
  }
36
37
  }
37
38
  const token = addToken(value);
@@ -51,14 +52,15 @@ class TokenCollection extends Array {
51
52
  return Array;
52
53
  }
53
54
  constructor(value, typeOptions) {
55
+ var _c, _d, _e, _f, _g, _h;
54
56
  super();
55
- this.disallowToSurroundBySpaces = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.disallowToSurroundBySpaces) || false;
56
- this.allowEmpty = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.allowEmpty) || true;
57
- this.ordered = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.ordered) || false;
58
- this.unique = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.unique) || false;
59
- this.caseInsensitive = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.caseInsensitive) || true;
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;
60
62
  this.number = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.number;
61
- this.separator = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.separator) || 'space';
63
+ this.separator = (_h = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.separator) !== null && _h !== void 0 ? _h : 'space';
62
64
  if (typeof value === 'number') {
63
65
  this.length = value;
64
66
  return;
@@ -70,12 +72,12 @@ class TokenCollection extends Array {
70
72
  if (this.separator === 'comma') {
71
73
  separators.push(',');
72
74
  }
73
- if (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.specificSeparator) {
74
- if (Array.isArray(typeOptions.specificSeparator)) {
75
- separators.push(...typeOptions.specificSeparator);
75
+ if ((typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.specificSeparator) != null) {
76
+ if (typeof typeOptions.specificSeparator === 'string') {
77
+ separators.push(typeOptions.specificSeparator);
76
78
  }
77
79
  else {
78
- separators.push(typeOptions.specificSeparator);
80
+ separators.push(...typeOptions.specificSeparator);
79
81
  }
80
82
  }
81
83
  const chars = value.split('');
@@ -88,8 +90,9 @@ class TokenCollection extends Array {
88
90
  continue;
89
91
  }
90
92
  const lastChar = last[0];
91
- if (!separators.includes(char) &&
92
- !separators.includes(last[0]) &&
93
+ if (lastChar &&
94
+ !separators.includes(char) &&
95
+ !separators.includes(lastChar) &&
93
96
  ((token_1.Token.whitespace.includes(lastChar) && token_1.Token.whitespace.includes(char)) ||
94
97
  (!token_1.Token.whitespace.includes(lastChar) && !token_1.Token.whitespace.includes(char)))) {
95
98
  values.push(last + char);
@@ -190,7 +193,7 @@ class TokenCollection extends Array {
190
193
  chunk(split) {
191
194
  const chunks = [];
192
195
  const tokens = this.slice();
193
- while (tokens.length) {
196
+ while (tokens.length > 0) {
194
197
  const chunkTokens = tokens.splice(0, split);
195
198
  const chunk = TokenCollection._new(chunkTokens, this);
196
199
  chunks.push(chunk);
@@ -221,6 +224,7 @@ class TokenCollection extends Array {
221
224
  return [a, b];
222
225
  }
223
226
  eachCheck(...callbacks) {
227
+ var _c, _d;
224
228
  let headAndTail = this.headAndTail();
225
229
  let head = headAndTail.head;
226
230
  let tail = headAndTail.tail;
@@ -233,10 +237,10 @@ class TokenCollection extends Array {
233
237
  wait--;
234
238
  const result = callback.call(this, head, tail);
235
239
  if (result && !result.matched) {
236
- passCount += result.passCount || 0;
240
+ passCount += (_c = result.passCount) !== null && _c !== void 0 ? _c : 0;
237
241
  if (prev && result.offset === 0 && result.length === 0) {
238
242
  const { offset, line, column } = token_1.Token.shiftLocation(prev, cumulativeOffset);
239
- firstUnmatched = firstUnmatched || {
243
+ firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : {
240
244
  ...result,
241
245
  offset,
242
246
  line,
@@ -244,7 +248,7 @@ class TokenCollection extends Array {
244
248
  };
245
249
  }
246
250
  if (!prev && this.value.length === 0) {
247
- firstUnmatched = firstUnmatched || {
251
+ firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : {
248
252
  ...result,
249
253
  reason: 'empty-token',
250
254
  expects: undefined,
@@ -261,7 +265,7 @@ class TokenCollection extends Array {
261
265
  }
262
266
  }
263
267
  }
264
- firstUnmatched = firstUnmatched || result;
268
+ firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : result;
265
269
  }
266
270
  else if (result && !firstUnmatched && result.matched) {
267
271
  return result;
@@ -271,7 +275,7 @@ class TokenCollection extends Array {
271
275
  passCount += 4 * wait;
272
276
  }
273
277
  }
274
- cumulativeOffset = (head === null || head === void 0 ? void 0 : head.length) || 0;
278
+ cumulativeOffset = (_d = head === null || head === void 0 ? void 0 : head.length) !== null && _d !== void 0 ? _d : 0;
275
279
  headAndTail = tail.headAndTail();
276
280
  prev = head;
277
281
  head = headAndTail.head;
@@ -295,7 +299,7 @@ class TokenCollection extends Array {
295
299
  return current;
296
300
  }
297
301
  });
298
- return resultToken || null;
302
+ return resultToken !== null && resultToken !== void 0 ? resultToken : null;
299
303
  }
300
304
  getDuplicated() {
301
305
  const aList = this.slice();
@@ -332,7 +336,7 @@ class TokenCollection extends Array {
332
336
  const copy = this.slice();
333
337
  const head = copy.shift();
334
338
  if (!head) {
335
- return { head: head || null, tail: TokenCollection._new([], this) };
339
+ return { head: head !== null && head !== void 0 ? head : null, tail: TokenCollection._new([], this) };
336
340
  }
337
341
  const tail = TokenCollection._new(copy, this);
338
342
  return { head, tail };
@@ -353,6 +357,9 @@ class TokenCollection extends Array {
353
357
  const tokens = this.slice();
354
358
  for (let i = 0; i < tokens.length; i++) {
355
359
  const token = tokens[i];
360
+ if (!token) {
361
+ continue;
362
+ }
356
363
  const expectedTokenNumber = tokenNumbers[i % tokenNumbers.length];
357
364
  if (token.type !== expectedTokenNumber) {
358
365
  return {
@@ -1,144 +1,166 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const token_collection_1 = require("./token-collection");
4
- const _1 = require(".");
1
+ 'use strict';
2
+ // @ts-nocheck
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+ const token_collection_1 = require('./token-collection');
5
+
6
+ const _1 = require('.');
5
7
  test('parse', () => {
6
- expect(new token_collection_1.TokenCollection(' a b c ').toJSON()).toStrictEqual([
7
- {
8
- offset: 0,
9
- type: 13,
10
- value: ' ',
11
- },
12
- {
13
- offset: 1,
14
- type: 1,
15
- value: 'a',
16
- },
17
- {
18
- offset: 2,
19
- type: 13,
20
- value: ' ',
21
- },
22
- {
23
- offset: 4,
24
- type: 1,
25
- value: 'b',
26
- },
27
- {
28
- offset: 5,
29
- type: 13,
30
- value: ' ',
31
- },
32
- {
33
- offset: 8,
34
- type: 1,
35
- value: 'c',
36
- },
37
- {
38
- offset: 9,
39
- type: 13,
40
- value: ' ',
41
- },
42
- ]);
8
+ expect(new token_collection_1.TokenCollection(' a b c ').toJSON()).toStrictEqual([
9
+ {
10
+ offset: 0,
11
+ type: 13,
12
+ value: ' ',
13
+ },
14
+ {
15
+ offset: 1,
16
+ type: 1,
17
+ value: 'a',
18
+ },
19
+ {
20
+ offset: 2,
21
+ type: 13,
22
+ value: ' ',
23
+ },
24
+ {
25
+ offset: 4,
26
+ type: 1,
27
+ value: 'b',
28
+ },
29
+ {
30
+ offset: 5,
31
+ type: 13,
32
+ value: ' ',
33
+ },
34
+ {
35
+ offset: 8,
36
+ type: 1,
37
+ value: 'c',
38
+ },
39
+ {
40
+ offset: 9,
41
+ type: 13,
42
+ value: ' ',
43
+ },
44
+ ]);
43
45
  });
44
46
  test('parse comma separator', () => {
45
- expect(new token_collection_1.TokenCollection('a,, ,b,cde', { separator: 'comma' }).toJSON()).toStrictEqual([
46
- {
47
- offset: 0,
48
- type: 1,
49
- value: 'a',
50
- },
51
- {
52
- offset: 1,
53
- type: 18,
54
- value: ',',
55
- },
56
- {
57
- offset: 2,
58
- type: 18,
59
- value: ',',
60
- },
61
- {
62
- offset: 3,
63
- type: 13,
64
- value: ' ',
65
- },
66
- {
67
- offset: 4,
68
- type: 18,
69
- value: ',',
70
- },
71
- {
72
- offset: 5,
73
- type: 1,
74
- value: 'b',
75
- },
76
- {
77
- offset: 6,
78
- type: 18,
79
- value: ',',
80
- },
81
- {
82
- offset: 7,
83
- type: 1,
84
- value: 'cde',
85
- },
86
- ]);
47
+ expect(new token_collection_1.TokenCollection('a,, ,b,cde', { separator: 'comma' }).toJSON()).toStrictEqual([
48
+ {
49
+ offset: 0,
50
+ type: 1,
51
+ value: 'a',
52
+ },
53
+ {
54
+ offset: 1,
55
+ type: 18,
56
+ value: ',',
57
+ },
58
+ {
59
+ offset: 2,
60
+ type: 18,
61
+ value: ',',
62
+ },
63
+ {
64
+ offset: 3,
65
+ type: 13,
66
+ value: ' ',
67
+ },
68
+ {
69
+ offset: 4,
70
+ type: 18,
71
+ value: ',',
72
+ },
73
+ {
74
+ offset: 5,
75
+ type: 1,
76
+ value: 'b',
77
+ },
78
+ {
79
+ offset: 6,
80
+ type: 18,
81
+ value: ',',
82
+ },
83
+ {
84
+ offset: 7,
85
+ type: 1,
86
+ value: 'cde',
87
+ },
88
+ ]);
87
89
  });
88
90
  test('A comma is an ident if the comma is not a separator', () => {
89
- expect(new token_collection_1.TokenCollection('a ,cde , f').toJSON()).toStrictEqual([
90
- {
91
- offset: 0,
92
- type: 1,
93
- value: 'a',
94
- },
95
- {
96
- offset: 1,
97
- type: 13,
98
- value: ' ',
99
- },
100
- {
101
- offset: 2,
102
- type: 1,
103
- value: ',cde',
104
- },
105
- {
106
- offset: 6,
107
- type: 13,
108
- value: ' ',
109
- },
110
- {
111
- offset: 7,
112
- type: 1,
113
- value: ',',
114
- },
115
- {
116
- offset: 8,
117
- type: 13,
118
- value: ' ',
119
- },
120
- {
121
- offset: 9,
122
- type: 1,
123
- value: 'f',
124
- },
125
- ]);
91
+ expect(new token_collection_1.TokenCollection('a ,cde , f').toJSON()).toStrictEqual([
92
+ {
93
+ offset: 0,
94
+ type: 1,
95
+ value: 'a',
96
+ },
97
+ {
98
+ offset: 1,
99
+ type: 13,
100
+ value: ' ',
101
+ },
102
+ {
103
+ offset: 2,
104
+ type: 1,
105
+ value: ',cde',
106
+ },
107
+ {
108
+ offset: 6,
109
+ type: 13,
110
+ value: ' ',
111
+ },
112
+ {
113
+ offset: 7,
114
+ type: 1,
115
+ value: ',',
116
+ },
117
+ {
118
+ offset: 8,
119
+ type: 13,
120
+ value: ' ',
121
+ },
122
+ {
123
+ offset: 9,
124
+ type: 1,
125
+ value: 'f',
126
+ },
127
+ ]);
126
128
  });
127
129
  test('getConsecutiveToken', () => {
128
- var _a;
129
- expect(new token_collection_1.TokenCollection('a,b,c', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma)).toBeFalsy();
130
- expect(new token_collection_1.TokenCollection('a,,b', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma)).toBeTruthy();
131
- expect((_a = new token_collection_1.TokenCollection('a,,b', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma)) === null || _a === void 0 ? void 0 : _a.offset).toBe(2);
130
+ let _a;
131
+ expect(
132
+ new token_collection_1.TokenCollection('a,b,c', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma),
133
+ ).toBeFalsy();
134
+ expect(
135
+ new token_collection_1.TokenCollection('a,,b', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma),
136
+ ).toBeTruthy();
137
+ expect(
138
+ (_a = new token_collection_1.TokenCollection('a,,b', { separator: 'comma' }).getConsecutiveToken(
139
+ _1.Token.Comma,
140
+ )) === null || _a === void 0
141
+ ? void 0
142
+ : _a.offset,
143
+ ).toBe(2);
132
144
  });
133
145
  test('fromPatterns', () => {
134
- const patterns = [/\+|-/, /[0-9]{2}/, /:?/, /[0-9]{2}/];
135
- expect(token_collection_1.TokenCollection.fromPatterns('+00:00', patterns).map(t => t.value)).toStrictEqual(['+', '00', ':', '00']);
136
- expect(token_collection_1.TokenCollection.fromPatterns('+0000', patterns).map(t => t.value)).toStrictEqual(['+', '00', '', '00']);
137
- expect(token_collection_1.TokenCollection.fromPatterns('+00/00', patterns).map(t => t.value)).toStrictEqual([
138
- '+',
139
- '00',
140
- '',
141
- '',
142
- '/00',
143
- ]);
146
+ const patterns = [/\+|-/, /[0-9]{2}/, /:?/, /[0-9]{2}/];
147
+ expect(token_collection_1.TokenCollection.fromPatterns('+00:00', patterns).map(t => t.value)).toStrictEqual([
148
+ '+',
149
+ '00',
150
+ ':',
151
+ '00',
152
+ ]);
153
+ expect(token_collection_1.TokenCollection.fromPatterns('+0000', patterns).map(t => t.value)).toStrictEqual([
154
+ '+',
155
+ '00',
156
+ '',
157
+ '00',
158
+ ]);
159
+ expect(token_collection_1.TokenCollection.fromPatterns('+00/00', patterns).map(t => t.value)).toStrictEqual([
160
+ '+',
161
+ '00',
162
+ '',
163
+ '',
164
+ '/00',
165
+ ]);
144
166
  });
@@ -1,6 +1,6 @@
1
+ import type { TokenValue } from './types';
1
2
  import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
2
3
  export declare class Token {
3
- #private;
4
4
  /**
5
5
  * @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
6
6
  */
@@ -20,9 +20,9 @@ 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?: string[]): 1 | 13 | 18;
23
+ static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
24
24
  static shiftLocation(
25
- token: Token,
25
+ token: Readonly<Token>,
26
26
  offset: number,
27
27
  ): {
28
28
  offset: number;
@@ -30,21 +30,22 @@ export declare class Token {
30
30
  column: number;
31
31
  };
32
32
  readonly offset: number;
33
+ readonly originalValue: string;
33
34
  readonly type: number;
34
35
  readonly value: string;
35
- constructor(value: string, offset: number, originalValue: string, separators?: string[]);
36
+ constructor(value: string, offset: number, originalValue: string, separators?: readonly string[]);
36
37
  get length(): number;
37
- get origin(): string;
38
+ clone(): Token;
38
39
  /**
39
40
  *
40
41
  * @param value The token value or the token type or its list
41
42
  */
42
- includes(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean;
43
+ includes(value: TokenValue, caseInsensitive?: boolean): boolean;
43
44
  /**
44
45
  *
45
46
  * @param value The token value or the token type or its list
46
47
  */
47
- match(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean;
48
+ match(value: TokenValue, caseInsensitive?: boolean): boolean;
48
49
  toJSON(): {
49
50
  type: number;
50
51
  value: string;
@@ -53,8 +54,8 @@ export declare class Token {
53
54
  toNumber(): number;
54
55
  unmatched(
55
56
  options?: UnmatchedResultOptions & {
56
- ref?: string;
57
- reason?: UnmatchedResultReason;
57
+ readonly ref?: string;
58
+ readonly reason?: UnmatchedResultReason;
58
59
  },
59
60
  ): UnmatchedResult;
60
61
  }
@@ -1,21 +1,21 @@
1
1
  "use strict";
2
- var _Token_originalValue;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.Token = void 0;
5
- const tslib_1 = require("tslib");
6
4
  class Token {
7
5
  static getCol(value, offset) {
6
+ var _a;
8
7
  const lines = value.slice(0, offset).split(/\n/g);
9
- return lines[lines.length - 1].length + 1;
8
+ return ((_a = lines[lines.length - 1]) !== null && _a !== void 0 ? _a : '').length + 1;
10
9
  }
11
10
  static getLine(value, offset) {
12
11
  return value.slice(0, offset).split(/\n/g).length;
13
12
  }
14
13
  static getType(value, separators) {
15
- if (Token.whitespace.includes(value[0])) {
14
+ var _a, _b;
15
+ if (Token.whitespace.includes((_a = value[0]) !== null && _a !== void 0 ? _a : '')) {
16
16
  return Token.WhiteSpace;
17
17
  }
18
- if (separators === null || separators === void 0 ? void 0 : separators.includes(value[0])) {
18
+ if (separators === null || separators === void 0 ? void 0 : separators.includes((_b = value[0]) !== null && _b !== void 0 ? _b : '')) {
19
19
  switch (value[0]) {
20
20
  case ',':
21
21
  return Token.Comma;
@@ -27,22 +27,21 @@ class Token {
27
27
  const shifted = token.offset + offset;
28
28
  return {
29
29
  offset: shifted,
30
- line: Token.getLine(tslib_1.__classPrivateFieldGet(token, _Token_originalValue, "f"), shifted),
31
- column: Token.getCol(tslib_1.__classPrivateFieldGet(token, _Token_originalValue, "f"), shifted),
30
+ line: Token.getLine(token.originalValue, shifted),
31
+ column: Token.getCol(token.originalValue, shifted),
32
32
  };
33
33
  }
34
34
  constructor(value, offset, originalValue, separators) {
35
- _Token_originalValue.set(this, void 0);
36
35
  this.type = Token.getType(value, separators);
37
36
  this.value = value;
38
37
  this.offset = offset;
39
- tslib_1.__classPrivateFieldSet(this, _Token_originalValue, originalValue, "f");
38
+ this.originalValue = originalValue;
40
39
  }
41
40
  get length() {
42
41
  return this.value.length;
43
42
  }
44
- get origin() {
45
- return tslib_1.__classPrivateFieldGet(this, _Token_originalValue, "f");
43
+ clone() {
44
+ return new Token(this.value, this.offset, this.originalValue);
46
45
  }
47
46
  /**
48
47
  *
@@ -55,7 +54,7 @@ class Token {
55
54
  if (typeof value === 'string') {
56
55
  const a = caseInsensitive ? this.value.toLowerCase() : this.value;
57
56
  const b = caseInsensitive ? value.toLowerCase() : value;
58
- return a.indexOf(b) !== -1;
57
+ return a.includes(b);
59
58
  }
60
59
  if (value instanceof RegExp) {
61
60
  const pattern = new RegExp(value, caseInsensitive ? 'i' : '');
@@ -90,25 +89,24 @@ class Token {
90
89
  };
91
90
  }
92
91
  toNumber() {
93
- return parseFloat(this.value);
92
+ const num = parseFloat(this.value);
93
+ return isNaN(num) ? 0 : num;
94
94
  }
95
95
  unmatched(options) {
96
- var _a;
96
+ var _a, _b;
97
97
  return {
98
98
  ...options,
99
99
  matched: false,
100
- ref: (options === null || options === void 0 ? void 0 : options.ref) || null,
100
+ ref: (_a = options === null || options === void 0 ? void 0 : options.ref) !== null && _a !== void 0 ? _a : null,
101
101
  raw: this.value,
102
102
  offset: this.offset,
103
103
  length: this.value.length,
104
- line: Token.getLine(tslib_1.__classPrivateFieldGet(this, _Token_originalValue, "f"), this.offset),
105
- column: Token.getCol(tslib_1.__classPrivateFieldGet(this, _Token_originalValue, "f"), this.offset),
106
- reason: (_a = options === null || options === void 0 ? void 0 : options.reason) !== null && _a !== void 0 ? _a : 'syntax-error',
104
+ line: Token.getLine(this.originalValue, this.offset),
105
+ 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',
107
107
  };
108
108
  }
109
109
  }
110
- exports.Token = Token;
111
- _Token_originalValue = new WeakMap();
112
110
  /**
113
111
  * @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
114
112
  */
@@ -126,3 +124,4 @@ Token.WhiteSpace = 13;
126
124
  * @see https://infra.spec.whatwg.org/#ascii-whitespace
127
125
  */
128
126
  Token.whitespace = ['\u0009', '\u000A', '\u000C', '\u000D', '\u0020'];
127
+ exports.Token = Token;
@@ -0,0 +1,3 @@
1
+ export type TokenValueScalar = string | Readonly<RegExp> | number;
2
+ export type TokenValueArray = readonly TokenValue[];
3
+ export type TokenValue = TokenValueScalar | TokenValueArray;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });