@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,145 +1,166 @@
1
- "use strict";
1
+ 'use strict';
2
2
  // @ts-nocheck
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const token_collection_1 = require("./token-collection");
5
- const _1 = require(".");
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+ const token_collection_1 = require('./token-collection');
5
+
6
+ const _1 = require('.');
6
7
  test('parse', () => {
7
- expect(new token_collection_1.TokenCollection(' a b c ').toJSON()).toStrictEqual([
8
- {
9
- offset: 0,
10
- type: 13,
11
- value: ' ',
12
- },
13
- {
14
- offset: 1,
15
- type: 1,
16
- value: 'a',
17
- },
18
- {
19
- offset: 2,
20
- type: 13,
21
- value: ' ',
22
- },
23
- {
24
- offset: 4,
25
- type: 1,
26
- value: 'b',
27
- },
28
- {
29
- offset: 5,
30
- type: 13,
31
- value: ' ',
32
- },
33
- {
34
- offset: 8,
35
- type: 1,
36
- value: 'c',
37
- },
38
- {
39
- offset: 9,
40
- type: 13,
41
- value: ' ',
42
- },
43
- ]);
8
+ expect(new token_collection_1.TokenCollection(' a b c ').toJSON()).toStrictEqual([
9
+ {
10
+ offset: 0,
11
+ type: 13,
12
+ value: ' ',
13
+ },
14
+ {
15
+ offset: 1,
16
+ type: 1,
17
+ value: 'a',
18
+ },
19
+ {
20
+ offset: 2,
21
+ type: 13,
22
+ value: ' ',
23
+ },
24
+ {
25
+ offset: 4,
26
+ type: 1,
27
+ value: 'b',
28
+ },
29
+ {
30
+ offset: 5,
31
+ type: 13,
32
+ value: ' ',
33
+ },
34
+ {
35
+ offset: 8,
36
+ type: 1,
37
+ value: 'c',
38
+ },
39
+ {
40
+ offset: 9,
41
+ type: 13,
42
+ value: ' ',
43
+ },
44
+ ]);
44
45
  });
45
46
  test('parse comma separator', () => {
46
- expect(new token_collection_1.TokenCollection('a,, ,b,cde', { separator: 'comma' }).toJSON()).toStrictEqual([
47
- {
48
- offset: 0,
49
- type: 1,
50
- value: 'a',
51
- },
52
- {
53
- offset: 1,
54
- type: 18,
55
- value: ',',
56
- },
57
- {
58
- offset: 2,
59
- type: 18,
60
- value: ',',
61
- },
62
- {
63
- offset: 3,
64
- type: 13,
65
- value: ' ',
66
- },
67
- {
68
- offset: 4,
69
- type: 18,
70
- value: ',',
71
- },
72
- {
73
- offset: 5,
74
- type: 1,
75
- value: 'b',
76
- },
77
- {
78
- offset: 6,
79
- type: 18,
80
- value: ',',
81
- },
82
- {
83
- offset: 7,
84
- type: 1,
85
- value: 'cde',
86
- },
87
- ]);
47
+ expect(new token_collection_1.TokenCollection('a,, ,b,cde', { separator: 'comma' }).toJSON()).toStrictEqual([
48
+ {
49
+ offset: 0,
50
+ type: 1,
51
+ value: 'a',
52
+ },
53
+ {
54
+ offset: 1,
55
+ type: 18,
56
+ value: ',',
57
+ },
58
+ {
59
+ offset: 2,
60
+ type: 18,
61
+ value: ',',
62
+ },
63
+ {
64
+ offset: 3,
65
+ type: 13,
66
+ value: ' ',
67
+ },
68
+ {
69
+ offset: 4,
70
+ type: 18,
71
+ value: ',',
72
+ },
73
+ {
74
+ offset: 5,
75
+ type: 1,
76
+ value: 'b',
77
+ },
78
+ {
79
+ offset: 6,
80
+ type: 18,
81
+ value: ',',
82
+ },
83
+ {
84
+ offset: 7,
85
+ type: 1,
86
+ value: 'cde',
87
+ },
88
+ ]);
88
89
  });
89
90
  test('A comma is an ident if the comma is not a separator', () => {
90
- expect(new token_collection_1.TokenCollection('a ,cde , f').toJSON()).toStrictEqual([
91
- {
92
- offset: 0,
93
- type: 1,
94
- value: 'a',
95
- },
96
- {
97
- offset: 1,
98
- type: 13,
99
- value: ' ',
100
- },
101
- {
102
- offset: 2,
103
- type: 1,
104
- value: ',cde',
105
- },
106
- {
107
- offset: 6,
108
- type: 13,
109
- value: ' ',
110
- },
111
- {
112
- offset: 7,
113
- type: 1,
114
- value: ',',
115
- },
116
- {
117
- offset: 8,
118
- type: 13,
119
- value: ' ',
120
- },
121
- {
122
- offset: 9,
123
- type: 1,
124
- value: 'f',
125
- },
126
- ]);
91
+ expect(new token_collection_1.TokenCollection('a ,cde , f').toJSON()).toStrictEqual([
92
+ {
93
+ offset: 0,
94
+ type: 1,
95
+ value: 'a',
96
+ },
97
+ {
98
+ offset: 1,
99
+ type: 13,
100
+ value: ' ',
101
+ },
102
+ {
103
+ offset: 2,
104
+ type: 1,
105
+ value: ',cde',
106
+ },
107
+ {
108
+ offset: 6,
109
+ type: 13,
110
+ value: ' ',
111
+ },
112
+ {
113
+ offset: 7,
114
+ type: 1,
115
+ value: ',',
116
+ },
117
+ {
118
+ offset: 8,
119
+ type: 13,
120
+ value: ' ',
121
+ },
122
+ {
123
+ offset: 9,
124
+ type: 1,
125
+ value: 'f',
126
+ },
127
+ ]);
127
128
  });
128
129
  test('getConsecutiveToken', () => {
129
- var _a;
130
- expect(new token_collection_1.TokenCollection('a,b,c', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma)).toBeFalsy();
131
- expect(new token_collection_1.TokenCollection('a,,b', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma)).toBeTruthy();
132
- expect((_a = new token_collection_1.TokenCollection('a,,b', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma)) === null || _a === void 0 ? void 0 : _a.offset).toBe(2);
130
+ let _a;
131
+ expect(
132
+ new token_collection_1.TokenCollection('a,b,c', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma),
133
+ ).toBeFalsy();
134
+ expect(
135
+ new token_collection_1.TokenCollection('a,,b', { separator: 'comma' }).getConsecutiveToken(_1.Token.Comma),
136
+ ).toBeTruthy();
137
+ expect(
138
+ (_a = new token_collection_1.TokenCollection('a,,b', { separator: 'comma' }).getConsecutiveToken(
139
+ _1.Token.Comma,
140
+ )) === null || _a === void 0
141
+ ? void 0
142
+ : _a.offset,
143
+ ).toBe(2);
133
144
  });
134
145
  test('fromPatterns', () => {
135
- const patterns = [/\+|-/, /[0-9]{2}/, /:?/, /[0-9]{2}/];
136
- expect(token_collection_1.TokenCollection.fromPatterns('+00:00', patterns).map(t => t.value)).toStrictEqual(['+', '00', ':', '00']);
137
- expect(token_collection_1.TokenCollection.fromPatterns('+0000', patterns).map(t => t.value)).toStrictEqual(['+', '00', '', '00']);
138
- expect(token_collection_1.TokenCollection.fromPatterns('+00/00', patterns).map(t => t.value)).toStrictEqual([
139
- '+',
140
- '00',
141
- '',
142
- '',
143
- '/00',
144
- ]);
146
+ const patterns = [/\+|-/, /[0-9]{2}/, /:?/, /[0-9]{2}/];
147
+ expect(token_collection_1.TokenCollection.fromPatterns('+00:00', patterns).map(t => t.value)).toStrictEqual([
148
+ '+',
149
+ '00',
150
+ ':',
151
+ '00',
152
+ ]);
153
+ expect(token_collection_1.TokenCollection.fromPatterns('+0000', patterns).map(t => t.value)).toStrictEqual([
154
+ '+',
155
+ '00',
156
+ '',
157
+ '00',
158
+ ]);
159
+ expect(token_collection_1.TokenCollection.fromPatterns('+00/00', patterns).map(t => t.value)).toStrictEqual([
160
+ '+',
161
+ '00',
162
+ '',
163
+ '',
164
+ '/00',
165
+ ]);
145
166
  });
@@ -20,7 +20,7 @@ export declare class Token {
20
20
  static readonly whitespace: ReadonlyArray<string>;
21
21
  static getCol(value: string, offset: number): number;
22
22
  static getLine(value: string, offset: number): number;
23
- static getType(value: string, separators?: readonly string[]): 18 | 1 | 13;
23
+ static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
24
24
  static shiftLocation(token: Readonly<Token>, offset: number): {
25
25
  offset: number;
26
26
  line: number;
package/lib/types.d.ts CHANGED
@@ -2,101 +2,77 @@ 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
- 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;
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
- readonly partName?: string;
17
- readonly expects?: readonly Expect[];
18
- readonly extra?: Expect;
19
- readonly candidate?: string;
16
+ readonly partName?: string;
17
+ readonly expects?: readonly Expect[];
18
+ readonly extra?: Expect;
19
+ readonly candidate?: string;
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
+ readonly type: 'out-of-range';
23
+ readonly gt?: number;
24
+ readonly gte?: number;
25
+ readonly lt?: number;
26
+ readonly lte?: number;
27
+ } | {
28
+ readonly type: 'out-of-range-length-char';
29
+ readonly gte: number;
30
+ readonly lte?: number;
31
+ } | {
32
+ readonly type: 'out-of-range-length-digit';
33
+ readonly gte: number;
34
+ readonly lte?: number;
20
35
  };
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
- };
56
36
  export type MatchedResult = {
57
- readonly matched: true;
37
+ readonly matched: true;
58
38
  };
59
39
  export type Expect = {
60
- readonly type: 'const' | 'format' | 'syntax' | 'regexp' | 'common';
61
- readonly value: string;
40
+ readonly type: 'const' | 'format' | 'syntax' | 'regexp' | 'common';
41
+ readonly value: string;
62
42
  };
63
43
  export type FormattedPrimitiveTypeCheck = (value: string) => boolean;
64
44
  export type FormattedPrimitiveTypeCreator<O = never> = (options?: O) => FormattedPrimitiveTypeCheck;
65
45
  export type Defs = Record<string, CustomCssSyntax | CustomSyntax>;
66
46
  export type CustomSyntax = {
67
- readonly ref: string;
68
- readonly expects?: readonly Expect[];
69
- readonly is: CustomSyntaxCheck;
47
+ readonly ref: string;
48
+ readonly expects?: readonly Expect[];
49
+ readonly is: CustomSyntaxCheck;
70
50
  };
71
51
  export type CustomSyntaxCheck = (value: string) => Result;
72
52
  export type CustomSyntaxChecker<O = {}> = (options?: O) => CustomSyntaxCheck;
73
53
  export type CustomCssSyntax = {
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
- };
54
+ readonly ref: string;
55
+ readonly caseSensitive?: boolean;
56
+ readonly expects?: readonly Expect[];
57
+ readonly syntax: {
58
+ readonly apply: `<${string}>`;
59
+ readonly def: Readonly<Record<string, string | CssSyntaxTokenizer>>;
60
+ /**
61
+ * @deprecated
62
+ */
63
+ readonly ebnf?: Readonly<Record<string, string | readonly string[]>>;
64
+ /**
65
+ * @deprecated
66
+ */
67
+ readonly properties?: Readonly<Record<string, string>>;
68
+ };
89
69
  };
90
70
  export type CSSSyntaxToken = {
91
- readonly type: number;
92
- readonly value: string;
93
- readonly index: number;
94
- readonly balance: number;
95
- readonly node?: any;
71
+ readonly type: number;
72
+ readonly value: string;
73
+ readonly index: number;
74
+ readonly balance: number;
75
+ readonly node?: any;
96
76
  };
97
- export type CssSyntaxTokenizer = (
98
- token: Readonly<CSSSyntaxToken> | null,
99
- getNextToken: GetNextToken,
100
- match: typeof cssSyntaxMatch,
101
- ) => number;
77
+ export type CssSyntaxTokenizer = (token: Readonly<CSSSyntaxToken> | null, getNextToken: GetNextToken, match: typeof cssSyntaxMatch) => number;
102
78
  export type GetNextToken = (length: number) => CSSSyntaxToken | null;