@markuplint/types 3.0.0-dev.25 → 3.0.0-dev.300
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 +63 -61
- package/lib/check-multi-types.d.ts +2 -2
- package/lib/check-multi-types.js +9 -13
- package/lib/check.d.ts +7 -6
- package/lib/check.js +20 -30
- package/lib/css-syntax.d.ts +1 -1
- package/lib/css-syntax.js +60 -63
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +1 -1
- package/lib/defs.js +163 -91
- package/lib/enum.d.ts +4 -3
- package/lib/enum.js +7 -12
- package/lib/get-candidate.d.ts +1 -1
- package/lib/get-candidate.js +3 -8
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -6
- package/lib/keyword-type.d.ts +2 -2
- package/lib/keyword-type.js +17 -21
- package/lib/list.d.ts +4 -3
- package/lib/list.js +9 -13
- package/lib/match-result.d.ts +4 -4
- package/lib/match-result.js +6 -12
- package/lib/number.d.ts +3 -3
- package/lib/number.js +11 -15
- package/lib/primitive/index.d.ts +7 -7
- package/lib/primitive/index.js +7 -17
- package/lib/primitive/is-float.js +1 -5
- package/lib/primitive/is-int.js +1 -5
- package/lib/primitive/is-non-zero-uint.js +1 -5
- package/lib/primitive/is-quantity.d.ts +1 -1
- package/lib/primitive/is-quantity.js +9 -13
- package/lib/primitive/is-uint.d.ts +1 -1
- package/lib/primitive/is-uint.js +1 -5
- package/lib/primitive/range.js +1 -5
- package/lib/primitive/split-unit.js +3 -7
- package/lib/rfc/is-bcp-47.d.ts +1 -1
- package/lib/rfc/is-bcp-47.js +3 -7
- package/lib/token/index.d.ts +2 -2
- package/lib/token/index.js +2 -7
- package/lib/token/token-collection.d.ts +13 -13
- package/lib/token/token-collection.js +55 -50
- package/lib/token/token.d.ts +11 -10
- package/lib/token/token.js +16 -24
- package/lib/token/types.d.ts +3 -0
- package/lib/types.d.ts +47 -46
- package/lib/types.js +1 -2
- package/lib/types.schema.d.ts +2 -2
- package/lib/types.schema.js +1 -3
- package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
- package/lib/w3c/check-serialized-permissions-policy.js +16 -20
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +28 -32
- package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/date-string.js +9 -13
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -1
- package/lib/whatwg/check-datetime/datetime-tokens.js +43 -46
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +48 -44
- package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/global-date-and-time-string.js +17 -21
- package/lib/whatwg/check-datetime/index.d.ts +1 -1
- package/lib/whatwg/check-datetime/index.js +25 -29
- package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +25 -26
- package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/month-string.js +9 -13
- package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/time-string.js +9 -13
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +16 -21
- package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/week-string.js +9 -13
- package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/year-string.js +9 -13
- package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/yearless-date-string.js +9 -13
- package/lib/whatwg/check-mime-type.d.ts +1 -1
- package/lib/whatwg/check-mime-type.js +12 -18
- package/lib/whatwg/is-abs-url.d.ts +1 -1
- package/lib/whatwg/is-abs-url.js +1 -5
- package/lib/whatwg/is-browser-context-name.d.ts +3 -1
- package/lib/whatwg/is-browser-context-name.js +3 -5
- package/lib/whatwg/is-custom-element-name.d.ts +1 -1
- package/lib/whatwg/is-custom-element-name.js +1 -5
- package/lib/whatwg/is-itemprop-name.d.ts +1 -1
- package/lib/whatwg/is-itemprop-name.js +2 -6
- package/lib/whatwg/is-navigable-target-name.d.ts +11 -0
- package/lib/whatwg/is-navigable-target-name.js +20 -0
- package/package.json +19 -14
- package/types.schema.json +314 -311
- package/gen/specific-schema.json +0 -98
- package/gen/types.ts +0 -66
- package/lib/check.spec.js +0 -76
- package/lib/css-syntax.spec.d.ts +0 -1
- package/lib/css-syntax.spec.js +0 -157
- package/lib/list.spec.d.ts +0 -1
- package/lib/list.spec.js +0 -129
- package/lib/primitive/index.spec.d.ts +0 -1
- package/lib/primitive/index.spec.js +0 -62
- package/lib/rfc/is-bcp-47.spec.d.ts +0 -1
- package/lib/rfc/is-bcp-47.spec.js +0 -19
- package/lib/token/token-collection.spec.d.ts +0 -1
- package/lib/token/token-collection.spec.js +0 -144
- package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +0 -1
- package/lib/w3c/check-serialized-permissions-policy.spec.js +0 -34
- package/lib/whatwg/check-autocomplete.spec.d.ts +0 -1
- package/lib/whatwg/check-autocomplete.spec.js +0 -379
- package/lib/whatwg/check-datetime/index.spec.d.ts +0 -1
- package/lib/whatwg/check-datetime/index.spec.js +0 -318
- package/lib/whatwg/check-mime-type.spec.d.ts +0 -1
- package/lib/whatwg/check-mime-type.spec.js +0 -58
- package/lib/whatwg/is-abs-url.spec.d.ts +0 -1
- package/lib/whatwg/is-abs-url.spec.js +0 -8
- package/patches/css-tree+2.3.1.patch +0 -23
- package/src/check-multi-types.ts +0 -35
- package/src/check.spec.ts +0 -83
- package/src/check.ts +0 -48
- package/src/css-syntax.spec.ts +0 -167
- 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.spec.ts +0 -133
- package/src/list.ts +0 -34
- package/src/match-result.ts +0 -49
- package/src/number.ts +0 -46
- package/src/primitive/index.spec.ts +0 -65
- 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.spec.ts +0 -23
- package/src/rfc/is-bcp-47.ts +0 -13
- package/src/token/index.ts +0 -2
- package/src/token/token-collection.spec.ts +0 -147
- package/src/token/token-collection.ts +0 -444
- package/src/token/token.ts +0 -144
- package/src/types.schema.ts +0 -1113
- package/src/types.ts +0 -118
- package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
- package/src/w3c/check-serialized-permissions-policy.ts +0 -303
- package/src/whatwg/check-autocomplete.spec.ts +0 -387
- 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.spec.ts +0 -333
- 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.spec.ts +0 -59
- package/src/whatwg/check-mime-type.ts +0 -46
- package/src/whatwg/is-abs-url.spec.ts +0 -8
- 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
- /package/lib/{check.spec.d.ts → token/types.js} +0 -0
package/src/token/token.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
|
|
2
|
-
|
|
3
|
-
export 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
|
-
/**
|
|
12
|
-
* ASCII whitespace is
|
|
13
|
-
* - U+0009 TAB
|
|
14
|
-
* - U+000A LF
|
|
15
|
-
* - U+000C FF
|
|
16
|
-
* - U+000D CR
|
|
17
|
-
* - U+0020 SPACE.
|
|
18
|
-
*
|
|
19
|
-
* @see https://infra.spec.whatwg.org/#ascii-whitespace
|
|
20
|
-
*/
|
|
21
|
-
static readonly whitespace: ReadonlyArray<string> = ['\u0009', '\u000A', '\u000C', '\u000D', '\u0020'];
|
|
22
|
-
|
|
23
|
-
static getCol(value: string, offset: number) {
|
|
24
|
-
const lines = value.slice(0, offset).split(/\n/g);
|
|
25
|
-
return lines[lines.length - 1].length + 1;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static getLine(value: string, offset: number) {
|
|
29
|
-
return value.slice(0, offset).split(/\n/g).length;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
static getType(value: string, separators?: string[]) {
|
|
33
|
-
if (Token.whitespace.includes(value[0])) {
|
|
34
|
-
return Token.WhiteSpace;
|
|
35
|
-
}
|
|
36
|
-
if (separators?.includes(value[0])) {
|
|
37
|
-
switch (value[0]) {
|
|
38
|
-
case ',':
|
|
39
|
-
return Token.Comma;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return Token.Ident;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static shiftLocation(token: Token, offset: number) {
|
|
46
|
-
const shifted = token.offset + offset;
|
|
47
|
-
return {
|
|
48
|
-
offset: shifted,
|
|
49
|
-
line: Token.getLine(token.#originalValue, shifted),
|
|
50
|
-
column: Token.getCol(token.#originalValue, shifted),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
readonly offset: number;
|
|
55
|
-
#originalValue: string;
|
|
56
|
-
readonly type: number;
|
|
57
|
-
readonly value: string;
|
|
58
|
-
|
|
59
|
-
constructor(value: string, offset: number, originalValue: string, separators?: string[]) {
|
|
60
|
-
this.type = Token.getType(value, separators);
|
|
61
|
-
this.value = value;
|
|
62
|
-
this.offset = offset;
|
|
63
|
-
this.#originalValue = originalValue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
get length() {
|
|
67
|
-
return this.value.length;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get origin() {
|
|
71
|
-
return this.#originalValue;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
* @param value The token value or the token type or its list
|
|
77
|
-
*/
|
|
78
|
-
includes(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean {
|
|
79
|
-
if (Array.isArray(value)) {
|
|
80
|
-
return value.some(v => this.includes(v));
|
|
81
|
-
}
|
|
82
|
-
if (typeof value === 'string') {
|
|
83
|
-
const a = caseInsensitive ? this.value.toLowerCase() : this.value;
|
|
84
|
-
const b = caseInsensitive ? value.toLowerCase() : value;
|
|
85
|
-
return a.indexOf(b) !== -1;
|
|
86
|
-
}
|
|
87
|
-
if (value instanceof RegExp) {
|
|
88
|
-
const pattern = new RegExp(value, caseInsensitive ? 'i' : '');
|
|
89
|
-
return pattern.test(this.value);
|
|
90
|
-
}
|
|
91
|
-
return this.type === value;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
*
|
|
96
|
-
* @param value The token value or the token type or its list
|
|
97
|
-
*/
|
|
98
|
-
match(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean {
|
|
99
|
-
if (Array.isArray(value)) {
|
|
100
|
-
return value.some(v => this.match(v));
|
|
101
|
-
}
|
|
102
|
-
if (typeof value === 'string') {
|
|
103
|
-
const a = caseInsensitive ? this.value.toLowerCase() : this.value;
|
|
104
|
-
const b = caseInsensitive ? value.toLowerCase() : value;
|
|
105
|
-
return a === b;
|
|
106
|
-
}
|
|
107
|
-
if (value instanceof RegExp) {
|
|
108
|
-
const pattern = new RegExp(value, caseInsensitive ? 'i' : '');
|
|
109
|
-
return pattern.test(this.value);
|
|
110
|
-
}
|
|
111
|
-
return this.type === value;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
toJSON() {
|
|
115
|
-
return {
|
|
116
|
-
type: this.type,
|
|
117
|
-
value: this.value,
|
|
118
|
-
offset: this.offset,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
toNumber() {
|
|
123
|
-
return parseFloat(this.value);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
unmatched(
|
|
127
|
-
options?: UnmatchedResultOptions & {
|
|
128
|
-
ref?: string;
|
|
129
|
-
reason?: UnmatchedResultReason;
|
|
130
|
-
},
|
|
131
|
-
): UnmatchedResult {
|
|
132
|
-
return {
|
|
133
|
-
...options,
|
|
134
|
-
matched: false,
|
|
135
|
-
ref: options?.ref || null,
|
|
136
|
-
raw: this.value,
|
|
137
|
-
offset: this.offset,
|
|
138
|
-
length: this.value.length,
|
|
139
|
-
line: Token.getLine(this.#originalValue, this.offset),
|
|
140
|
-
column: Token.getCol(this.#originalValue, this.offset),
|
|
141
|
-
reason: options?.reason ?? 'syntax-error',
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|