@markuplint/types 3.5.1 → 3.7.0

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.
Files changed (37) hide show
  1. package/lib/check-multi-types.d.ts +1 -1
  2. package/lib/check.spec.js +61 -61
  3. package/lib/css-syntax.spec.js +151 -149
  4. package/lib/get-candidate.d.ts +1 -4
  5. package/lib/list.spec.js +117 -117
  6. package/lib/match-result.d.ts +1 -1
  7. package/lib/primitive/index.spec.js +52 -52
  8. package/lib/primitive/is-quantity.d.ts +1 -5
  9. package/lib/primitive/is-uint.d.ts +3 -6
  10. package/lib/primitive/split-unit.d.ts +2 -2
  11. package/lib/rfc/is-bcp-47.spec.js +8 -8
  12. package/lib/token/token-collection.d.ts +1 -1
  13. package/lib/token/token-collection.spec.js +155 -134
  14. package/lib/token/token.d.ts +1 -1
  15. package/lib/types.d.ts +55 -79
  16. package/lib/types.schema.d.ts +31 -1084
  17. package/lib/types.schema.js +0 -1
  18. package/lib/w3c/check-serialized-permissions-policy.spec.js +30 -28
  19. package/lib/whatwg/check-autocomplete.spec.js +360 -360
  20. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -21
  21. package/lib/whatwg/check-datetime/index.spec.js +277 -276
  22. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +1 -1
  23. package/lib/whatwg/check-mime-type.d.ts +4 -4
  24. package/lib/whatwg/check-mime-type.spec.js +52 -52
  25. package/lib/whatwg/is-abs-url.spec.js +5 -5
  26. package/package.json +8 -10
  27. package/test/check.spec.js +89 -0
  28. package/test/css-syntax.spec.js +165 -0
  29. package/test/list.spec.js +133 -0
  30. package/test/primitive/index.spec.js +65 -0
  31. package/test/rfc/is-bcp-47.spec.js +23 -0
  32. package/test/token/token-collection.spec.js +146 -0
  33. package/test/w3c/check-serialized-permissions-policy.spec.js +36 -0
  34. package/test/whatwg/check-autocomplete.spec.js +387 -0
  35. package/test/whatwg/check-datetime/index.spec.js +336 -0
  36. package/test/whatwg/check-mime-type.spec.js +59 -0
  37. package/test/whatwg/is-abs-url.spec.js +8 -0
@@ -1,2 +1,2 @@
1
1
  import type { CustomSyntaxCheck, UnmatchedResult } from './types';
2
- export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): UnmatchedResult | import("./types").MatchedResult;
2
+ export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): import("./types").MatchedResult | UnmatchedResult;
package/lib/check.spec.js CHANGED
@@ -1,82 +1,82 @@
1
- "use strict";
1
+ 'use strict';
2
2
  // @ts-nocheck
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const check_1 = require("./check");
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+ const check_1 = require('./check');
5
5
  test('Any', () => {
6
- expect((0, check_1.check)('', 'Any').matched).toBe(true);
7
- expect((0, check_1.check)(' ', 'Any').matched).toBe(true);
8
- expect((0, check_1.check)('a', 'Any').matched).toBe(true);
6
+ expect((0, check_1.check)('', 'Any').matched).toBe(true);
7
+ expect((0, check_1.check)(' ', 'Any').matched).toBe(true);
8
+ expect((0, check_1.check)('a', 'Any').matched).toBe(true);
9
9
  });
10
10
  test('NoEmptyAny', () => {
11
- expect((0, check_1.check)('', 'NoEmptyAny').matched).toBe(false);
12
- expect((0, check_1.check)(' ', 'NoEmptyAny').matched).toBe(true);
13
- expect((0, check_1.check)('a', 'NoEmptyAny').matched).toBe(true);
11
+ expect((0, check_1.check)('', 'NoEmptyAny').matched).toBe(false);
12
+ expect((0, check_1.check)(' ', 'NoEmptyAny').matched).toBe(true);
13
+ expect((0, check_1.check)('a', 'NoEmptyAny').matched).toBe(true);
14
14
  });
15
15
  test('OneLineAny', () => {
16
- expect((0, check_1.check)('', 'OneLineAny').matched).toBe(true);
17
- expect((0, check_1.check)(' ', 'OneLineAny').matched).toBe(true);
18
- expect((0, check_1.check)('a', 'OneLineAny').matched).toBe(true);
19
- expect((0, check_1.check)('a ', 'OneLineAny').matched).toBe(true);
20
- expect((0, check_1.check)('a b', 'OneLineAny').matched).toBe(true);
21
- expect((0, check_1.check)('a\n', 'OneLineAny').matched).toBe(false);
22
- expect((0, check_1.check)('a\nb', 'OneLineAny').matched).toBe(false);
23
- expect((0, check_1.check)('a\r\nb', 'OneLineAny').matched).toBe(false);
24
- expect((0, check_1.check)('a\rb', 'OneLineAny').matched).toBe(false);
16
+ expect((0, check_1.check)('', 'OneLineAny').matched).toBe(true);
17
+ expect((0, check_1.check)(' ', 'OneLineAny').matched).toBe(true);
18
+ expect((0, check_1.check)('a', 'OneLineAny').matched).toBe(true);
19
+ expect((0, check_1.check)('a ', 'OneLineAny').matched).toBe(true);
20
+ expect((0, check_1.check)('a b', 'OneLineAny').matched).toBe(true);
21
+ expect((0, check_1.check)('a\n', 'OneLineAny').matched).toBe(false);
22
+ expect((0, check_1.check)('a\nb', 'OneLineAny').matched).toBe(false);
23
+ expect((0, check_1.check)('a\r\nb', 'OneLineAny').matched).toBe(false);
24
+ expect((0, check_1.check)('a\rb', 'OneLineAny').matched).toBe(false);
25
25
  });
26
26
  test('Pattern', () => {
27
- expect((0, check_1.check)('.*', 'Pattern').matched).toBe(true);
28
- expect((0, check_1.check)('[a-z]+', 'Pattern').matched).toBe(true);
29
- expect((0, check_1.check)(']//[()?!+*', 'Pattern').matched).toBe(false);
27
+ expect((0, check_1.check)('.*', 'Pattern').matched).toBe(true);
28
+ expect((0, check_1.check)('[a-z]+', 'Pattern').matched).toBe(true);
29
+ expect((0, check_1.check)(']//[()?!+*', 'Pattern').matched).toBe(false);
30
30
  });
31
31
  test('BCP47', () => {
32
- expect((0, check_1.check)('en', 'BCP47').matched).toBe(true);
33
- expect((0, check_1.check)('en-US', 'BCP47').matched).toBe(true);
34
- expect((0, check_1.check)('ja', 'BCP47').matched).toBe(true);
35
- expect((0, check_1.check)(' ja ', 'BCP47').matched).toBe(false);
36
- expect((0, check_1.check)('', 'BCP47').matched).toBe(false);
37
- expect((0, check_1.check)('zh/cn', 'BCP47').matched).toBe(false);
32
+ expect((0, check_1.check)('en', 'BCP47').matched).toBe(true);
33
+ expect((0, check_1.check)('en-US', 'BCP47').matched).toBe(true);
34
+ expect((0, check_1.check)('ja', 'BCP47').matched).toBe(true);
35
+ expect((0, check_1.check)(' ja ', 'BCP47').matched).toBe(false);
36
+ expect((0, check_1.check)('', 'BCP47').matched).toBe(false);
37
+ expect((0, check_1.check)('zh/cn', 'BCP47').matched).toBe(false);
38
38
  });
39
39
  test('Srcset', () => {
40
- expect((0, check_1.check)('a/bb/ccc/dddd', 'Srcset').matched).toBe(true);
41
- expect((0, check_1.check)('a/bb/ccc/dddd 200w', 'Srcset').matched).toBe(true);
42
- expect((0, check_1.check)('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5x', 'Srcset').matched).toBe(true);
43
- expect((0, check_1.check)('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5a', 'Srcset').matched).toBe(false);
40
+ expect((0, check_1.check)('a/bb/ccc/dddd', 'Srcset').matched).toBe(true);
41
+ expect((0, check_1.check)('a/bb/ccc/dddd 200w', 'Srcset').matched).toBe(true);
42
+ expect((0, check_1.check)('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5x', 'Srcset').matched).toBe(true);
43
+ expect((0, check_1.check)('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5a', 'Srcset').matched).toBe(false);
44
44
  });
45
45
  test('IconSize', () => {
46
- expect((0, check_1.check)('any', 'IconSize').matched).toBe(true);
47
- expect((0, check_1.check)('Any', 'IconSize').matched).toBe(true);
48
- expect((0, check_1.check)('10x10', 'IconSize').matched).toBe(true);
49
- expect((0, check_1.check)('1x1', 'IconSize').matched).toBe(true);
50
- expect((0, check_1.check)('1x0', 'IconSize').matched).toBe(false);
51
- expect((0, check_1.check)('0x1', 'IconSize').matched).toBe(false);
52
- expect((0, check_1.check)('0x0', 'IconSize').matched).toBe(false);
53
- expect((0, check_1.check)('', 'IconSize').matched).toBe(false);
54
- expect((0, check_1.check)(' ', 'IconSize').matched).toBe(false);
55
- expect((0, check_1.check)('1', 'IconSize').matched).toBe(false);
56
- expect((0, check_1.check)('1x', 'IconSize').matched).toBe(false);
57
- expect((0, check_1.check)('x1', 'IconSize').matched).toBe(false);
46
+ expect((0, check_1.check)('any', 'IconSize').matched).toBe(true);
47
+ expect((0, check_1.check)('Any', 'IconSize').matched).toBe(true);
48
+ expect((0, check_1.check)('10x10', 'IconSize').matched).toBe(true);
49
+ expect((0, check_1.check)('1x1', 'IconSize').matched).toBe(true);
50
+ expect((0, check_1.check)('1x0', 'IconSize').matched).toBe(false);
51
+ expect((0, check_1.check)('0x1', 'IconSize').matched).toBe(false);
52
+ expect((0, check_1.check)('0x0', 'IconSize').matched).toBe(false);
53
+ expect((0, check_1.check)('', 'IconSize').matched).toBe(false);
54
+ expect((0, check_1.check)(' ', 'IconSize').matched).toBe(false);
55
+ expect((0, check_1.check)('1', 'IconSize').matched).toBe(false);
56
+ expect((0, check_1.check)('1x', 'IconSize').matched).toBe(false);
57
+ expect((0, check_1.check)('x1', 'IconSize').matched).toBe(false);
58
58
  });
59
59
  test('Number', () => {
60
- expect((0, check_1.check)('10', { type: 'integer', gt: 0 }).matched).toBe(true);
61
- expect((0, check_1.check)('0', { type: 'integer', gt: 0 }).matched).toBe(false);
62
- expect((0, check_1.check)('0', { type: 'integer', gte: 0 }).matched).toBe(true);
63
- expect((0, check_1.check)('9', { type: 'integer', lt: 10 }).matched).toBe(true);
64
- expect((0, check_1.check)('10', { type: 'integer', lt: 10 }).matched).toBe(false);
60
+ expect((0, check_1.check)('10', { type: 'integer', gt: 0 }).matched).toBe(true);
61
+ expect((0, check_1.check)('0', { type: 'integer', gt: 0 }).matched).toBe(false);
62
+ expect((0, check_1.check)('0', { type: 'integer', gte: 0 }).matched).toBe(true);
63
+ expect((0, check_1.check)('9', { type: 'integer', lt: 10 }).matched).toBe(true);
64
+ expect((0, check_1.check)('10', { type: 'integer', lt: 10 }).matched).toBe(false);
65
65
  });
66
66
  test('Non-exist types', () => {
67
- // @ts-ignore
68
- expect((0, check_1.check)('abc', 'String').matched).toBe(true);
69
- // @ts-ignore
70
- expect((0, check_1.check)('abc', 'FooBar').matched).toBe(true);
71
- // @ts-ignore
72
- expect((0, check_1.check)('abc', ' ').matched).toBe(true);
73
- // @ts-ignore
74
- expect((0, check_1.check)('abc', '\n').matched).toBe(true);
75
- // @ts-ignore
76
- expect((0, check_1.check)('abc', '').matched).toBe(true);
67
+ // @ts-ignore
68
+ expect((0, check_1.check)('abc', 'String').matched).toBe(true);
69
+ // @ts-ignore
70
+ expect((0, check_1.check)('abc', 'FooBar').matched).toBe(true);
71
+ // @ts-ignore
72
+ expect((0, check_1.check)('abc', ' ').matched).toBe(true);
73
+ // @ts-ignore
74
+ expect((0, check_1.check)('abc', '\n').matched).toBe(true);
75
+ // @ts-ignore
76
+ expect((0, check_1.check)('abc', '').matched).toBe(true);
77
77
  });
78
78
  test('ItemProp', () => {
79
- expect((0, check_1.check)('itemListElement', 'ItemProp').matched).toBe(true);
80
- expect((0, check_1.check)('item', 'ItemProp').matched).toBe(true);
81
- expect((0, check_1.check)('position', 'ItemProp').matched).toBe(true);
79
+ expect((0, check_1.check)('itemListElement', 'ItemProp').matched).toBe(true);
80
+ expect((0, check_1.check)('item', 'ItemProp').matched).toBe(true);
81
+ expect((0, check_1.check)('position', 'ItemProp').matched).toBe(true);
82
82
  });
@@ -1,158 +1,160 @@
1
- "use strict";
1
+ 'use strict';
2
2
  // @ts-nocheck
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const css_syntax_1 = require("./css-syntax");
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+ const css_syntax_1 = require('./css-syntax');
5
5
  test('CSS Standard', () => {
6
- expect((0, css_syntax_1.cssSyntaxMatch)('10px', '<length>').matched).toBe(true);
7
- expect((0, css_syntax_1.cssSyntaxMatch)('one-pixel', '<length>').matched).toBe(false);
8
- expect((0, css_syntax_1.cssSyntaxMatch)('(prefers-color-scheme: dark)', '<media-query-list>').matched).toBe(true);
6
+ expect((0, css_syntax_1.cssSyntaxMatch)('10px', '<length>').matched).toBe(true);
7
+ expect((0, css_syntax_1.cssSyntaxMatch)('one-pixel', '<length>').matched).toBe(false);
8
+ expect((0, css_syntax_1.cssSyntaxMatch)('(prefers-color-scheme: dark)', '<media-query-list>').matched).toBe(true);
9
9
  });
10
10
  test('Extends', () => {
11
- const sourceSizeList = {
12
- ref: 'https://html.spec.whatwg.org/multipage/images.html#sizes-attributes',
13
- syntax: {
14
- apply: '<source-size-list>',
15
- def: {
16
- 'source-size-list': '[ <source-size># , ]? <source-size-value>',
17
- 'source-size': '<media-condition> <source-size-value>',
18
- 'source-size-value': '<length>',
19
- },
20
- },
21
- };
22
- expect((0, css_syntax_1.cssSyntaxMatch)('50vw', sourceSizeList).matched).toBe(true);
23
- expect((0, css_syntax_1.cssSyntaxMatch)('(max-width: 600px) 200px, 50vw', sourceSizeList).matched).toBe(true);
24
- expect((0, css_syntax_1.cssSyntaxMatch)('print 300vw', sourceSizeList).matched).toBe(false);
25
- expect((0, css_syntax_1.cssSyntaxMatch)('(max-width: 600px) 200px', sourceSizeList).matched).toBe(false);
26
- expect((0, css_syntax_1.cssSyntaxMatch)('(max-width: 600px) 200px', {
27
- ...sourceSizeList,
28
- syntax: {
29
- ...sourceSizeList.syntax,
30
- apply: '<source-size>',
31
- },
32
- }).matched).toBe(true);
33
- const keyTimes = {
34
- ref: 'https://svgwg.org/specs/animations/#KeyTimesAttribute',
35
- syntax: {
36
- apply: '<key-times>',
37
- def: {
38
- 'key-times': '<number> [; <number>]* [;]?',
39
- },
40
- },
41
- };
42
- expect((0, css_syntax_1.cssSyntaxMatch)('20; 20; 30', keyTimes).matched).toBe(true);
43
- expect((0, css_syntax_1.cssSyntaxMatch)('20; 20; 30;', keyTimes).matched).toBe(true);
44
- expect((0, css_syntax_1.cssSyntaxMatch)('20; 20; abc;', keyTimes).matched).toBe(false);
45
- expect((0, css_syntax_1.cssSyntaxMatch)('20; 20; ;', keyTimes).matched).toBe(false);
46
- const SVGViewBox = {
47
- ref: 'https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute',
48
- syntax: {
49
- apply: '<view-box>',
50
- def: {
51
- 'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>',
52
- 'min-x': '<number>',
53
- 'min-y': '<number>',
54
- width: '<number>',
55
- height: '<number>',
56
- },
57
- },
58
- };
59
- expect((0, css_syntax_1.cssSyntaxMatch)('0 0 30 10', SVGViewBox).matched).toBe(true);
60
- expect((0, css_syntax_1.cssSyntaxMatch)('0 0, 30, 10', SVGViewBox).matched).toBe(true);
61
- expect((0, css_syntax_1.cssSyntaxMatch)('0 0, 30', SVGViewBox).matched).toBe(false);
62
- const percentageList = {
63
- ref: 'https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage',
64
- syntax: {
65
- apply: '<percentage-list>',
66
- def: {
67
- 'percentage-list': '[ <number> [,]? ]* <number>',
68
- },
69
- },
70
- };
71
- expect((0, css_syntax_1.cssSyntaxMatch)('0 0 30 10', percentageList).matched).toBe(true);
72
- expect((0, css_syntax_1.cssSyntaxMatch)('0, 0, 30 10', percentageList).matched).toBe(true);
73
- expect((0, css_syntax_1.cssSyntaxMatch)('0', percentageList).matched).toBe(true);
74
- expect((0, css_syntax_1.cssSyntaxMatch)('', percentageList).matched).toBe(false);
75
- const custom = {
76
- ref: 'n/a',
77
- syntax: {
78
- apply: '<custom>',
79
- def: {
80
- custom: '0 | 1 | .',
81
- },
82
- },
83
- };
84
- expect((0, css_syntax_1.cssSyntaxMatch)('0', custom).matched).toBe(true);
85
- expect((0, css_syntax_1.cssSyntaxMatch)('1', custom).matched).toBe(true);
86
- expect((0, css_syntax_1.cssSyntaxMatch)('.', custom).matched).toBe(true);
87
- expect((0, css_syntax_1.cssSyntaxMatch)('2', custom).matched).toBe(false);
88
- expect((0, css_syntax_1.cssSyntaxMatch)(':', custom).matched).toBe(false);
11
+ const sourceSizeList = {
12
+ ref: 'https://html.spec.whatwg.org/multipage/images.html#sizes-attributes',
13
+ syntax: {
14
+ apply: '<source-size-list>',
15
+ def: {
16
+ 'source-size-list': '[ <source-size># , ]? <source-size-value>',
17
+ 'source-size': '<media-condition> <source-size-value>',
18
+ 'source-size-value': '<length>',
19
+ },
20
+ },
21
+ };
22
+ expect((0, css_syntax_1.cssSyntaxMatch)('50vw', sourceSizeList).matched).toBe(true);
23
+ expect((0, css_syntax_1.cssSyntaxMatch)('(max-width: 600px) 200px, 50vw', sourceSizeList).matched).toBe(true);
24
+ expect((0, css_syntax_1.cssSyntaxMatch)('print 300vw', sourceSizeList).matched).toBe(false);
25
+ expect((0, css_syntax_1.cssSyntaxMatch)('(max-width: 600px) 200px', sourceSizeList).matched).toBe(false);
26
+ expect(
27
+ (0, css_syntax_1.cssSyntaxMatch)('(max-width: 600px) 200px', {
28
+ ...sourceSizeList,
29
+ syntax: {
30
+ ...sourceSizeList.syntax,
31
+ apply: '<source-size>',
32
+ },
33
+ }).matched,
34
+ ).toBe(true);
35
+ const keyTimes = {
36
+ ref: 'https://svgwg.org/specs/animations/#KeyTimesAttribute',
37
+ syntax: {
38
+ apply: '<key-times>',
39
+ def: {
40
+ 'key-times': '<number> [; <number>]* [;]?',
41
+ },
42
+ },
43
+ };
44
+ expect((0, css_syntax_1.cssSyntaxMatch)('20; 20; 30', keyTimes).matched).toBe(true);
45
+ expect((0, css_syntax_1.cssSyntaxMatch)('20; 20; 30;', keyTimes).matched).toBe(true);
46
+ expect((0, css_syntax_1.cssSyntaxMatch)('20; 20; abc;', keyTimes).matched).toBe(false);
47
+ expect((0, css_syntax_1.cssSyntaxMatch)('20; 20; ;', keyTimes).matched).toBe(false);
48
+ const SVGViewBox = {
49
+ ref: 'https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute',
50
+ syntax: {
51
+ apply: '<view-box>',
52
+ def: {
53
+ 'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>',
54
+ 'min-x': '<number>',
55
+ 'min-y': '<number>',
56
+ width: '<number>',
57
+ height: '<number>',
58
+ },
59
+ },
60
+ };
61
+ expect((0, css_syntax_1.cssSyntaxMatch)('0 0 30 10', SVGViewBox).matched).toBe(true);
62
+ expect((0, css_syntax_1.cssSyntaxMatch)('0 0, 30, 10', SVGViewBox).matched).toBe(true);
63
+ expect((0, css_syntax_1.cssSyntaxMatch)('0 0, 30', SVGViewBox).matched).toBe(false);
64
+ const percentageList = {
65
+ ref: 'https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage',
66
+ syntax: {
67
+ apply: '<percentage-list>',
68
+ def: {
69
+ 'percentage-list': '[ <number> [,]? ]* <number>',
70
+ },
71
+ },
72
+ };
73
+ expect((0, css_syntax_1.cssSyntaxMatch)('0 0 30 10', percentageList).matched).toBe(true);
74
+ expect((0, css_syntax_1.cssSyntaxMatch)('0, 0, 30 10', percentageList).matched).toBe(true);
75
+ expect((0, css_syntax_1.cssSyntaxMatch)('0', percentageList).matched).toBe(true);
76
+ expect((0, css_syntax_1.cssSyntaxMatch)('', percentageList).matched).toBe(false);
77
+ const custom = {
78
+ ref: 'n/a',
79
+ syntax: {
80
+ apply: '<custom>',
81
+ def: {
82
+ custom: '0 | 1 | .',
83
+ },
84
+ },
85
+ };
86
+ expect((0, css_syntax_1.cssSyntaxMatch)('0', custom).matched).toBe(true);
87
+ expect((0, css_syntax_1.cssSyntaxMatch)('1', custom).matched).toBe(true);
88
+ expect((0, css_syntax_1.cssSyntaxMatch)('.', custom).matched).toBe(true);
89
+ expect((0, css_syntax_1.cssSyntaxMatch)('2', custom).matched).toBe(false);
90
+ expect((0, css_syntax_1.cssSyntaxMatch)(':', custom).matched).toBe(false);
89
91
  });
90
92
  test('custom-type-checking', () => {
91
- const custom = {
92
- ref: 'n/a',
93
- caseSensitive: true,
94
- syntax: {
95
- apply: '<custom>',
96
- def: {
97
- custom: '<custom-type>',
98
- 'custom-type': token => {
99
- if (!token) {
100
- return 0;
101
- }
102
- return token.value === '1' ? 1 : 0;
103
- },
104
- },
105
- },
106
- };
107
- expect((0, css_syntax_1.cssSyntaxMatch)('1', custom).matched).toBe(true);
108
- expect((0, css_syntax_1.cssSyntaxMatch)('0', custom).matched).toBe(false);
93
+ const custom = {
94
+ ref: 'n/a',
95
+ caseSensitive: true,
96
+ syntax: {
97
+ apply: '<custom>',
98
+ def: {
99
+ custom: '<custom-type>',
100
+ 'custom-type': token => {
101
+ if (!token) {
102
+ return 0;
103
+ }
104
+ return token.value === '1' ? 1 : 0;
105
+ },
106
+ },
107
+ },
108
+ };
109
+ expect((0, css_syntax_1.cssSyntaxMatch)('1', custom).matched).toBe(true);
110
+ expect((0, css_syntax_1.cssSyntaxMatch)('0', custom).matched).toBe(false);
109
111
  });
110
112
  test('case-sensitive', () => {
111
- const custom = {
112
- ref: 'n/a',
113
- caseSensitive: true,
114
- syntax: {
115
- apply: '<custom>',
116
- def: {
117
- custom: 'CaSeS [a | B | aBc]',
118
- },
119
- },
120
- };
121
- expect((0, css_syntax_1.cssSyntaxMatch)('CaSeS a', custom).matched).toBe(true);
122
- expect((0, css_syntax_1.cssSyntaxMatch)('CaSeS B', custom).matched).toBe(true);
123
- expect((0, css_syntax_1.cssSyntaxMatch)('CaSeS aBc', custom).matched).toBe(true);
124
- expect((0, css_syntax_1.cssSyntaxMatch)('CaSeS A', custom)).toStrictEqual({
125
- column: 7,
126
- line: 1,
127
- matched: false,
128
- length: 1,
129
- offset: 6,
130
- partName: 'value',
131
- raw: 'A',
132
- reason: 'syntax-error',
133
- ref: 'n/a',
134
- expects: [
135
- {
136
- type: 'syntax',
137
- value: '<custom>',
138
- },
139
- ],
140
- });
141
- expect((0, css_syntax_1.cssSyntaxMatch)('CaSeS abc', custom)).toStrictEqual({
142
- column: 7,
143
- line: 1,
144
- matched: false,
145
- length: 3,
146
- offset: 6,
147
- partName: 'value',
148
- raw: 'abc',
149
- reason: 'syntax-error',
150
- ref: 'n/a',
151
- expects: [
152
- {
153
- type: 'syntax',
154
- value: '<custom>',
155
- },
156
- ],
157
- });
113
+ const custom = {
114
+ ref: 'n/a',
115
+ caseSensitive: true,
116
+ syntax: {
117
+ apply: '<custom>',
118
+ def: {
119
+ custom: 'CaSeS [a | B | aBc]',
120
+ },
121
+ },
122
+ };
123
+ expect((0, css_syntax_1.cssSyntaxMatch)('CaSeS a', custom).matched).toBe(true);
124
+ expect((0, css_syntax_1.cssSyntaxMatch)('CaSeS B', custom).matched).toBe(true);
125
+ expect((0, css_syntax_1.cssSyntaxMatch)('CaSeS aBc', custom).matched).toBe(true);
126
+ expect((0, css_syntax_1.cssSyntaxMatch)('CaSeS A', custom)).toStrictEqual({
127
+ column: 7,
128
+ line: 1,
129
+ matched: false,
130
+ length: 1,
131
+ offset: 6,
132
+ partName: 'value',
133
+ raw: 'A',
134
+ reason: 'syntax-error',
135
+ ref: 'n/a',
136
+ expects: [
137
+ {
138
+ type: 'syntax',
139
+ value: '<custom>',
140
+ },
141
+ ],
142
+ });
143
+ expect((0, css_syntax_1.cssSyntaxMatch)('CaSeS abc', custom)).toStrictEqual({
144
+ column: 7,
145
+ line: 1,
146
+ matched: false,
147
+ length: 3,
148
+ offset: 6,
149
+ partName: 'value',
150
+ raw: 'abc',
151
+ reason: 'syntax-error',
152
+ ref: 'n/a',
153
+ expects: [
154
+ {
155
+ type: 'syntax',
156
+ value: '<custom>',
157
+ },
158
+ ],
159
+ });
158
160
  });
@@ -1,6 +1,3 @@
1
1
  type NullableString = string | null | undefined;
2
- export declare function getCandidate(
3
- value: NullableString,
4
- ...candidates: readonly (NullableString | readonly NullableString[])[]
5
- ): string | undefined;
2
+ export declare function getCandidate(value: NullableString, ...candidates: readonly (NullableString | readonly NullableString[])[]): string | undefined;
6
3
  export {};