@markuplint/types 3.0.0-canary.5 → 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.
- package/README.md +1 -1
- package/lib/check-multi-types.d.ts +4 -1
- package/lib/check-multi-types.js +5 -4
- package/lib/check.d.ts +6 -5
- package/lib/check.spec.js +64 -58
- package/lib/css-syntax.js +49 -47
- package/lib/css-syntax.spec.js +152 -149
- package/lib/defs.js +2 -2
- package/lib/enum.d.ts +2 -1
- package/lib/enum.js +1 -1
- package/lib/get-candidate.d.ts +4 -1
- package/lib/keyword-type.js +3 -2
- package/lib/list.d.ts +2 -1
- package/lib/list.js +2 -1
- package/lib/list.spec.js +118 -117
- package/lib/match-result.d.ts +21 -8
- package/lib/match-result.js +2 -1
- package/lib/number.d.ts +1 -1
- package/lib/primitive/index.spec.js +53 -52
- package/lib/primitive/is-quantity.d.ts +5 -1
- package/lib/primitive/is-uint.d.ts +6 -3
- package/lib/primitive/split-unit.d.ts +2 -2
- package/lib/primitive/split-unit.js +2 -2
- package/lib/rfc/is-bcp-47.spec.js +9 -8
- package/lib/token/token-collection.d.ts +71 -56
- package/lib/token/token-collection.js +30 -23
- package/lib/token/token-collection.spec.js +156 -134
- package/lib/token/token.d.ts +58 -52
- package/lib/token/token.js +19 -20
- package/lib/token/types.d.ts +3 -0
- package/lib/token/types.js +2 -0
- package/lib/types.d.ts +79 -55
- package/lib/types.schema.d.ts +1084 -31
- package/lib/w3c/check-serialized-permissions-policy.spec.js +30 -28
- package/lib/whatwg/check-autocomplete.js +6 -6
- package/lib/whatwg/check-autocomplete.spec.js +361 -360
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +21 -1
- package/lib/whatwg/check-datetime/datetime-tokens.js +9 -6
- package/lib/whatwg/check-datetime/duration-string.js +12 -2
- package/lib/whatwg/check-datetime/index.spec.js +277 -276
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +6 -2
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +3 -2
- package/lib/whatwg/check-mime-type.d.ts +4 -4
- package/lib/whatwg/check-mime-type.js +1 -1
- package/lib/whatwg/check-mime-type.spec.js +53 -52
- package/lib/whatwg/is-abs-url.spec.js +6 -5
- package/lib/whatwg/is-itemprop-name.js +1 -1
- package/package.json +12 -10
- package/{src/check.spec.ts → test/check.spec.js} +7 -1
- package/{src/css-syntax.spec.ts → test/css-syntax.spec.js} +10 -12
- package/{src/list.spec.ts → test/list.spec.js} +7 -7
- package/{src/primitive/index.spec.ts → test/primitive/index.spec.js} +1 -1
- package/{src/rfc/is-bcp-47.spec.ts → test/rfc/is-bcp-47.spec.js} +1 -1
- package/{src/token/token-collection.spec.ts → test/token/token-collection.spec.js} +2 -3
- package/{src/w3c/check-serialized-permissions-policy.spec.ts → test/w3c/check-serialized-permissions-policy.spec.js} +1 -3
- package/{src/whatwg/check-autocomplete.spec.ts → test/whatwg/check-autocomplete.spec.js} +1 -1
- package/{src/whatwg/check-datetime/index.spec.ts → test/whatwg/check-datetime/index.spec.js} +18 -15
- package/{src/whatwg/check-mime-type.spec.ts → test/whatwg/check-mime-type.spec.js} +1 -1
- package/{src/whatwg/is-abs-url.spec.ts → test/whatwg/is-abs-url.spec.js} +1 -1
- package/types.schema.json +369 -318
- package/gen/specific-schema.json +0 -98
- package/gen/types.ts +0 -66
- package/src/check-multi-types.ts +0 -35
- package/src/check.ts +0 -48
- package/src/css-syntax.ts +0 -188
- package/src/debug.ts +0 -3
- package/src/defs.ts +0 -811
- package/src/enum.ts +0 -25
- package/src/get-candidate.ts +0 -24
- package/src/index.ts +0 -3
- package/src/keyword-type.ts +0 -64
- package/src/list.ts +0 -34
- package/src/match-result.ts +0 -49
- package/src/number.ts +0 -46
- package/src/primitive/index.ts +0 -7
- package/src/primitive/is-float.ts +0 -8
- package/src/primitive/is-int.ts +0 -8
- package/src/primitive/is-non-zero-uint.ts +0 -8
- package/src/primitive/is-quantity.ts +0 -38
- package/src/primitive/is-uint.ts +0 -15
- package/src/primitive/range.ts +0 -14
- package/src/primitive/split-unit.ts +0 -20
- package/src/rfc/is-bcp-47.ts +0 -13
- package/src/token/index.ts +0 -2
- package/src/token/token-collection.ts +0 -444
- package/src/token/token.ts +0 -144
- package/src/types.schema.ts +0 -1062
- package/src/types.ts +0 -118
- package/src/w3c/check-serialized-permissions-policy.ts +0 -303
- package/src/whatwg/check-autocomplete.ts +0 -380
- package/src/whatwg/check-datetime/date-string.ts +0 -44
- package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
- package/src/whatwg/check-datetime/duration-string.ts +0 -399
- package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
- package/src/whatwg/check-datetime/index.ts +0 -36
- package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
- package/src/whatwg/check-datetime/month-string.ts +0 -31
- package/src/whatwg/check-datetime/time-string.ts +0 -49
- package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
- package/src/whatwg/check-datetime/week-string.ts +0 -41
- package/src/whatwg/check-datetime/year-string.ts +0 -26
- package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
- package/src/whatwg/check-mime-type.ts +0 -46
- package/src/whatwg/is-abs-url.ts +0 -31
- package/src/whatwg/is-browser-context-name.ts +0 -16
- package/src/whatwg/is-custom-element-name.ts +0 -76
- package/src/whatwg/is-itemprop-name.ts +0 -17
- package/tsconfig.test.json +0 -3
- 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
|
-
|
|
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,
|
|
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)
|
|
56
|
-
this.allowEmpty = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.allowEmpty)
|
|
57
|
-
this.ordered = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.ordered)
|
|
58
|
-
this.unique = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.unique)
|
|
59
|
-
this.caseInsensitive = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.caseInsensitive)
|
|
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)
|
|
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 (
|
|
75
|
-
separators.push(
|
|
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 (
|
|
92
|
-
!separators.includes(
|
|
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
|
|
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
|
|
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)
|
|
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
|
|
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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
});
|
package/lib/token/token.d.ts
CHANGED
|
@@ -1,55 +1,61 @@
|
|
|
1
|
+
import type { TokenValue } from './types';
|
|
1
2
|
import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
|
|
2
3
|
export declare class Token {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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;
|
|
55
61
|
}
|