@markuplint/types 3.5.1 → 3.6.0

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.
@@ -1,145 +1,166 @@
1
- "use strict";
1
+ 'use strict';
2
2
  // @ts-nocheck
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const token_collection_1 = require("./token-collection");
5
- const _1 = require(".");
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+ const token_collection_1 = require('./token-collection');
5
+
6
+ const _1 = require('.');
6
7
  test('parse', () => {
7
- expect(new token_collection_1.TokenCollection(' a b c ').toJSON()).toStrictEqual([
8
- {
9
- offset: 0,
10
- type: 13,
11
- value: ' ',
12
- },
13
- {
14
- offset: 1,
15
- type: 1,
16
- value: 'a',
17
- },
18
- {
19
- offset: 2,
20
- type: 13,
21
- value: ' ',
22
- },
23
- {
24
- offset: 4,
25
- type: 1,
26
- value: 'b',
27
- },
28
- {
29
- offset: 5,
30
- type: 13,
31
- value: ' ',
32
- },
33
- {
34
- offset: 8,
35
- type: 1,
36
- value: 'c',
37
- },
38
- {
39
- offset: 9,
40
- type: 13,
41
- value: ' ',
42
- },
43
- ]);
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
+ ]);
44
45
  });
45
46
  test('parse comma separator', () => {
46
- expect(new token_collection_1.TokenCollection('a,, ,b,cde', { separator: 'comma' }).toJSON()).toStrictEqual([
47
- {
48
- offset: 0,
49
- type: 1,
50
- value: 'a',
51
- },
52
- {
53
- offset: 1,
54
- type: 18,
55
- value: ',',
56
- },
57
- {
58
- offset: 2,
59
- type: 18,
60
- value: ',',
61
- },
62
- {
63
- offset: 3,
64
- type: 13,
65
- value: ' ',
66
- },
67
- {
68
- offset: 4,
69
- type: 18,
70
- value: ',',
71
- },
72
- {
73
- offset: 5,
74
- type: 1,
75
- value: 'b',
76
- },
77
- {
78
- offset: 6,
79
- type: 18,
80
- value: ',',
81
- },
82
- {
83
- offset: 7,
84
- type: 1,
85
- value: 'cde',
86
- },
87
- ]);
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
+ ]);
88
89
  });
89
90
  test('A comma is an ident if the comma is not a separator', () => {
90
- expect(new token_collection_1.TokenCollection('a ,cde , f').toJSON()).toStrictEqual([
91
- {
92
- offset: 0,
93
- type: 1,
94
- value: 'a',
95
- },
96
- {
97
- offset: 1,
98
- type: 13,
99
- value: ' ',
100
- },
101
- {
102
- offset: 2,
103
- type: 1,
104
- value: ',cde',
105
- },
106
- {
107
- offset: 6,
108
- type: 13,
109
- value: ' ',
110
- },
111
- {
112
- offset: 7,
113
- type: 1,
114
- value: ',',
115
- },
116
- {
117
- offset: 8,
118
- type: 13,
119
- value: ' ',
120
- },
121
- {
122
- offset: 9,
123
- type: 1,
124
- value: 'f',
125
- },
126
- ]);
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
+ ]);
127
128
  });
128
129
  test('getConsecutiveToken', () => {
129
- var _a;
130
- expect(new token_collection_1.TokenCollection('a,b,c', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma)).toBeFalsy();
131
- expect(new token_collection_1.TokenCollection('a,,b', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma)).toBeTruthy();
132
- 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);
133
144
  });
134
145
  test('fromPatterns', () => {
135
- const patterns = [/\+|-/, /[0-9]{2}/, /:?/, /[0-9]{2}/];
136
- expect(token_collection_1.TokenCollection.fromPatterns('+00:00', patterns).map(t => t.value)).toStrictEqual(['+', '00', ':', '00']);
137
- expect(token_collection_1.TokenCollection.fromPatterns('+0000', patterns).map(t => t.value)).toStrictEqual(['+', '00', '', '00']);
138
- expect(token_collection_1.TokenCollection.fromPatterns('+00/00', patterns).map(t => t.value)).toStrictEqual([
139
- '+',
140
- '00',
141
- '',
142
- '',
143
- '/00',
144
- ]);
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
+ ]);
145
166
  });
@@ -1,56 +1,61 @@
1
1
  import type { TokenValue } from './types';
2
2
  import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
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[]): 18 | 1 | 13;
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
- match(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;
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;
56
61
  }
@@ -1,34 +1,36 @@
1
- "use strict";
1
+ 'use strict';
2
2
  // @ts-nocheck
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const check_serialized_permissions_policy_1 = require("./check-serialized-permissions-policy");
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+ const check_serialized_permissions_policy_1 = require('./check-serialized-permissions-policy');
5
5
  const check = (0, check_serialized_permissions_policy_1.checkSerializedPermissionsPolicy)();
6
6
  test('checkSerializedPermissionsPolicy', () => {
7
- expect(check('').reason).toBe('empty-token');
8
- expect(check(' ').reason).toBe('unexpected-token');
9
- // expect(check('a').reason).toBe('missing-token');
10
- expect(check('a').matched).toBe(true); // Current supported
11
- expect(check('a:').reason).toBe('unexpected-token');
12
- // expect(check('a ').reason).toBe('missing-token'); // Current supported
13
- expect(check('a ').matched).toBe(true);
14
- expect(check('a a').reason).toBe('unexpected-token');
15
- expect(check('a *').matched).toBe(true);
16
- expect(check('a *a').reason).toBe('unexpected-token');
17
- expect(check('a none').reason).toBe('missing-token');
18
- expect(check("a 'none'").matched).toBe(true);
19
- expect(check('a https://markuplint.dev').matched).toBe(true);
20
- expect(check('a https://markuplint.dev/path/to').reason).toBe('extra-token');
21
- expect(check('a https://マルチバイト.abc.xyz').reason).toBe('must-be-serialized');
22
- expect(check('a * https://markuplint.dev').matched).toBe(true);
23
- expect(check("a * https://markuplint.dev 'none'").matched).toBe(true);
24
- // expect(check("a * https://markuplint.dev 'none';b").reason).toBe('missing-token');
25
- expect(check("a * https://markuplint.dev 'none';b").matched).toBe(true); // Current supported
26
- // expect(check("a * https://markuplint.dev 'none';b ").reason).toBe('missing-token');
27
- expect(check("a * https://markuplint.dev 'none';b ").matched).toBe(true); // Current supported
28
- expect(check("a * https://markuplint.dev 'none';b *").matched).toBe(true);
29
- expect(check("a * https://markuplint.dev 'none';b *;c 'none'").matched).toBe(true);
30
- expect(check("a * https://markuplint.dev 'none'; b *; c 'none'").matched).toBe(true);
7
+ expect(check('').reason).toBe('empty-token');
8
+ expect(check(' ').reason).toBe('unexpected-token');
9
+ // expect(check('a').reason).toBe('missing-token');
10
+ expect(check('a').matched).toBe(true); // Current supported
11
+ expect(check('a:').reason).toBe('unexpected-token');
12
+ // expect(check('a ').reason).toBe('missing-token'); // Current supported
13
+ expect(check('a ').matched).toBe(true);
14
+ expect(check('a a').reason).toBe('unexpected-token');
15
+ expect(check('a *').matched).toBe(true);
16
+ expect(check('a *a').reason).toBe('unexpected-token');
17
+ expect(check('a none').reason).toBe('missing-token');
18
+ expect(check("a 'none'").matched).toBe(true);
19
+ expect(check('a https://markuplint.dev').matched).toBe(true);
20
+ expect(check('a https://markuplint.dev/path/to').reason).toBe('extra-token');
21
+ expect(check('a https://マルチバイト.abc.xyz').reason).toBe('must-be-serialized');
22
+ expect(check('a * https://markuplint.dev').matched).toBe(true);
23
+ expect(check("a * https://markuplint.dev 'none'").matched).toBe(true);
24
+ // expect(check("a * https://markuplint.dev 'none';b").reason).toBe('missing-token');
25
+ expect(check("a * https://markuplint.dev 'none';b").matched).toBe(true); // Current supported
26
+ // expect(check("a * https://markuplint.dev 'none';b ").reason).toBe('missing-token');
27
+ expect(check("a * https://markuplint.dev 'none';b ").matched).toBe(true); // Current supported
28
+ expect(check("a * https://markuplint.dev 'none';b *").matched).toBe(true);
29
+ expect(check("a * https://markuplint.dev 'none';b *;c 'none'").matched).toBe(true);
30
+ expect(check("a * https://markuplint.dev 'none'; b *; c 'none'").matched).toBe(true);
31
31
  });
32
32
  test('YouTube embed', () => {
33
- expect(check('accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture').matched).toBe(true);
33
+ expect(
34
+ check('accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture').matched,
35
+ ).toBe(true);
34
36
  });