@markuplint/types 3.0.0-rc.4 → 3.0.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 (73) hide show
  1. package/lib/check-multi-types.d.ts +1 -4
  2. package/lib/get-candidate.d.ts +1 -4
  3. package/lib/match-result.d.ts +8 -21
  4. package/lib/primitive/is-uint.d.ts +3 -6
  5. package/lib/primitive/split-unit.d.ts +2 -2
  6. package/lib/token/token-collection.d.ts +55 -64
  7. package/lib/token/token.d.ts +52 -57
  8. package/lib/types.d.ts +55 -79
  9. package/lib/types.schema.d.ts +31 -1033
  10. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -21
  11. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +1 -1
  12. package/lib/whatwg/check-mime-type.d.ts +4 -4
  13. package/package.json +2 -2
  14. package/gen/specific-schema.json +0 -98
  15. package/gen/types.ts +0 -66
  16. package/src/check-multi-types.ts +0 -35
  17. package/src/check.spec.ts +0 -83
  18. package/src/check.ts +0 -48
  19. package/src/css-syntax.spec.ts +0 -167
  20. package/src/css-syntax.ts +0 -188
  21. package/src/debug.ts +0 -3
  22. package/src/defs.ts +0 -811
  23. package/src/enum.ts +0 -25
  24. package/src/get-candidate.ts +0 -24
  25. package/src/index.ts +0 -3
  26. package/src/keyword-type.ts +0 -64
  27. package/src/list.spec.ts +0 -133
  28. package/src/list.ts +0 -34
  29. package/src/match-result.ts +0 -49
  30. package/src/number.ts +0 -46
  31. package/src/primitive/index.spec.ts +0 -65
  32. package/src/primitive/index.ts +0 -7
  33. package/src/primitive/is-float.ts +0 -8
  34. package/src/primitive/is-int.ts +0 -8
  35. package/src/primitive/is-non-zero-uint.ts +0 -8
  36. package/src/primitive/is-quantity.ts +0 -38
  37. package/src/primitive/is-uint.ts +0 -15
  38. package/src/primitive/range.ts +0 -14
  39. package/src/primitive/split-unit.ts +0 -20
  40. package/src/rfc/is-bcp-47.spec.ts +0 -23
  41. package/src/rfc/is-bcp-47.ts +0 -13
  42. package/src/token/index.ts +0 -2
  43. package/src/token/token-collection.spec.ts +0 -147
  44. package/src/token/token-collection.ts +0 -444
  45. package/src/token/token.ts +0 -144
  46. package/src/types.schema.ts +0 -1062
  47. package/src/types.ts +0 -118
  48. package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
  49. package/src/w3c/check-serialized-permissions-policy.ts +0 -303
  50. package/src/whatwg/check-autocomplete.spec.ts +0 -387
  51. package/src/whatwg/check-autocomplete.ts +0 -380
  52. package/src/whatwg/check-datetime/date-string.ts +0 -44
  53. package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
  54. package/src/whatwg/check-datetime/duration-string.ts +0 -399
  55. package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
  56. package/src/whatwg/check-datetime/index.spec.ts +0 -333
  57. package/src/whatwg/check-datetime/index.ts +0 -36
  58. package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
  59. package/src/whatwg/check-datetime/month-string.ts +0 -31
  60. package/src/whatwg/check-datetime/time-string.ts +0 -49
  61. package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
  62. package/src/whatwg/check-datetime/week-string.ts +0 -41
  63. package/src/whatwg/check-datetime/year-string.ts +0 -26
  64. package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
  65. package/src/whatwg/check-mime-type.spec.ts +0 -59
  66. package/src/whatwg/check-mime-type.ts +0 -46
  67. package/src/whatwg/is-abs-url.spec.ts +0 -8
  68. package/src/whatwg/is-abs-url.ts +0 -31
  69. package/src/whatwg/is-browser-context-name.ts +0 -16
  70. package/src/whatwg/is-custom-element-name.ts +0 -76
  71. package/src/whatwg/is-itemprop-name.ts +0 -17
  72. package/tsconfig.test.json +0 -3
  73. package/tsconfig.tsbuildinfo +0 -1
package/src/css-syntax.ts DELETED
@@ -1,188 +0,0 @@
1
- import type { CustomCssSyntax, CssSyntaxTokenizer, CSSSyntaxToken, GetNextToken, Result, CssSyntax } from './types';
2
-
3
- // @ts-ignore
4
- import csstree from 'css-tree';
5
- // @ts-ignore
6
- import { SyntaxMatchError } from 'css-tree/lib/lexer/error.js';
7
- // @ts-ignore
8
- import { matchAsTree } from 'css-tree/lib/lexer/match.js';
9
- // @ts-ignore
10
- import prepareTokens from 'css-tree/lib/lexer/prepare-tokens.js';
11
-
12
- import { log } from './debug';
13
- import { tokenizers } from './defs';
14
- import { matched } from './match-result';
15
-
16
- // eslint-disable-next-line no-redeclare
17
- interface SyntaxMatchError {
18
- message: string;
19
- rawMessage: 'Mismatch';
20
- syntax: string;
21
- css: string;
22
- mismatchOffset: number;
23
- mismatchLength: number;
24
- offset: number;
25
- line: number;
26
- column: number;
27
- loc: {
28
- source: '<unknown>';
29
- start: { offset: number; line: number; column: number };
30
- end: { offset: number; line: number; column: number };
31
- };
32
- }
33
-
34
- export function cssSyntaxMatch(value: string, type: CssSyntax | CustomCssSyntax): Result {
35
- log('Search CSS Syntax: "%s"', type);
36
-
37
- const origin = value;
38
- let defName: `<${string}>`;
39
- const typesExtended: Record<string, string> = {};
40
- const typesCheckers: Record<string, CssSyntaxTokenizer> = {};
41
- let propsExtended: Record<string, string>;
42
- let ref: string | undefined = undefined;
43
- let caseSensitive = false;
44
- let ebnf: Record<string, string | string[]> | null = null;
45
-
46
- if (typeof type === 'string') {
47
- defName = type;
48
- propsExtended = {};
49
- } else {
50
- defName = type.syntax.apply;
51
- ebnf = type.syntax.ebnf || null;
52
-
53
- if (ebnf) {
54
- // Work in progress
55
- return matched();
56
- }
57
-
58
- const types = {
59
- ...tokenizers,
60
- ...type.syntax.def,
61
- };
62
- Object.keys(types).forEach(key => {
63
- const valueOrChecker = types[key];
64
- if (typeof valueOrChecker === 'string') {
65
- typesExtended[key] = valueOrChecker;
66
- } else {
67
- typesCheckers[key] = valueOrChecker;
68
- }
69
- });
70
- propsExtended = { ...type.syntax.properties };
71
- if (type.caseSensitive) {
72
- caseSensitive = true;
73
- Object.keys(typesExtended).forEach(key => eachMimicCases(key, typesExtended));
74
- Object.keys(propsExtended).forEach(key => eachMimicCases(key, propsExtended));
75
- value = mimicCases(value);
76
- }
77
- ref = type.ref;
78
- }
79
-
80
- // @ts-ignore
81
- const lexer = csstree.fork({
82
- types: typesExtended,
83
- properties: propsExtended,
84
- }).lexer;
85
-
86
- Object.keys(typesCheckers).forEach(key => {
87
- const checker = typesCheckers[key];
88
- lexer.addType_(key, (token: CSSSyntaxToken, getNextToken: GetNextToken) =>
89
- checker(token, getNextToken, cssSyntaxMatch),
90
- );
91
- });
92
-
93
- const { isProp, name, matcher } = defToMatcher(lexer, defName);
94
- const refParam = isProp ? 'Property' : 'Type';
95
- ref = ref || `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
96
-
97
- // eslint-disable-next-line no-console
98
- const _w = console.warn;
99
-
100
- if (log.enabled) {
101
- // eslint-disable-next-line no-console
102
- console.warn = warn => log('WARNING: %s (by %s => %s)', warn, value, type);
103
- }
104
-
105
- const tokens = prepareTokens(value, lexer.syntax);
106
- const result = matchAsTree(tokens, matcher.match, lexer);
107
-
108
- if (caseSensitive) {
109
- if (result.tokens && Array.isArray(result.tokens)) {
110
- let reducer = 0;
111
- result.tokens = result.tokens.map((token: CSSSyntaxToken) => {
112
- const value = token.value;
113
- const originValue = deMimicCases(value || '');
114
- const isMimiced = value !== originValue;
115
- reducer += isMimiced ? 'mimiccases------mimiccases'.length : 0;
116
- token.value = originValue;
117
- token.balance = token.balance - reducer;
118
- return token;
119
- });
120
- }
121
- }
122
-
123
- log('css-tree/result: %O', result);
124
- // eslint-disable-next-line no-console
125
- console.warn = _w;
126
-
127
- if (result.match) {
128
- if (log.enabled) {
129
- log('css-tree/result.match: %s', JSON.stringify(result.match, null, 2));
130
- }
131
- return matched();
132
- }
133
-
134
- const error: SyntaxMatchError = new SyntaxMatchError(result.reason, matcher.syntax, value, result);
135
-
136
- if (caseSensitive) {
137
- error.message = deMimicCases(error.message);
138
- error.syntax = deMimicCases(error.syntax);
139
- }
140
-
141
- log('css-tree/SyntaxMatchError: %O', error);
142
-
143
- return {
144
- matched: false,
145
- ref,
146
- raw: origin.slice(error.mismatchOffset, error.mismatchOffset + error.mismatchLength),
147
- offset: error.mismatchOffset,
148
- length: error.mismatchLength,
149
- line: error.line,
150
- column: error.column,
151
- expects: [
152
- {
153
- type: 'syntax',
154
- value: error.syntax,
155
- },
156
- ],
157
- partName: error.mismatchOffset === 0 ? undefined : 'value',
158
- reason: 'syntax-error',
159
- };
160
- }
161
-
162
- function defToMatcher(lexer: any, def: `<${string}>`) {
163
- const isProp = def.search("<'") === 0;
164
- const name = def.replace(/^<'?|'?>$/g, '');
165
- const matcher = isProp ? lexer.properties[name] : lexer.types[name];
166
- if (!matcher) {
167
- log('"%s" CSS syntax not found', def);
168
- throw new Error('MARKUPLINT_TYPE_NO_EXIST');
169
- }
170
- return {
171
- isProp,
172
- name,
173
- matcher,
174
- };
175
- }
176
-
177
- function eachMimicCases(key: string, obj: Record<string, string>) {
178
- const value = obj[key];
179
- obj[key] = mimicCases(value);
180
- }
181
-
182
- function mimicCases(value: string) {
183
- return value.replace(/[A-Z]/g, $0 => `mimiccases---${$0}---mimiccases`);
184
- }
185
-
186
- function deMimicCases(value: string) {
187
- return value.replace(/mimiccases---([A-Z])---mimiccases/g, (_, $1) => $1);
188
- }
package/src/debug.ts DELETED
@@ -1,3 +0,0 @@
1
- import debug from 'debug';
2
-
3
- export const log = debug('@markuplint/types');