@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
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import type { FormattedPrimitiveTypeCreator } from '../types';
|
|
1
|
+
import type { FormattedPrimitiveTypeCreator } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* valid name of custom element
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* > PotentialCustomElementName ::=
|
|
6
|
+
* > [a-z] (PCENChar)* '-' (PCENChar)*
|
|
7
|
+
* > PCENChar ::=
|
|
8
|
+
* > "-" | "." | [0-9] | "_" | [a-z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] |
|
|
9
|
+
* > [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
|
10
|
+
* > This uses the EBNF notation from the XML specification. [XML]
|
|
11
|
+
*
|
|
12
|
+
* > They start with an ASCII lower alpha, ensuring that the HTML parser will treat them as tags instead of as text.
|
|
6
13
|
*
|
|
7
14
|
* > - name must match the [PotentialCustomElementName](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname) production
|
|
8
15
|
* > - name must not be any of the following:
|
|
@@ -15,8 +22,6 @@ import type { FormattedPrimitiveTypeCreator } from '../types';
|
|
|
15
22
|
* > - `<font-face-name>`
|
|
16
23
|
* > - `<missing-glyph>`
|
|
17
24
|
*
|
|
18
|
-
*
|
|
19
|
-
* Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
|
|
20
|
-
*
|
|
25
|
+
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
21
26
|
*/
|
|
22
27
|
export declare const isCustomElementName: FormattedPrimitiveTypeCreator;
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCustomElementName = void 0;
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
2
|
+
* PCENChar
|
|
6
3
|
*
|
|
4
|
+
* > PCENChar ::=
|
|
5
|
+
* > "-" | "." | [0-9] | "_" | [a-z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] |
|
|
6
|
+
* > [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
|
7
7
|
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname
|
|
8
8
|
*
|
|
9
|
+
*/
|
|
10
|
+
const onlyPCENChar =
|
|
11
|
+
// eslint-disable-next-line no-misleading-character-class
|
|
12
|
+
/^[-.\d_a-z\u00B7\u00C0-\u00D6[\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C\u200D\u203F\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*$/u;
|
|
13
|
+
/**
|
|
14
|
+
* valid name of custom element
|
|
15
|
+
*
|
|
9
16
|
* > PotentialCustomElementName ::=
|
|
10
17
|
* > [a-z] (PCENChar)* '-' (PCENChar)*
|
|
11
18
|
* > PCENChar ::=
|
|
@@ -13,34 +20,7 @@ exports.isCustomElementName = void 0;
|
|
|
13
20
|
* > [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
|
14
21
|
* > This uses the EBNF notation from the XML specification. [XML]
|
|
15
22
|
*
|
|
16
|
-
* ASCII
|
|
17
|
-
* Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
|
|
18
|
-
*/
|
|
19
|
-
const rePCENChar = [
|
|
20
|
-
'\\-',
|
|
21
|
-
'\\.',
|
|
22
|
-
'[0-9]',
|
|
23
|
-
'_',
|
|
24
|
-
'[a-z]',
|
|
25
|
-
'\u00B7',
|
|
26
|
-
'[\u00C0-\u00D6]',
|
|
27
|
-
'[\u00D8-\u00F6]',
|
|
28
|
-
'[\u00F8-\u037D]',
|
|
29
|
-
'[\u037F-\u1FFF]',
|
|
30
|
-
'[\u200C-\u200D]',
|
|
31
|
-
'[\u203F-\u2040]',
|
|
32
|
-
'[\u2070-\u218F]',
|
|
33
|
-
'[\u2C00-\u2FEF]',
|
|
34
|
-
'[\u3001-\uD7FF]',
|
|
35
|
-
'[\uF900-\uFDCF]',
|
|
36
|
-
'[\uFDF0-\uFFFD]',
|
|
37
|
-
'[\uD800-\uDBFF][\uDC00-\uDFFF]',
|
|
38
|
-
].join('|');
|
|
39
|
-
const rePCEN = new RegExp(`^[a-z](?:${rePCENChar})*\\-(?:${rePCENChar})*$`, 'i');
|
|
40
|
-
/**
|
|
41
|
-
* valid name of custom element
|
|
42
|
-
*
|
|
43
|
-
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
23
|
+
* > They start with an ASCII lower alpha, ensuring that the HTML parser will treat them as tags instead of as text.
|
|
44
24
|
*
|
|
45
25
|
* > - name must match the [PotentialCustomElementName](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname) production
|
|
46
26
|
* > - name must not be any of the following:
|
|
@@ -53,11 +33,9 @@ const rePCEN = new RegExp(`^[a-z](?:${rePCENChar})*\\-(?:${rePCENChar})*$`, 'i')
|
|
|
53
33
|
* > - `<font-face-name>`
|
|
54
34
|
* > - `<missing-glyph>`
|
|
55
35
|
*
|
|
56
|
-
*
|
|
57
|
-
* Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
|
|
58
|
-
*
|
|
36
|
+
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
59
37
|
*/
|
|
60
|
-
const isCustomElementName = () => {
|
|
38
|
+
export const isCustomElementName = () => {
|
|
61
39
|
return tagName => {
|
|
62
40
|
switch (tagName) {
|
|
63
41
|
case 'annotation-xml':
|
|
@@ -71,7 +49,13 @@ const isCustomElementName = () => {
|
|
|
71
49
|
return false;
|
|
72
50
|
}
|
|
73
51
|
}
|
|
74
|
-
|
|
52
|
+
// First char must be ASCII lowercase alpha.
|
|
53
|
+
if (!/^[a-z]/.test(tagName)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (!tagName.includes('-')) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return onlyPCENChar.test(tagName);
|
|
75
60
|
};
|
|
76
61
|
};
|
|
77
|
-
exports.isCustomElementName = isCustomElementName;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isItempropName = void 0;
|
|
4
1
|
/**
|
|
5
2
|
*
|
|
6
3
|
* @see https://html.spec.whatwg.org/multipage/microdata.html#defined-property-name
|
|
@@ -11,9 +8,8 @@ exports.isItempropName = void 0;
|
|
|
11
8
|
* > ASCII whitespace are disallowed because otherwise the values would be parsed as multiple tokens.
|
|
12
9
|
*
|
|
13
10
|
*/
|
|
14
|
-
const isItempropName = () => {
|
|
11
|
+
export const isItempropName = () => {
|
|
15
12
|
return value => {
|
|
16
13
|
return !value.includes(':') && !value.includes('.') && !value.includes(' ');
|
|
17
14
|
};
|
|
18
15
|
};
|
|
19
|
-
exports.isItempropName = isItempropName;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNavigableTargetName = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* @see https://infra.spec.whatwg.org/#ascii-tab-or-newline
|
|
6
3
|
*
|
|
@@ -16,9 +13,8 @@ const TAB_OR_NEWLINE = /[\t\n\r]/;
|
|
|
16
13
|
* > (Names starting with a U+005F (_) are reserved for special keywords.)
|
|
17
14
|
*
|
|
18
15
|
*/
|
|
19
|
-
const isNavigableTargetName = () => {
|
|
16
|
+
export const isNavigableTargetName = () => {
|
|
20
17
|
return value => {
|
|
21
18
|
return !!value && !TAB_OR_NEWLINE.test(value) && value[0] !== '_';
|
|
22
19
|
};
|
|
23
20
|
};
|
|
24
|
-
exports.isNavigableTargetName = isNavigableTargetName;
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.10",
|
|
4
4
|
"description": "Type declaration and value checker",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"private": false,
|
|
9
|
-
"
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./lib/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
10
15
|
"types": "lib/index.d.ts",
|
|
11
16
|
"publishConfig": {
|
|
12
17
|
"access": "public"
|
|
@@ -17,19 +22,22 @@
|
|
|
17
22
|
"scripts": {
|
|
18
23
|
"build": "tsc",
|
|
19
24
|
"clean": "tsc --build --clean",
|
|
20
|
-
"schema": "
|
|
25
|
+
"schema": "run-s schema:types schema:schema build schema:prettier schema:eslint schema:prettier",
|
|
26
|
+
"schema:types": "node --loader ts-node/esm \"./gen/types.ts\"",
|
|
27
|
+
"schema:schema": "json2ts \"./types.schema.json\" > \"./src/types.schema.ts\"",
|
|
28
|
+
"schema:eslint": "eslint --fix \"./src/types.schema.ts\"",
|
|
29
|
+
"schema:prettier": "prettier --write \"./src/types.schema.ts\" \"./types.schema.json\" --log-level warn"
|
|
21
30
|
},
|
|
22
31
|
"dependencies": {
|
|
23
|
-
"@types/bcp-47": "1",
|
|
24
32
|
"@types/css-tree": "^2.3.4",
|
|
25
33
|
"@types/debug": "^4.1.12",
|
|
26
34
|
"@types/whatwg-mimetype": "3.0.2",
|
|
27
|
-
"bcp-47": "1",
|
|
35
|
+
"bcp-47": "^2.1.0",
|
|
28
36
|
"css-tree": "^2.3.1",
|
|
29
37
|
"debug": "^4.3.4",
|
|
30
|
-
"leven": "
|
|
31
|
-
"type-fest": "^4.
|
|
32
|
-
"whatwg-mimetype": "^
|
|
38
|
+
"leven": "^4.0.0",
|
|
39
|
+
"type-fest": "^4.10.1",
|
|
40
|
+
"whatwg-mimetype": "^4.0.0"
|
|
33
41
|
},
|
|
34
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "b41153ea665aa8f091daf6114a06047f4ccb8350"
|
|
35
43
|
}
|
package/test/check.spec.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
const { check } = require('../lib/check');
|
|
2
|
-
|
|
3
|
-
test('Any', () => {
|
|
4
|
-
expect(check('', 'Any').matched).toBe(true);
|
|
5
|
-
expect(check(' ', 'Any').matched).toBe(true);
|
|
6
|
-
expect(check('a', 'Any').matched).toBe(true);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test('NoEmptyAny', () => {
|
|
10
|
-
expect(check('', 'NoEmptyAny').matched).toBe(false);
|
|
11
|
-
expect(check(' ', 'NoEmptyAny').matched).toBe(true);
|
|
12
|
-
expect(check('a', 'NoEmptyAny').matched).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('OneLineAny', () => {
|
|
16
|
-
expect(check('', 'OneLineAny').matched).toBe(true);
|
|
17
|
-
expect(check(' ', 'OneLineAny').matched).toBe(true);
|
|
18
|
-
expect(check('a', 'OneLineAny').matched).toBe(true);
|
|
19
|
-
expect(check('a ', 'OneLineAny').matched).toBe(true);
|
|
20
|
-
expect(check('a b', 'OneLineAny').matched).toBe(true);
|
|
21
|
-
expect(check('a\n', 'OneLineAny').matched).toBe(false);
|
|
22
|
-
expect(check('a\nb', 'OneLineAny').matched).toBe(false);
|
|
23
|
-
expect(check('a\r\nb', 'OneLineAny').matched).toBe(false);
|
|
24
|
-
expect(check('a\rb', 'OneLineAny').matched).toBe(false);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('Pattern', () => {
|
|
28
|
-
expect(check('.*', 'Pattern').matched).toBe(true);
|
|
29
|
-
expect(check('[a-z]+', 'Pattern').matched).toBe(true);
|
|
30
|
-
expect(check(']//[()?!+*', 'Pattern').matched).toBe(false);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('BCP47', () => {
|
|
34
|
-
expect(check('en', 'BCP47').matched).toBe(true);
|
|
35
|
-
expect(check('en-US', 'BCP47').matched).toBe(true);
|
|
36
|
-
expect(check('ja', 'BCP47').matched).toBe(true);
|
|
37
|
-
expect(check(' ja ', 'BCP47').matched).toBe(false);
|
|
38
|
-
expect(check('', 'BCP47').matched).toBe(false);
|
|
39
|
-
expect(check('zh/cn', 'BCP47').matched).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('Srcset', () => {
|
|
43
|
-
expect(check('a/bb/ccc/dddd', 'Srcset').matched).toBe(true);
|
|
44
|
-
expect(check('a/bb/ccc/dddd 200w', 'Srcset').matched).toBe(true);
|
|
45
|
-
expect(check('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5x', 'Srcset').matched).toBe(true);
|
|
46
|
-
expect(check('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5a', 'Srcset').matched).toBe(false);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('IconSize', () => {
|
|
50
|
-
expect(check('any', 'IconSize').matched).toBe(true);
|
|
51
|
-
expect(check('Any', 'IconSize').matched).toBe(true);
|
|
52
|
-
expect(check('10x10', 'IconSize').matched).toBe(true);
|
|
53
|
-
expect(check('1x1', 'IconSize').matched).toBe(true);
|
|
54
|
-
expect(check('1x0', 'IconSize').matched).toBe(false);
|
|
55
|
-
expect(check('0x1', 'IconSize').matched).toBe(false);
|
|
56
|
-
expect(check('0x0', 'IconSize').matched).toBe(false);
|
|
57
|
-
expect(check('', 'IconSize').matched).toBe(false);
|
|
58
|
-
expect(check(' ', 'IconSize').matched).toBe(false);
|
|
59
|
-
expect(check('1', 'IconSize').matched).toBe(false);
|
|
60
|
-
expect(check('1x', 'IconSize').matched).toBe(false);
|
|
61
|
-
expect(check('x1', 'IconSize').matched).toBe(false);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('Number', () => {
|
|
65
|
-
expect(check('10', { type: 'integer', gt: 0 }).matched).toBe(true);
|
|
66
|
-
expect(check('0', { type: 'integer', gt: 0 }).matched).toBe(false);
|
|
67
|
-
expect(check('0', { type: 'integer', gte: 0 }).matched).toBe(true);
|
|
68
|
-
expect(check('9', { type: 'integer', lt: 10 }).matched).toBe(true);
|
|
69
|
-
expect(check('10', { type: 'integer', lt: 10 }).matched).toBe(false);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('Non-exist types', () => {
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
expect(check('abc', 'String').matched).toBe(true);
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
expect(check('abc', 'FooBar').matched).toBe(true);
|
|
77
|
-
// @ts-ignore
|
|
78
|
-
expect(check('abc', ' ').matched).toBe(true);
|
|
79
|
-
// @ts-ignore
|
|
80
|
-
expect(check('abc', '\n').matched).toBe(true);
|
|
81
|
-
// @ts-ignore
|
|
82
|
-
expect(check('abc', '').matched).toBe(true);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('ItemProp', () => {
|
|
86
|
-
expect(check('itemListElement', 'ItemProp').matched).toBe(true);
|
|
87
|
-
expect(check('item', 'ItemProp').matched).toBe(true);
|
|
88
|
-
expect(check('position', 'ItemProp').matched).toBe(true);
|
|
89
|
-
});
|
package/test/css-syntax.spec.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
const { cssSyntaxMatch } = require('../lib/css-syntax');
|
|
2
|
-
|
|
3
|
-
test('CSS Standard', () => {
|
|
4
|
-
expect(cssSyntaxMatch('10px', '<length>').matched).toBe(true);
|
|
5
|
-
expect(cssSyntaxMatch('one-pixel', '<length>').matched).toBe(false);
|
|
6
|
-
expect(cssSyntaxMatch('(prefers-color-scheme: dark)', '<media-query-list>').matched).toBe(true);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test('Extends', () => {
|
|
10
|
-
const sourceSizeList = {
|
|
11
|
-
ref: 'https://html.spec.whatwg.org/multipage/images.html#sizes-attributes',
|
|
12
|
-
syntax: {
|
|
13
|
-
apply: '<source-size-list>',
|
|
14
|
-
def: {
|
|
15
|
-
'source-size-list': '[ <source-size># , ]? <source-size-value>',
|
|
16
|
-
'source-size': '<media-condition> <source-size-value> | auto',
|
|
17
|
-
'source-size-value': '<length> | auto',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
expect(cssSyntaxMatch('50vw', sourceSizeList).matched).toBe(true);
|
|
22
|
-
expect(cssSyntaxMatch('(max-width: 600px) 200px, 50vw', sourceSizeList).matched).toBe(true);
|
|
23
|
-
expect(cssSyntaxMatch('print 300vw', sourceSizeList).matched).toBe(false);
|
|
24
|
-
expect(cssSyntaxMatch('(max-width: 600px) 200px', sourceSizeList).matched).toBe(false);
|
|
25
|
-
expect(cssSyntaxMatch('100vw', sourceSizeList).matched).toBe(true);
|
|
26
|
-
expect(cssSyntaxMatch('auto', sourceSizeList).matched).toBe(true);
|
|
27
|
-
expect(cssSyntaxMatch('auto, auto', sourceSizeList).matched).toBe(true);
|
|
28
|
-
expect(cssSyntaxMatch('auto, 100vw', sourceSizeList).matched).toBe(true);
|
|
29
|
-
expect(cssSyntaxMatch('auto, 100%', sourceSizeList).matched).toBe(false);
|
|
30
|
-
expect(
|
|
31
|
-
cssSyntaxMatch('(max-width: 600px) 200px', {
|
|
32
|
-
...sourceSizeList,
|
|
33
|
-
syntax: {
|
|
34
|
-
...sourceSizeList.syntax,
|
|
35
|
-
apply: '<source-size>',
|
|
36
|
-
},
|
|
37
|
-
}).matched,
|
|
38
|
-
).toBe(true);
|
|
39
|
-
|
|
40
|
-
const keyTimes = {
|
|
41
|
-
ref: 'https://svgwg.org/specs/animations/#KeyTimesAttribute',
|
|
42
|
-
syntax: {
|
|
43
|
-
apply: '<key-times>',
|
|
44
|
-
def: {
|
|
45
|
-
'key-times': '<number> [; <number>]* [;]?',
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
expect(cssSyntaxMatch('20; 20; 30', keyTimes).matched).toBe(true);
|
|
50
|
-
expect(cssSyntaxMatch('20; 20; 30;', keyTimes).matched).toBe(true);
|
|
51
|
-
expect(cssSyntaxMatch('20; 20; abc;', keyTimes).matched).toBe(false);
|
|
52
|
-
expect(cssSyntaxMatch('20; 20; ;', keyTimes).matched).toBe(false);
|
|
53
|
-
|
|
54
|
-
const SVGViewBox = {
|
|
55
|
-
ref: 'https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute',
|
|
56
|
-
syntax: {
|
|
57
|
-
apply: '<view-box>',
|
|
58
|
-
def: {
|
|
59
|
-
'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>',
|
|
60
|
-
'min-x': '<number>',
|
|
61
|
-
'min-y': '<number>',
|
|
62
|
-
width: '<number>',
|
|
63
|
-
height: '<number>',
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
expect(cssSyntaxMatch('0 0 30 10', SVGViewBox).matched).toBe(true);
|
|
68
|
-
expect(cssSyntaxMatch('0 0, 30, 10', SVGViewBox).matched).toBe(true);
|
|
69
|
-
expect(cssSyntaxMatch('0 0, 30', SVGViewBox).matched).toBe(false);
|
|
70
|
-
|
|
71
|
-
const percentageList = {
|
|
72
|
-
ref: 'https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage',
|
|
73
|
-
syntax: {
|
|
74
|
-
apply: '<percentage-list>',
|
|
75
|
-
def: {
|
|
76
|
-
'percentage-list': '[ <number> [,]? ]* <number>',
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
expect(cssSyntaxMatch('0 0 30 10', percentageList).matched).toBe(true);
|
|
81
|
-
expect(cssSyntaxMatch('0, 0, 30 10', percentageList).matched).toBe(true);
|
|
82
|
-
expect(cssSyntaxMatch('0', percentageList).matched).toBe(true);
|
|
83
|
-
expect(cssSyntaxMatch('', percentageList).matched).toBe(false);
|
|
84
|
-
|
|
85
|
-
const custom = {
|
|
86
|
-
ref: 'n/a',
|
|
87
|
-
syntax: {
|
|
88
|
-
apply: '<custom>',
|
|
89
|
-
def: {
|
|
90
|
-
custom: '0 | 1 | .',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
expect(cssSyntaxMatch('0', custom).matched).toBe(true);
|
|
95
|
-
expect(cssSyntaxMatch('1', custom).matched).toBe(true);
|
|
96
|
-
expect(cssSyntaxMatch('.', custom).matched).toBe(true);
|
|
97
|
-
expect(cssSyntaxMatch('2', custom).matched).toBe(false);
|
|
98
|
-
expect(cssSyntaxMatch(':', custom).matched).toBe(false);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('custom-type-checking', () => {
|
|
102
|
-
const custom = {
|
|
103
|
-
ref: 'n/a',
|
|
104
|
-
caseSensitive: true,
|
|
105
|
-
syntax: {
|
|
106
|
-
apply: '<custom>',
|
|
107
|
-
def: {
|
|
108
|
-
custom: '<custom-type>',
|
|
109
|
-
'custom-type': token => {
|
|
110
|
-
if (!token) {
|
|
111
|
-
return 0;
|
|
112
|
-
}
|
|
113
|
-
return token.value === '1' ? 1 : 0;
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
expect(cssSyntaxMatch('1', custom).matched).toBe(true);
|
|
119
|
-
expect(cssSyntaxMatch('0', custom).matched).toBe(false);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('case-sensitive', () => {
|
|
123
|
-
const custom = {
|
|
124
|
-
ref: 'n/a',
|
|
125
|
-
caseSensitive: true,
|
|
126
|
-
syntax: {
|
|
127
|
-
apply: '<custom>',
|
|
128
|
-
def: {
|
|
129
|
-
custom: 'CaSeS [a | B | aBc]',
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
expect(cssSyntaxMatch('CaSeS a', custom).matched).toBe(true);
|
|
134
|
-
expect(cssSyntaxMatch('CaSeS B', custom).matched).toBe(true);
|
|
135
|
-
expect(cssSyntaxMatch('CaSeS aBc', custom).matched).toBe(true);
|
|
136
|
-
expect(cssSyntaxMatch('CaSeS A', custom)).toStrictEqual({
|
|
137
|
-
column: 7,
|
|
138
|
-
line: 1,
|
|
139
|
-
matched: false,
|
|
140
|
-
length: 1,
|
|
141
|
-
offset: 6,
|
|
142
|
-
partName: 'value',
|
|
143
|
-
raw: 'A',
|
|
144
|
-
reason: 'syntax-error',
|
|
145
|
-
ref: 'n/a',
|
|
146
|
-
expects: [
|
|
147
|
-
{
|
|
148
|
-
type: 'syntax',
|
|
149
|
-
value: '<custom>',
|
|
150
|
-
},
|
|
151
|
-
],
|
|
152
|
-
});
|
|
153
|
-
expect(cssSyntaxMatch('CaSeS abc', custom)).toStrictEqual({
|
|
154
|
-
column: 7,
|
|
155
|
-
line: 1,
|
|
156
|
-
matched: false,
|
|
157
|
-
length: 3,
|
|
158
|
-
offset: 6,
|
|
159
|
-
partName: 'value',
|
|
160
|
-
raw: 'abc',
|
|
161
|
-
reason: 'syntax-error',
|
|
162
|
-
ref: 'n/a',
|
|
163
|
-
expects: [
|
|
164
|
-
{
|
|
165
|
-
type: 'syntax',
|
|
166
|
-
value: '<custom>',
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
});
|
|
170
|
-
});
|
package/test/list.spec.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
const { checkList } = require('../lib/list');
|
|
2
|
-
|
|
3
|
-
test('Zero space', () => {
|
|
4
|
-
const type = { token: 'Zero', separator: 'space' };
|
|
5
|
-
expect(checkList('0', type).matched).toBe(true);
|
|
6
|
-
expect(checkList(' 0 ', type).matched).toBe(true);
|
|
7
|
-
expect(checkList(' 0 0', type).matched).toBe(true);
|
|
8
|
-
expect(checkList(' 0 0 ', type).matched).toBe(true);
|
|
9
|
-
expect(checkList('0 0 0 ', type).matched).toBe(true);
|
|
10
|
-
expect(checkList('0 0 0 0', type).matched).toBe(true);
|
|
11
|
-
expect(checkList('0 0 0 0', type).matched).toBe(true);
|
|
12
|
-
expect(checkList('1', type).matched).toBe(false);
|
|
13
|
-
expect(checkList(' 1 ', type).matched).toBe(false);
|
|
14
|
-
expect(checkList(' 1 0', type).matched).toBe(false);
|
|
15
|
-
expect(checkList(' 1 0 ', type).matched).toBe(false);
|
|
16
|
-
expect(checkList('0 1 0 ', type).matched).toBe(false);
|
|
17
|
-
expect(checkList('0 1 0 0', type).matched).toBe(false);
|
|
18
|
-
expect(checkList('0 1 0 0', type).matched).toBe(false);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('Zero comma', () => {
|
|
22
|
-
const type = { token: 'Zero', separator: 'comma' };
|
|
23
|
-
expect(checkList('0', type).matched).toBe(true);
|
|
24
|
-
expect(checkList(' 0 ', type).matched).toBe(true);
|
|
25
|
-
expect(checkList(' 0 0', type).matched).toBe(false);
|
|
26
|
-
expect(checkList(' 0,0', type).matched).toBe(true);
|
|
27
|
-
expect(checkList(' 0,,0 ', type).matched).toBe(false);
|
|
28
|
-
expect(checkList('0 0 0 ', type).matched).toBe(false);
|
|
29
|
-
expect(checkList(' 0,0,0,0 ', type).matched).toBe(true);
|
|
30
|
-
expect(checkList('0, 0, 0 , 0', type).matched).toBe(true);
|
|
31
|
-
expect(checkList('0,0,0,0,', type).matched).toBe(false);
|
|
32
|
-
expect(checkList(',0,0,0,0', type).matched).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('Zero comma (disallowToSurroundBySpaces)', () => {
|
|
36
|
-
const type = { token: 'Zero', separator: 'comma', disallowToSurroundBySpaces: true };
|
|
37
|
-
expect(checkList('0', type).matched).toBe(true);
|
|
38
|
-
expect(checkList(' 0 ', type).matched).toBe(false);
|
|
39
|
-
expect(checkList(' 0 0', type).matched).toBe(false);
|
|
40
|
-
expect(checkList(' 0,0', type).matched).toBe(false);
|
|
41
|
-
expect(checkList(' 0,,0 ', type).matched).toBe(false);
|
|
42
|
-
expect(checkList('0 0 0 ', type).matched).toBe(false);
|
|
43
|
-
expect(checkList(' 0,0,0,0 ', type).matched).toBe(false);
|
|
44
|
-
expect(checkList('0, 0, 0 , 0', type).matched).toBe(false);
|
|
45
|
-
expect(checkList('0,0,0,0', type).matched).toBe(true);
|
|
46
|
-
expect(checkList('0,0,0,0,', type).matched).toBe(false);
|
|
47
|
-
expect(checkList(',0,0,0,0', type).matched).toBe(false);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('Location of the token', () => {
|
|
51
|
-
const type = { token: 'Accept', separator: 'comma' };
|
|
52
|
-
expect(checkList('x/y;a=b', type)).toStrictEqual({
|
|
53
|
-
candidate: 'x/y',
|
|
54
|
-
column: 4,
|
|
55
|
-
expects: [{ type: 'format', value: 'MIME Type with no parameters' }],
|
|
56
|
-
length: 4,
|
|
57
|
-
line: 1,
|
|
58
|
-
matched: false,
|
|
59
|
-
offset: 3,
|
|
60
|
-
raw: ';a=b',
|
|
61
|
-
reason: 'extra-token',
|
|
62
|
-
partName: 'the content of the list',
|
|
63
|
-
ref: 'https://html.spec.whatwg.org/multipage/input.html#attr-input-accept',
|
|
64
|
-
});
|
|
65
|
-
expect(checkList('x/y,x/y;a=b', type)).toStrictEqual({
|
|
66
|
-
candidate: 'x/y',
|
|
67
|
-
column: 8,
|
|
68
|
-
expects: [{ type: 'format', value: 'MIME Type with no parameters' }],
|
|
69
|
-
length: 4,
|
|
70
|
-
line: 1,
|
|
71
|
-
matched: false,
|
|
72
|
-
offset: 7,
|
|
73
|
-
raw: ';a=b',
|
|
74
|
-
reason: 'extra-token',
|
|
75
|
-
partName: 'the content of the list',
|
|
76
|
-
ref: 'https://html.spec.whatwg.org/multipage/input.html#attr-input-accept',
|
|
77
|
-
});
|
|
78
|
-
expect(checkList('x/y\n,\nx/y;a=b', type)).toStrictEqual({
|
|
79
|
-
candidate: 'x/y',
|
|
80
|
-
column: 4,
|
|
81
|
-
expects: [{ type: 'format', value: 'MIME Type with no parameters' }],
|
|
82
|
-
length: 4,
|
|
83
|
-
line: 3,
|
|
84
|
-
matched: false,
|
|
85
|
-
offset: 9,
|
|
86
|
-
raw: ';a=b',
|
|
87
|
-
reason: 'extra-token',
|
|
88
|
-
partName: 'the content of the list',
|
|
89
|
-
ref: 'https://html.spec.whatwg.org/multipage/input.html#attr-input-accept',
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('Expected comma', () => {
|
|
94
|
-
const type = { token: 'Accept', separator: 'comma' };
|
|
95
|
-
expect(checkList('x/y,', type)).toStrictEqual({
|
|
96
|
-
column: 4,
|
|
97
|
-
expects: undefined,
|
|
98
|
-
length: 1,
|
|
99
|
-
line: 1,
|
|
100
|
-
matched: false,
|
|
101
|
-
offset: 3,
|
|
102
|
-
raw: ',',
|
|
103
|
-
reason: 'extra-token',
|
|
104
|
-
ref: null,
|
|
105
|
-
});
|
|
106
|
-
expect(checkList('x/y,,x/y', type)).toStrictEqual({
|
|
107
|
-
column: 5,
|
|
108
|
-
expects: undefined,
|
|
109
|
-
length: 1,
|
|
110
|
-
line: 1,
|
|
111
|
-
matched: false,
|
|
112
|
-
offset: 4,
|
|
113
|
-
raw: ',',
|
|
114
|
-
reason: 'unexpected-comma',
|
|
115
|
-
ref: null,
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('Missing comma', () => {
|
|
120
|
-
const type = { token: 'Accept', separator: 'comma' };
|
|
121
|
-
expect(checkList('a/b,x/y a/z', type)).toStrictEqual({
|
|
122
|
-
column: 9,
|
|
123
|
-
candidate: ',a/z',
|
|
124
|
-
expects: undefined,
|
|
125
|
-
length: 3,
|
|
126
|
-
line: 1,
|
|
127
|
-
matched: false,
|
|
128
|
-
offset: 8,
|
|
129
|
-
raw: 'a/z',
|
|
130
|
-
reason: 'missing-comma',
|
|
131
|
-
ref: null,
|
|
132
|
-
});
|
|
133
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
const { isInt, isUint, isFloat, isNonZeroUint, isQuantity } = require('../../lib/primitive');
|
|
2
|
-
|
|
3
|
-
test('int', () => {
|
|
4
|
-
expect(isInt('0')).toBe(true);
|
|
5
|
-
expect(isInt('1')).toBe(true);
|
|
6
|
-
expect(isInt('-0')).toBe(true);
|
|
7
|
-
expect(isInt('-1')).toBe(true);
|
|
8
|
-
expect(isInt('10')).toBe(true);
|
|
9
|
-
expect(isInt('100')).toBe(true);
|
|
10
|
-
expect(isInt('1.00')).toBe(false);
|
|
11
|
-
expect(isInt('.001')).toBe(false);
|
|
12
|
-
expect(isInt(' 1 ')).toBe(false);
|
|
13
|
-
expect(isInt('- 1')).toBe(false);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('uint', () => {
|
|
17
|
-
expect(isUint('0')).toBe(true);
|
|
18
|
-
expect(isUint('1')).toBe(true);
|
|
19
|
-
expect(isUint('10')).toBe(true);
|
|
20
|
-
expect(isUint('100')).toBe(true);
|
|
21
|
-
expect(isUint('-0')).toBe(false);
|
|
22
|
-
expect(isUint('-1')).toBe(false);
|
|
23
|
-
expect(isUint('1.00')).toBe(false);
|
|
24
|
-
expect(isUint('.001')).toBe(false);
|
|
25
|
-
expect(isUint(' 1 ')).toBe(false);
|
|
26
|
-
expect(isUint('- 1')).toBe(false);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('float', () => {
|
|
30
|
-
expect(isFloat('0')).toBe(true);
|
|
31
|
-
expect(isFloat('1')).toBe(true);
|
|
32
|
-
expect(isFloat('10')).toBe(true);
|
|
33
|
-
expect(isFloat('100')).toBe(true);
|
|
34
|
-
expect(isFloat('-0')).toBe(true);
|
|
35
|
-
expect(isFloat('-1')).toBe(true);
|
|
36
|
-
expect(isFloat('1.00')).toBe(true);
|
|
37
|
-
expect(isFloat('.001')).toBe(true);
|
|
38
|
-
expect(isFloat(' 1 ')).toBe(false);
|
|
39
|
-
expect(isFloat('- 1')).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('nonZeroUint', () => {
|
|
43
|
-
expect(isNonZeroUint('0')).toBe(false);
|
|
44
|
-
expect(isNonZeroUint('1')).toBe(true);
|
|
45
|
-
expect(isNonZeroUint('10')).toBe(true);
|
|
46
|
-
expect(isNonZeroUint('100')).toBe(true);
|
|
47
|
-
expect(isNonZeroUint('-0')).toBe(false);
|
|
48
|
-
expect(isNonZeroUint('-1')).toBe(false);
|
|
49
|
-
expect(isNonZeroUint('1.00')).toBe(false);
|
|
50
|
-
expect(isNonZeroUint('.001')).toBe(false);
|
|
51
|
-
expect(isNonZeroUint(' 1 ')).toBe(false);
|
|
52
|
-
expect(isNonZeroUint('- 1')).toBe(false);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('quantity', () => {
|
|
56
|
-
expect(isQuantity('0px', ['px', 'em'])).toBe(true);
|
|
57
|
-
expect(isQuantity('.5px', ['px', 'em'])).toBe(true);
|
|
58
|
-
expect(isQuantity('1.5em', ['px', 'em'])).toBe(true);
|
|
59
|
-
expect(isQuantity('1.5cm', ['px', 'em'])).toBe(false);
|
|
60
|
-
expect(isQuantity('1.5px', ['px', 'em'], 'int')).toBe(false);
|
|
61
|
-
expect(isQuantity('-5px', ['px', 'em'], 'int')).toBe(true);
|
|
62
|
-
expect(isQuantity('-5px', ['px', 'em'], 'uint')).toBe(false);
|
|
63
|
-
expect(isQuantity('1.12e+21px', ['px', 'em'], 'float')).toBe(true);
|
|
64
|
-
expect(isQuantity('1.12e+21px', ['px', 'em'], 'int')).toBe(false);
|
|
65
|
-
});
|