@markuplint/types 3.0.0-dev.25 → 3.0.0-dev.38
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/package.json +2 -2
- package/gen/specific-schema.json +0 -98
- package/gen/types.ts +0 -66
- 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/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
|
-
}
|