@markuplint/types 3.0.0-canary.5 → 3.0.0-dev.176
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 +1 -1
- package/lib/check-multi-types.d.ts +4 -1
- package/lib/check-multi-types.js +5 -4
- package/lib/check.d.ts +6 -5
- package/lib/check.spec.js +64 -58
- package/lib/css-syntax.js +49 -47
- package/lib/css-syntax.spec.js +152 -149
- package/lib/defs.js +2 -2
- package/lib/enum.d.ts +2 -1
- package/lib/enum.js +1 -1
- package/lib/get-candidate.d.ts +4 -1
- package/lib/keyword-type.js +3 -2
- package/lib/list.d.ts +2 -1
- package/lib/list.js +2 -1
- package/lib/list.spec.js +118 -117
- package/lib/match-result.d.ts +21 -8
- package/lib/match-result.js +2 -1
- package/lib/number.d.ts +1 -1
- package/lib/primitive/index.spec.js +53 -52
- package/lib/primitive/is-quantity.d.ts +5 -1
- package/lib/primitive/is-uint.d.ts +6 -3
- package/lib/primitive/split-unit.d.ts +2 -2
- package/lib/primitive/split-unit.js +2 -2
- package/lib/rfc/is-bcp-47.spec.js +9 -8
- package/lib/token/token-collection.d.ts +71 -56
- package/lib/token/token-collection.js +30 -23
- package/lib/token/token-collection.spec.js +156 -134
- package/lib/token/token.d.ts +58 -52
- package/lib/token/token.js +19 -20
- package/lib/token/types.d.ts +3 -0
- package/lib/token/types.js +2 -0
- package/lib/types.d.ts +79 -55
- package/lib/types.schema.d.ts +1084 -31
- package/lib/w3c/check-serialized-permissions-policy.spec.js +30 -28
- package/lib/whatwg/check-autocomplete.js +6 -6
- package/lib/whatwg/check-autocomplete.spec.js +361 -360
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +21 -1
- package/lib/whatwg/check-datetime/datetime-tokens.js +9 -6
- package/lib/whatwg/check-datetime/duration-string.js +12 -2
- package/lib/whatwg/check-datetime/index.spec.js +277 -276
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +6 -2
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +3 -2
- package/lib/whatwg/check-mime-type.d.ts +4 -4
- package/lib/whatwg/check-mime-type.js +1 -1
- package/lib/whatwg/check-mime-type.spec.js +53 -52
- package/lib/whatwg/is-abs-url.spec.js +6 -5
- package/lib/whatwg/is-itemprop-name.js +1 -1
- package/package.json +12 -10
- package/{src/check.spec.ts → test/check.spec.js} +7 -1
- package/{src/css-syntax.spec.ts → test/css-syntax.spec.js} +10 -12
- package/{src/list.spec.ts → test/list.spec.js} +7 -7
- package/{src/primitive/index.spec.ts → test/primitive/index.spec.js} +1 -1
- package/{src/rfc/is-bcp-47.spec.ts → test/rfc/is-bcp-47.spec.js} +1 -1
- package/{src/token/token-collection.spec.ts → test/token/token-collection.spec.js} +2 -3
- package/{src/w3c/check-serialized-permissions-policy.spec.ts → test/w3c/check-serialized-permissions-policy.spec.js} +1 -3
- package/{src/whatwg/check-autocomplete.spec.ts → test/whatwg/check-autocomplete.spec.js} +1 -1
- package/{src/whatwg/check-datetime/index.spec.ts → test/whatwg/check-datetime/index.spec.js} +18 -15
- package/{src/whatwg/check-mime-type.spec.ts → test/whatwg/check-mime-type.spec.js} +1 -1
- package/{src/whatwg/is-abs-url.spec.ts → test/whatwg/is-abs-url.spec.js} +1 -1
- package/types.schema.json +369 -318
- package/gen/specific-schema.json +0 -98
- package/gen/types.ts +0 -66
- package/src/check-multi-types.ts +0 -35
- package/src/check.ts +0 -48
- 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.ts +0 -34
- package/src/match-result.ts +0 -49
- package/src/number.ts +0 -46
- 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.ts +0 -13
- package/src/token/index.ts +0 -2
- package/src/token/token-collection.ts +0 -444
- package/src/token/token.ts +0 -144
- package/src/types.schema.ts +0 -1062
- package/src/types.ts +0 -118
- package/src/w3c/check-serialized-permissions-policy.ts +0 -303
- 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.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.ts +0 -46
- 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/token/token.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _Token_originalValue;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.Token = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
4
|
class Token {
|
|
7
5
|
static getCol(value, offset) {
|
|
6
|
+
var _a;
|
|
8
7
|
const lines = value.slice(0, offset).split(/\n/g);
|
|
9
|
-
return lines[lines.length - 1].length + 1;
|
|
8
|
+
return ((_a = lines[lines.length - 1]) !== null && _a !== void 0 ? _a : '').length + 1;
|
|
10
9
|
}
|
|
11
10
|
static getLine(value, offset) {
|
|
12
11
|
return value.slice(0, offset).split(/\n/g).length;
|
|
13
12
|
}
|
|
14
13
|
static getType(value, separators) {
|
|
15
|
-
|
|
14
|
+
var _a, _b;
|
|
15
|
+
if (Token.whitespace.includes((_a = value[0]) !== null && _a !== void 0 ? _a : '')) {
|
|
16
16
|
return Token.WhiteSpace;
|
|
17
17
|
}
|
|
18
|
-
if (separators === null || separators === void 0 ? void 0 : separators.includes(value[0])) {
|
|
18
|
+
if (separators === null || separators === void 0 ? void 0 : separators.includes((_b = value[0]) !== null && _b !== void 0 ? _b : '')) {
|
|
19
19
|
switch (value[0]) {
|
|
20
20
|
case ',':
|
|
21
21
|
return Token.Comma;
|
|
@@ -27,22 +27,21 @@ class Token {
|
|
|
27
27
|
const shifted = token.offset + offset;
|
|
28
28
|
return {
|
|
29
29
|
offset: shifted,
|
|
30
|
-
line: Token.getLine(
|
|
31
|
-
column: Token.getCol(
|
|
30
|
+
line: Token.getLine(token.originalValue, shifted),
|
|
31
|
+
column: Token.getCol(token.originalValue, shifted),
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
constructor(value, offset, originalValue, separators) {
|
|
35
|
-
_Token_originalValue.set(this, void 0);
|
|
36
35
|
this.type = Token.getType(value, separators);
|
|
37
36
|
this.value = value;
|
|
38
37
|
this.offset = offset;
|
|
39
|
-
|
|
38
|
+
this.originalValue = originalValue;
|
|
40
39
|
}
|
|
41
40
|
get length() {
|
|
42
41
|
return this.value.length;
|
|
43
42
|
}
|
|
44
|
-
|
|
45
|
-
return
|
|
43
|
+
clone() {
|
|
44
|
+
return new Token(this.value, this.offset, this.originalValue);
|
|
46
45
|
}
|
|
47
46
|
/**
|
|
48
47
|
*
|
|
@@ -55,7 +54,7 @@ class Token {
|
|
|
55
54
|
if (typeof value === 'string') {
|
|
56
55
|
const a = caseInsensitive ? this.value.toLowerCase() : this.value;
|
|
57
56
|
const b = caseInsensitive ? value.toLowerCase() : value;
|
|
58
|
-
return a.
|
|
57
|
+
return a.includes(b);
|
|
59
58
|
}
|
|
60
59
|
if (value instanceof RegExp) {
|
|
61
60
|
const pattern = new RegExp(value, caseInsensitive ? 'i' : '');
|
|
@@ -90,25 +89,24 @@ class Token {
|
|
|
90
89
|
};
|
|
91
90
|
}
|
|
92
91
|
toNumber() {
|
|
93
|
-
|
|
92
|
+
const num = parseFloat(this.value);
|
|
93
|
+
return isNaN(num) ? 0 : num;
|
|
94
94
|
}
|
|
95
95
|
unmatched(options) {
|
|
96
|
-
var _a;
|
|
96
|
+
var _a, _b;
|
|
97
97
|
return {
|
|
98
98
|
...options,
|
|
99
99
|
matched: false,
|
|
100
|
-
ref: (options === null || options === void 0 ? void 0 : options.ref)
|
|
100
|
+
ref: (_a = options === null || options === void 0 ? void 0 : options.ref) !== null && _a !== void 0 ? _a : null,
|
|
101
101
|
raw: this.value,
|
|
102
102
|
offset: this.offset,
|
|
103
103
|
length: this.value.length,
|
|
104
|
-
line: Token.getLine(
|
|
105
|
-
column: Token.getCol(
|
|
106
|
-
reason: (
|
|
104
|
+
line: Token.getLine(this.originalValue, this.offset),
|
|
105
|
+
column: Token.getCol(this.originalValue, this.offset),
|
|
106
|
+
reason: (_b = options === null || options === void 0 ? void 0 : options.reason) !== null && _b !== void 0 ? _b : 'syntax-error',
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
exports.Token = Token;
|
|
111
|
-
_Token_originalValue = new WeakMap();
|
|
112
110
|
/**
|
|
113
111
|
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
114
112
|
*/
|
|
@@ -126,3 +124,4 @@ Token.WhiteSpace = 13;
|
|
|
126
124
|
* @see https://infra.spec.whatwg.org/#ascii-whitespace
|
|
127
125
|
*/
|
|
128
126
|
Token.whitespace = ['\u0009', '\u000A', '\u000C', '\u000D', '\u0020'];
|
|
127
|
+
exports.Token = Token;
|
package/lib/types.d.ts
CHANGED
|
@@ -2,77 +2,101 @@ 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
|
-
|
|
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
|
-
type: 'out-of-range';
|
|
23
|
-
gt?: number;
|
|
24
|
-
gte?: number;
|
|
25
|
-
lt?: number;
|
|
26
|
-
lte?: number;
|
|
27
|
-
} | {
|
|
28
|
-
type: 'out-of-range-length-char';
|
|
29
|
-
gte: number;
|
|
30
|
-
lte?: number;
|
|
31
|
-
} | {
|
|
32
|
-
type: 'out-of-range-length-digit';
|
|
33
|
-
gte: number;
|
|
34
|
-
lte?: number;
|
|
16
|
+
readonly partName?: string;
|
|
17
|
+
readonly expects?: readonly Expect[];
|
|
18
|
+
readonly extra?: Expect;
|
|
19
|
+
readonly candidate?: string;
|
|
35
20
|
};
|
|
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
|
+
};
|
|
36
56
|
export type MatchedResult = {
|
|
37
|
-
|
|
57
|
+
readonly matched: true;
|
|
38
58
|
};
|
|
39
59
|
export type Expect = {
|
|
40
|
-
|
|
41
|
-
|
|
60
|
+
readonly type: 'const' | 'format' | 'syntax' | 'regexp' | 'common';
|
|
61
|
+
readonly value: string;
|
|
42
62
|
};
|
|
43
63
|
export type FormattedPrimitiveTypeCheck = (value: string) => boolean;
|
|
44
64
|
export type FormattedPrimitiveTypeCreator<O = never> = (options?: O) => FormattedPrimitiveTypeCheck;
|
|
45
65
|
export type Defs = Record<string, CustomCssSyntax | CustomSyntax>;
|
|
46
66
|
export type CustomSyntax = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
67
|
+
readonly ref: string;
|
|
68
|
+
readonly expects?: readonly Expect[];
|
|
69
|
+
readonly is: CustomSyntaxCheck;
|
|
50
70
|
};
|
|
51
71
|
export type CustomSyntaxCheck = (value: string) => Result;
|
|
52
72
|
export type CustomSyntaxChecker<O = {}> = (options?: O) => CustomSyntaxCheck;
|
|
53
73
|
export type CustomCssSyntax = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
readonly ref: string;
|
|
75
|
+
readonly caseSensitive?: boolean;
|
|
76
|
+
readonly expects?: readonly Expect[];
|
|
77
|
+
readonly syntax: {
|
|
78
|
+
readonly apply: `<${string}>`;
|
|
79
|
+
readonly def: Readonly<Record<string, string | CssSyntaxTokenizer>>;
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated
|
|
82
|
+
*/
|
|
83
|
+
readonly ebnf?: Readonly<Record<string, string | readonly string[]>>;
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated
|
|
86
|
+
*/
|
|
87
|
+
readonly properties?: Readonly<Record<string, string>>;
|
|
88
|
+
};
|
|
69
89
|
};
|
|
70
90
|
export type CSSSyntaxToken = {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
readonly type: number;
|
|
92
|
+
readonly value: string;
|
|
93
|
+
readonly index: number;
|
|
94
|
+
readonly balance: number;
|
|
95
|
+
readonly node?: any;
|
|
76
96
|
};
|
|
77
|
-
export type CssSyntaxTokenizer = (
|
|
97
|
+
export type CssSyntaxTokenizer = (
|
|
98
|
+
token: Readonly<CSSSyntaxToken> | null,
|
|
99
|
+
getNextToken: GetNextToken,
|
|
100
|
+
match: typeof cssSyntaxMatch,
|
|
101
|
+
) => number;
|
|
78
102
|
export type GetNextToken = (length: number) => CSSSyntaxToken | null;
|