@markuplint/types 3.5.1 → 3.7.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 +1 -1
- package/lib/check.spec.js +61 -61
- package/lib/css-syntax.spec.js +151 -149
- package/lib/get-candidate.d.ts +1 -4
- package/lib/list.spec.js +117 -117
- package/lib/match-result.d.ts +1 -1
- package/lib/primitive/index.spec.js +52 -52
- package/lib/primitive/is-quantity.d.ts +1 -5
- package/lib/primitive/is-uint.d.ts +3 -6
- package/lib/primitive/split-unit.d.ts +2 -2
- package/lib/rfc/is-bcp-47.spec.js +8 -8
- package/lib/token/token-collection.d.ts +1 -1
- package/lib/token/token-collection.spec.js +155 -134
- package/lib/token/token.d.ts +1 -1
- package/lib/types.d.ts +55 -79
- package/lib/types.schema.d.ts +31 -1084
- package/lib/types.schema.js +0 -1
- 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/datetime-tokens.d.ts +1 -21
- package/lib/whatwg/check-datetime/index.spec.js +277 -276
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +1 -1
- package/lib/whatwg/check-mime-type.d.ts +4 -4
- 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
|
@@ -20,7 +20,7 @@ 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?: readonly string[]):
|
|
23
|
+
static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
|
|
24
24
|
static shiftLocation(token: Readonly<Token>, offset: number): {
|
|
25
25
|
offset: number;
|
|
26
26
|
line: number;
|
package/lib/types.d.ts
CHANGED
|
@@ -2,101 +2,77 @@ import type { cssSyntaxMatch } from './css-syntax';
|
|
|
2
2
|
export type { Type, List, Enum, CssSyntax, KeywordDefinedType, Number } from './types.schema';
|
|
3
3
|
export type Result = UnmatchedResult | MatchedResult;
|
|
4
4
|
export type UnmatchedResult = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
readonly matched: false;
|
|
6
|
+
readonly ref: string | null;
|
|
7
|
+
readonly raw: string;
|
|
8
|
+
readonly length: number;
|
|
9
|
+
readonly offset: number;
|
|
10
|
+
readonly line: number;
|
|
11
|
+
readonly column: number;
|
|
12
|
+
readonly reason: UnmatchedResultReason;
|
|
13
|
+
readonly passCount?: number;
|
|
14
14
|
} & UnmatchedResultOptions;
|
|
15
15
|
export type UnmatchedResultOptions = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
readonly partName?: string;
|
|
17
|
+
readonly expects?: readonly Expect[];
|
|
18
|
+
readonly extra?: Expect;
|
|
19
|
+
readonly candidate?: string;
|
|
20
|
+
};
|
|
21
|
+
export type UnmatchedResultReason = 'syntax-error' | 'typo' | 'missing-token' | 'missing-comma' | 'unexpected-token' | 'unexpected-space' | 'unexpected-newline' | 'unexpected-comma' | 'empty-token' | 'out-of-range' | 'doesnt-exist-in-enum' | 'duplicated' | 'illegal-combination' | 'illegal-order' | 'extra-token' | 'must-be-percent-encoded' | 'must-be-serialized' | {
|
|
22
|
+
readonly type: 'out-of-range';
|
|
23
|
+
readonly gt?: number;
|
|
24
|
+
readonly gte?: number;
|
|
25
|
+
readonly lt?: number;
|
|
26
|
+
readonly lte?: number;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: 'out-of-range-length-char';
|
|
29
|
+
readonly gte: number;
|
|
30
|
+
readonly lte?: number;
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: 'out-of-range-length-digit';
|
|
33
|
+
readonly gte: number;
|
|
34
|
+
readonly lte?: number;
|
|
20
35
|
};
|
|
21
|
-
export type UnmatchedResultReason =
|
|
22
|
-
| 'syntax-error'
|
|
23
|
-
| 'typo'
|
|
24
|
-
| 'missing-token'
|
|
25
|
-
| 'missing-comma'
|
|
26
|
-
| 'unexpected-token'
|
|
27
|
-
| 'unexpected-space'
|
|
28
|
-
| 'unexpected-newline'
|
|
29
|
-
| 'unexpected-comma'
|
|
30
|
-
| 'empty-token'
|
|
31
|
-
| 'out-of-range'
|
|
32
|
-
| 'doesnt-exist-in-enum'
|
|
33
|
-
| 'duplicated'
|
|
34
|
-
| 'illegal-combination'
|
|
35
|
-
| 'illegal-order'
|
|
36
|
-
| 'extra-token'
|
|
37
|
-
| 'must-be-percent-encoded'
|
|
38
|
-
| 'must-be-serialized'
|
|
39
|
-
| {
|
|
40
|
-
readonly type: 'out-of-range';
|
|
41
|
-
readonly gt?: number;
|
|
42
|
-
readonly gte?: number;
|
|
43
|
-
readonly lt?: number;
|
|
44
|
-
readonly lte?: number;
|
|
45
|
-
}
|
|
46
|
-
| {
|
|
47
|
-
readonly type: 'out-of-range-length-char';
|
|
48
|
-
readonly gte: number;
|
|
49
|
-
readonly lte?: number;
|
|
50
|
-
}
|
|
51
|
-
| {
|
|
52
|
-
readonly type: 'out-of-range-length-digit';
|
|
53
|
-
readonly gte: number;
|
|
54
|
-
readonly lte?: number;
|
|
55
|
-
};
|
|
56
36
|
export type MatchedResult = {
|
|
57
|
-
|
|
37
|
+
readonly matched: true;
|
|
58
38
|
};
|
|
59
39
|
export type Expect = {
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
readonly type: 'const' | 'format' | 'syntax' | 'regexp' | 'common';
|
|
41
|
+
readonly value: string;
|
|
62
42
|
};
|
|
63
43
|
export type FormattedPrimitiveTypeCheck = (value: string) => boolean;
|
|
64
44
|
export type FormattedPrimitiveTypeCreator<O = never> = (options?: O) => FormattedPrimitiveTypeCheck;
|
|
65
45
|
export type Defs = Record<string, CustomCssSyntax | CustomSyntax>;
|
|
66
46
|
export type CustomSyntax = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
readonly ref: string;
|
|
48
|
+
readonly expects?: readonly Expect[];
|
|
49
|
+
readonly is: CustomSyntaxCheck;
|
|
70
50
|
};
|
|
71
51
|
export type CustomSyntaxCheck = (value: string) => Result;
|
|
72
52
|
export type CustomSyntaxChecker<O = {}> = (options?: O) => CustomSyntaxCheck;
|
|
73
53
|
export type CustomCssSyntax = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
54
|
+
readonly ref: string;
|
|
55
|
+
readonly caseSensitive?: boolean;
|
|
56
|
+
readonly expects?: readonly Expect[];
|
|
57
|
+
readonly syntax: {
|
|
58
|
+
readonly apply: `<${string}>`;
|
|
59
|
+
readonly def: Readonly<Record<string, string | CssSyntaxTokenizer>>;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated
|
|
62
|
+
*/
|
|
63
|
+
readonly ebnf?: Readonly<Record<string, string | readonly string[]>>;
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated
|
|
66
|
+
*/
|
|
67
|
+
readonly properties?: Readonly<Record<string, string>>;
|
|
68
|
+
};
|
|
89
69
|
};
|
|
90
70
|
export type CSSSyntaxToken = {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
71
|
+
readonly type: number;
|
|
72
|
+
readonly value: string;
|
|
73
|
+
readonly index: number;
|
|
74
|
+
readonly balance: number;
|
|
75
|
+
readonly node?: any;
|
|
96
76
|
};
|
|
97
|
-
export type CssSyntaxTokenizer = (
|
|
98
|
-
token: Readonly<CSSSyntaxToken> | null,
|
|
99
|
-
getNextToken: GetNextToken,
|
|
100
|
-
match: typeof cssSyntaxMatch,
|
|
101
|
-
) => number;
|
|
77
|
+
export type CssSyntaxTokenizer = (token: Readonly<CSSSyntaxToken> | null, getNextToken: GetNextToken, match: typeof cssSyntaxMatch) => number;
|
|
102
78
|
export type GetNextToken = (length: number) => CSSSyntaxToken | null;
|