@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.
- package/lib/check-multi-types.d.ts +4 -1
- package/lib/check.spec.js +61 -61
- package/lib/css-syntax.spec.js +151 -149
- package/lib/list.spec.js +117 -117
- package/lib/match-result.d.ts +21 -8
- package/lib/primitive/index.spec.js +52 -52
- package/lib/rfc/is-bcp-47.spec.js +8 -8
- package/lib/token/token-collection.d.ts +68 -55
- package/lib/token/token-collection.spec.js +155 -134
- package/lib/token/token.d.ts +57 -52
- package/lib/w3c/check-serialized-permissions-policy.spec.js +30 -28
- package/lib/whatwg/check-autocomplete.spec.js +360 -360
- package/lib/whatwg/check-datetime/index.spec.js +277 -276
- package/lib/whatwg/check-mime-type.spec.js +52 -52
- package/lib/whatwg/is-abs-url.spec.js +5 -5
- package/package.json +8 -10
- package/test/check.spec.js +89 -0
- package/test/css-syntax.spec.js +165 -0
- package/test/list.spec.js +133 -0
- package/test/primitive/index.spec.js +65 -0
- package/test/rfc/is-bcp-47.spec.js +23 -0
- package/test/token/token-collection.spec.js +146 -0
- package/test/w3c/check-serialized-permissions-policy.spec.js +36 -0
- package/test/whatwg/check-autocomplete.spec.js +387 -0
- package/test/whatwg/check-datetime/index.spec.js +336 -0
- package/test/whatwg/check-mime-type.spec.js +59 -0
- package/test/whatwg/is-abs-url.spec.js +8 -0
|
@@ -1,145 +1,166 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
// @ts-nocheck
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
const token_collection_1 = require(
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
});
|
package/lib/token/token.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
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
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
// @ts-nocheck
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
const check_serialized_permissions_policy_1 = require(
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
33
|
+
expect(
|
|
34
|
+
check('accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture').matched,
|
|
35
|
+
).toBe(true);
|
|
34
36
|
});
|