@markuplint/types 3.8.0 → 4.0.0-alpha.1
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 +2 -2
- 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 +18 -23
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +1 -1
- package/lib/defs.js +82 -85
- package/lib/enum.d.ts +2 -2
- package/lib/enum.js +6 -11
- 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 -22
- package/lib/list.d.ts +2 -2
- package/lib/list.js +9 -14
- package/lib/match-result.d.ts +1 -1
- package/lib/match-result.js +6 -13
- package/lib/number.d.ts +2 -2
- 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.js +9 -13
- 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 +4 -5
- package/lib/token/token-collection.js +35 -43
- package/lib/token/token.d.ts +2 -2
- package/lib/token/token.js +6 -13
- package/lib/token/types.js +1 -2
- package/lib/types.d.ts +2 -2
- package/lib/types.js +1 -2
- 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 +16 -20
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +24 -28
- 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 +40 -46
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +38 -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 +20 -25
- 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 -22
- 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 +11 -17
- 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 +1 -1
- package/lib/whatwg/is-browser-context-name.js +1 -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 +1 -5
- package/package.json +13 -8
- 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
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CustomSyntaxCheck, UnmatchedResult } from './types';
|
|
2
|
-
export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): import("./types").MatchedResult | UnmatchedResult;
|
|
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 } 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,13 +21,13 @@ 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
33
|
Object.keys(types).forEach(key => {
|
|
@@ -53,36 +49,36 @@ function cssSyntaxMatch(value, type) {
|
|
|
53
49
|
ref = type.ref;
|
|
54
50
|
}
|
|
55
51
|
// @ts-ignore
|
|
56
|
-
const lexer =
|
|
52
|
+
const lexer = fork({
|
|
57
53
|
types: typesExtended,
|
|
58
54
|
properties: propsExtended,
|
|
59
55
|
}).lexer;
|
|
60
56
|
Object.keys(typesCheckers).forEach(key => {
|
|
61
57
|
const checker = typesCheckers[key];
|
|
62
58
|
// @ts-ignore
|
|
63
|
-
lexer.addType_(key, (token, getNextToken) => checker
|
|
59
|
+
lexer.addType_(key, (token, getNextToken) => checker?.(token, getNextToken, cssSyntaxMatch));
|
|
64
60
|
});
|
|
65
61
|
const { isProp, name } = detectName(defName);
|
|
66
62
|
// @ts-ignore
|
|
67
63
|
const matcher = isProp ? lexer.properties[name] : lexer.types[name];
|
|
68
64
|
if (!matcher) {
|
|
69
|
-
|
|
65
|
+
log('"%s" CSS syntax not found', defName);
|
|
70
66
|
throw new Error('MARKUPLINT_TYPE_NO_EXIST');
|
|
71
67
|
}
|
|
72
68
|
const refParam = isProp ? 'Property' : 'Type';
|
|
73
|
-
ref = ref
|
|
69
|
+
ref = ref ?? `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
|
|
74
70
|
// eslint-disable-next-line no-console
|
|
75
71
|
const _w = console.warn;
|
|
76
|
-
if (
|
|
72
|
+
if (log.enabled) {
|
|
77
73
|
// eslint-disable-next-line no-console
|
|
78
|
-
console.warn = warn =>
|
|
74
|
+
console.warn = warn => log('WARNING: %s (by %s => %s)', warn, value, type);
|
|
79
75
|
}
|
|
80
76
|
const result = lexer.match(defName, value);
|
|
81
|
-
|
|
77
|
+
log('css-tree/result: %O', result);
|
|
82
78
|
// eslint-disable-next-line no-console
|
|
83
79
|
console.warn = _w;
|
|
84
80
|
if (!result.error) {
|
|
85
|
-
return
|
|
81
|
+
return matched();
|
|
86
82
|
}
|
|
87
83
|
if (!('css' in result.error)) {
|
|
88
84
|
throw result.error;
|
|
@@ -99,7 +95,7 @@ function cssSyntaxMatch(value, type) {
|
|
|
99
95
|
const mismatchLength = error.mismatchLength - MIMIC_LENGTH;
|
|
100
96
|
error.mismatchLength = mismatchLength < 0 ? error.mismatchLength : mismatchLength;
|
|
101
97
|
}
|
|
102
|
-
|
|
98
|
+
log('css-tree/SyntaxMatchError: %O', error);
|
|
103
99
|
return {
|
|
104
100
|
matched: false,
|
|
105
101
|
ref,
|
|
@@ -118,7 +114,6 @@ function cssSyntaxMatch(value, type) {
|
|
|
118
114
|
reason: 'syntax-error',
|
|
119
115
|
};
|
|
120
116
|
}
|
|
121
|
-
exports.cssSyntaxMatch = cssSyntaxMatch;
|
|
122
117
|
function detectName(def) {
|
|
123
118
|
const isProp = def.search("<'") === 0;
|
|
124
119
|
const name = def.replace(/^<'?|'?>$/g, '');
|
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