@markuplint/types 3.12.0 → 4.0.0-alpha.10
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/LICENSE +1 -1
- package/lib/check-multi-types.d.ts +2 -5
- package/lib/check-multi-types.js +9 -14
- package/lib/check.d.ts +1 -1
- package/lib/check.js +20 -30
- package/lib/css-syntax.d.ts +1 -1
- package/lib/css-syntax.js +33 -33
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +2 -1
- package/lib/defs.js +188 -138
- package/lib/enum.d.ts +2 -2
- package/lib/enum.js +7 -12
- package/lib/get-candidate.d.ts +1 -4
- package/lib/get-candidate.js +5 -10
- 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 +20 -25
- package/lib/list.d.ts +2 -2
- package/lib/list.js +9 -14
- package/lib/match-result.d.ts +8 -21
- package/lib/match-result.js +6 -13
- package/lib/number.d.ts +3 -3
- package/lib/number.js +13 -17
- package/lib/primitive/index.d.ts +7 -7
- package/lib/primitive/index.js +7 -17
- package/lib/primitive/is-float.js +2 -6
- package/lib/primitive/is-int.js +2 -6
- package/lib/primitive/is-non-zero-uint.js +2 -6
- package/lib/primitive/is-quantity.d.ts +1 -5
- package/lib/primitive/is-quantity.js +9 -13
- package/lib/primitive/is-uint.d.ts +3 -6
- package/lib/primitive/is-uint.js +4 -8
- package/lib/primitive/range.js +3 -7
- package/lib/primitive/split-unit.d.ts +2 -2
- package/lib/primitive/split-unit.js +4 -8
- 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 +58 -70
- package/lib/token/token-collection.js +47 -56
- package/lib/token/token.d.ts +54 -59
- package/lib/token/token.js +14 -20
- package/lib/token/types.js +1 -2
- package/lib/types.d.ts +58 -82
- package/lib/types.js +1 -2
- package/lib/types.schema.d.ts +31 -1087
- package/lib/types.schema.js +1 -2
- package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
- package/lib/w3c/check-serialized-permissions-policy.js +21 -25
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +34 -41
- package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/date-string.js +12 -16
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +2 -22
- package/lib/whatwg/check-datetime/datetime-tokens.js +58 -64
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +64 -69
- 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 +24 -28
- 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 +37 -41
- 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 +13 -17
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +22 -28
- package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/week-string.js +11 -15
- 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 +11 -15
- package/lib/whatwg/check-mime-type.d.ts +5 -5
- package/lib/whatwg/check-mime-type.js +11 -17
- package/lib/whatwg/is-abs-url.d.ts +1 -1
- package/lib/whatwg/is-abs-url.js +8 -12
- package/lib/whatwg/is-browser-context-name.d.ts +1 -1
- package/lib/whatwg/is-browser-context-name.js +1 -5
- package/lib/whatwg/is-custom-element-name.d.ts +10 -5
- package/lib/whatwg/is-custom-element-name.js +22 -38
- package/lib/whatwg/is-itemprop-name.d.ts +1 -1
- package/lib/whatwg/is-itemprop-name.js +1 -5
- package/lib/whatwg/is-navigable-target-name.d.ts +1 -1
- package/lib/whatwg/is-navigable-target-name.js +1 -5
- package/package.json +17 -9
- package/test/check.spec.js +0 -89
- package/test/css-syntax.spec.js +0 -170
- package/test/list.spec.js +0 -133
- package/test/primitive/index.spec.js +0 -65
- package/test/rfc/is-bcp-47.spec.js +0 -23
- package/test/token/token-collection.spec.js +0 -146
- package/test/w3c/check-serialized-permissions-policy.spec.js +0 -36
- package/test/whatwg/check-autocomplete.spec.js +0 -387
- package/test/whatwg/check-datetime/index.spec.js +0 -336
- package/test/whatwg/check-mime-type.spec.js +0 -59
- package/test/whatwg/is-abs-url.spec.js +0 -8
package/LICENSE
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import type { CustomSyntaxCheck, UnmatchedResult } from './types';
|
|
2
|
-
export declare function checkMultiTypes(
|
|
3
|
-
value: string,
|
|
4
|
-
checks: readonly CustomSyntaxCheck[],
|
|
5
|
-
): UnmatchedResult | import('./types').MatchedResult;
|
|
1
|
+
import type { CustomSyntaxCheck, UnmatchedResult } from './types.js';
|
|
2
|
+
export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): import("./types.js").MatchedResult | UnmatchedResult;
|
package/lib/check-multi-types.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("./debug");
|
|
5
|
-
const match_result_1 = require("./match-result");
|
|
6
|
-
function checkMultiTypes(value, checks) {
|
|
7
|
-
var _a, _b, _c;
|
|
1
|
+
import { log } from './debug.js';
|
|
2
|
+
import { matched } from './match-result.js';
|
|
3
|
+
export function checkMultiTypes(value, checks) {
|
|
8
4
|
let unmatched;
|
|
9
5
|
for (const check of checks) {
|
|
10
6
|
const res = check(value);
|
|
@@ -14,17 +10,16 @@ function checkMultiTypes(value, checks) {
|
|
|
14
10
|
// @ts-ignore
|
|
15
11
|
res._fn = check.name;
|
|
16
12
|
// @ts-ignore
|
|
17
|
-
|
|
18
|
-
const passedA =
|
|
19
|
-
const passedB =
|
|
20
|
-
const offsetA =
|
|
13
|
+
log('%s(%d) vs %s(%d)', unmatched?._fn, unmatched?.passCount, res._fn, res.passCount);
|
|
14
|
+
const passedA = unmatched?.passCount ?? 0;
|
|
15
|
+
const passedB = res.passCount ?? 0;
|
|
16
|
+
const offsetA = unmatched?.offset ?? 0;
|
|
21
17
|
const offsetB = res.offset;
|
|
22
18
|
if (passedA < passedB || (passedA === passedB && offsetA <= offsetB)) {
|
|
23
19
|
unmatched = res;
|
|
24
20
|
}
|
|
25
21
|
}
|
|
26
|
-
const result = unmatched
|
|
27
|
-
|
|
22
|
+
const result = unmatched ?? matched();
|
|
23
|
+
log('%d checks result: %O', checks.length, result);
|
|
28
24
|
return result;
|
|
29
25
|
}
|
|
30
|
-
exports.checkMultiTypes = checkMultiTypes;
|
package/lib/check.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types';
|
|
1
|
+
import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types.js';
|
|
2
2
|
import type { ReadonlyDeep } from 'type-fest';
|
|
3
3
|
export declare function check(value: string, type: ReadonlyDeep<Type>, ref?: string, cache?: boolean): Result;
|
|
4
4
|
export declare function isKeyword(type: ReadonlyDeep<Type>): type is ReadonlyDeep<KeywordDefinedType>;
|
package/lib/check.js
CHANGED
|
@@ -1,49 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const list_1 = require("./list");
|
|
8
|
-
const number_1 = require("./number");
|
|
9
|
-
function check(value, type, ref, cache = true) {
|
|
1
|
+
import { log } from './debug.js';
|
|
2
|
+
import { checkEnum } from './enum.js';
|
|
3
|
+
import { checkKeywordType } from './keyword-type.js';
|
|
4
|
+
import { checkList } from './list.js';
|
|
5
|
+
import { checkNumber } from './number.js';
|
|
6
|
+
export function check(value, type, ref, cache = true) {
|
|
10
7
|
if (isKeyword(type)) {
|
|
11
|
-
|
|
12
|
-
return
|
|
8
|
+
log('Check keyword: %s', type);
|
|
9
|
+
return checkKeywordType(value, type, cache);
|
|
13
10
|
}
|
|
14
11
|
if (isList(type)) {
|
|
15
|
-
|
|
16
|
-
return
|
|
12
|
+
log('Check list: %O', type);
|
|
13
|
+
return checkList(value, type, ref, cache);
|
|
17
14
|
}
|
|
18
15
|
if (isEnum(type)) {
|
|
19
|
-
|
|
20
|
-
return
|
|
16
|
+
log('Check enum: %O', type);
|
|
17
|
+
return checkEnum(value, type, ref);
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
return
|
|
19
|
+
log('Check number: %O', type);
|
|
20
|
+
return checkNumber(value, type, ref);
|
|
24
21
|
}
|
|
25
|
-
|
|
26
|
-
function isKeyword(type) {
|
|
22
|
+
export function isKeyword(type) {
|
|
27
23
|
return typeof type === 'string';
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
function isList(type) {
|
|
25
|
+
export function isList(type) {
|
|
31
26
|
return typeof type !== 'string' && 'token' in type;
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
function isEnum(type) {
|
|
28
|
+
export function isEnum(type) {
|
|
35
29
|
return typeof type !== 'string' && 'enum' in type;
|
|
36
30
|
}
|
|
37
|
-
|
|
38
|
-
function isNumber(type) {
|
|
31
|
+
export function isNumber(type) {
|
|
39
32
|
return typeof type !== 'string' && 'enum' in type;
|
|
40
33
|
}
|
|
41
|
-
|
|
42
|
-
function isCSSSyntax(type) {
|
|
34
|
+
export function isCSSSyntax(type) {
|
|
43
35
|
return typeof type === 'string' || 'syntax' in type;
|
|
44
36
|
}
|
|
45
|
-
|
|
46
|
-
function isCustomSyntax(type) {
|
|
37
|
+
export function isCustomSyntax(type) {
|
|
47
38
|
return !isCSSSyntax(type);
|
|
48
39
|
}
|
|
49
|
-
exports.isCustomSyntax = isCustomSyntax;
|
package/lib/css-syntax.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CustomCssSyntax, Result, CssSyntax } from './types';
|
|
1
|
+
import type { CustomCssSyntax, Result, CssSyntax } from './types.js';
|
|
2
2
|
export declare function cssSyntaxMatch(value: string, type: CssSyntax | CustomCssSyntax): Result;
|
package/lib/css-syntax.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const debug_1 = require("./debug");
|
|
6
|
-
const defs_1 = require("./defs");
|
|
7
|
-
const match_result_1 = require("./match-result");
|
|
1
|
+
import { fork } from 'css-tree';
|
|
2
|
+
import { log } from './debug.js';
|
|
3
|
+
import { tokenizers, overrides } from './defs.js';
|
|
4
|
+
import { matched } from './match-result.js';
|
|
8
5
|
const MIMIC_TAG_L = 'mimiccases---';
|
|
9
6
|
const MIMIC_TAG_R = '---mimiccases';
|
|
10
7
|
const MIMIC_LENGTH = (MIMIC_TAG_L + MIMIC_TAG_R).length;
|
|
11
|
-
function cssSyntaxMatch(value, type) {
|
|
12
|
-
|
|
13
|
-
(0, debug_1.log)('Search CSS Syntax: "%s"', type);
|
|
8
|
+
export function cssSyntaxMatch(value, type) {
|
|
9
|
+
log('Search CSS Syntax: "%s"', type);
|
|
14
10
|
const origin = value;
|
|
15
11
|
let defName;
|
|
16
12
|
const typesExtended = {};
|
|
@@ -25,16 +21,16 @@ function cssSyntaxMatch(value, type) {
|
|
|
25
21
|
}
|
|
26
22
|
else {
|
|
27
23
|
defName = type.syntax.apply;
|
|
28
|
-
ebnf =
|
|
24
|
+
ebnf = type.syntax.ebnf ?? null;
|
|
29
25
|
if (ebnf) {
|
|
30
26
|
// Work in progress
|
|
31
|
-
return
|
|
27
|
+
return matched();
|
|
32
28
|
}
|
|
33
29
|
const types = {
|
|
34
|
-
...
|
|
30
|
+
...tokenizers,
|
|
35
31
|
...type.syntax.def,
|
|
36
32
|
};
|
|
37
|
-
Object.keys(types)
|
|
33
|
+
for (const key of Object.keys(types)) {
|
|
38
34
|
const valueOrChecker = types[key];
|
|
39
35
|
if (typeof valueOrChecker === 'string') {
|
|
40
36
|
typesExtended[key] = valueOrChecker;
|
|
@@ -42,47 +38,52 @@ function cssSyntaxMatch(value, type) {
|
|
|
42
38
|
else if (valueOrChecker) {
|
|
43
39
|
typesCheckers[key] = valueOrChecker;
|
|
44
40
|
}
|
|
45
|
-
}
|
|
41
|
+
}
|
|
46
42
|
propsExtended = { ...type.syntax.properties };
|
|
47
43
|
if (type.caseSensitive) {
|
|
48
44
|
caseSensitive = true;
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
for (const key of Object.keys(typesExtended))
|
|
46
|
+
eachMimicCases(key, typesExtended);
|
|
47
|
+
for (const key of Object.keys(propsExtended))
|
|
48
|
+
eachMimicCases(key, propsExtended);
|
|
51
49
|
value = mimicCases(value);
|
|
52
50
|
}
|
|
53
51
|
ref = type.ref;
|
|
54
52
|
}
|
|
55
53
|
// @ts-ignore
|
|
56
|
-
const lexer =
|
|
57
|
-
types:
|
|
54
|
+
const lexer = fork({
|
|
55
|
+
types: {
|
|
56
|
+
...overrides,
|
|
57
|
+
...typesExtended,
|
|
58
|
+
},
|
|
58
59
|
properties: propsExtended,
|
|
59
60
|
}).lexer;
|
|
60
|
-
Object.keys(typesCheckers)
|
|
61
|
+
for (const key of Object.keys(typesCheckers)) {
|
|
61
62
|
const checker = typesCheckers[key];
|
|
62
63
|
// @ts-ignore
|
|
63
|
-
lexer.addType_(key, (token, getNextToken) => checker
|
|
64
|
-
}
|
|
64
|
+
lexer.addType_(key, (token, getNextToken) => checker?.(token, getNextToken, cssSyntaxMatch));
|
|
65
|
+
}
|
|
65
66
|
const { isProp, name } = detectName(defName);
|
|
66
67
|
// @ts-ignore
|
|
67
68
|
const matcher = isProp ? lexer.properties[name] : lexer.types[name];
|
|
68
69
|
if (!matcher) {
|
|
69
|
-
|
|
70
|
+
log('"%s" CSS syntax not found', defName);
|
|
70
71
|
throw new Error('MARKUPLINT_TYPE_NO_EXIST');
|
|
71
72
|
}
|
|
72
73
|
const refParam = isProp ? 'Property' : 'Type';
|
|
73
|
-
ref = ref
|
|
74
|
+
ref = ref ?? `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
|
|
74
75
|
// eslint-disable-next-line no-console
|
|
75
76
|
const _w = console.warn;
|
|
76
|
-
if (
|
|
77
|
+
if (log.enabled) {
|
|
77
78
|
// eslint-disable-next-line no-console
|
|
78
|
-
console.warn = warn =>
|
|
79
|
+
console.warn = warn => log('WARNING: %s (by %s => %s)', warn, value, type);
|
|
79
80
|
}
|
|
80
81
|
const result = lexer.match(defName, value);
|
|
81
|
-
|
|
82
|
+
log('css-tree/result: %O', result);
|
|
82
83
|
// eslint-disable-next-line no-console
|
|
83
84
|
console.warn = _w;
|
|
84
85
|
if (!result.error) {
|
|
85
|
-
return
|
|
86
|
+
return matched();
|
|
86
87
|
}
|
|
87
88
|
if (!('css' in result.error)) {
|
|
88
89
|
throw result.error;
|
|
@@ -99,7 +100,7 @@ function cssSyntaxMatch(value, type) {
|
|
|
99
100
|
const mismatchLength = error.mismatchLength - MIMIC_LENGTH;
|
|
100
101
|
error.mismatchLength = mismatchLength < 0 ? error.mismatchLength : mismatchLength;
|
|
101
102
|
}
|
|
102
|
-
|
|
103
|
+
log('css-tree/SyntaxMatchError: %O', error);
|
|
103
104
|
return {
|
|
104
105
|
matched: false,
|
|
105
106
|
ref,
|
|
@@ -118,10 +119,9 @@ function cssSyntaxMatch(value, type) {
|
|
|
118
119
|
reason: 'syntax-error',
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
|
-
exports.cssSyntaxMatch = cssSyntaxMatch;
|
|
122
122
|
function detectName(def) {
|
|
123
123
|
const isProp = def.search("<'") === 0;
|
|
124
|
-
const name = def.
|
|
124
|
+
const name = def.replaceAll(/^<'?|'?>$/g, '');
|
|
125
125
|
return {
|
|
126
126
|
isProp,
|
|
127
127
|
name,
|
|
@@ -145,8 +145,8 @@ obj) {
|
|
|
145
145
|
obj[key] = mimicCases(value);
|
|
146
146
|
}
|
|
147
147
|
function mimicCases(value) {
|
|
148
|
-
return value.
|
|
148
|
+
return value.replaceAll(/[A-Z]/g, $0 => `${MIMIC_TAG_L}${$0}${MIMIC_TAG_R}`);
|
|
149
149
|
}
|
|
150
150
|
function deMimicCases(value) {
|
|
151
|
-
return value.
|
|
151
|
+
return value.replaceAll(new RegExp(`${MIMIC_TAG_L}([A-Z])${MIMIC_TAG_R}`, 'g'), (_, $1) => $1);
|
|
152
152
|
}
|
package/lib/debug.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.log = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
|
-
exports.log = (0, debug_1.default)('@markuplint/types');
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
export const log = debug('@markuplint/types');
|
package/lib/defs.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { Defs, CssSyntaxTokenizer } from './types';
|
|
1
|
+
import type { Defs, CssSyntaxTokenizer } from './types.js';
|
|
2
2
|
export declare const types: Defs;
|
|
3
|
+
export declare const overrides: Record<string, string>;
|
|
3
4
|
export declare const tokenizers: Record<string, CssSyntaxTokenizer>;
|