@markuplint/types 3.0.0-alpha.2 → 3.0.0-alpha.27

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 (72) hide show
  1. package/README.md +12 -8
  2. package/lib/css-syntax.js +6 -6
  3. package/lib/defs.js +1 -0
  4. package/lib/get-candidate.d.ts +1 -1
  5. package/lib/token/token-collection.d.ts +2 -2
  6. package/lib/token/token-collection.js +47 -47
  7. package/lib/token/token.js +7 -7
  8. package/lib/types.d.ts +16 -16
  9. package/lib/types.schema.d.ts +5 -5
  10. package/package.json +7 -5
  11. package/patches/css-tree+2.3.1.patch +23 -0
  12. package/types.schema.json +67 -16
  13. package/gen/specific-schema.json +0 -98
  14. package/gen/types.ts +0 -66
  15. package/src/check-multi-types.ts +0 -35
  16. package/src/check.spec.ts +0 -83
  17. package/src/check.ts +0 -48
  18. package/src/css-syntax.spec.ts +0 -167
  19. package/src/css-syntax.ts +0 -188
  20. package/src/debug.ts +0 -3
  21. package/src/defs.ts +0 -810
  22. package/src/enum.ts +0 -25
  23. package/src/get-candidate.ts +0 -24
  24. package/src/index.ts +0 -3
  25. package/src/keyword-type.ts +0 -64
  26. package/src/list.spec.ts +0 -133
  27. package/src/list.ts +0 -34
  28. package/src/match-result.ts +0 -49
  29. package/src/number.ts +0 -46
  30. package/src/primitive/index.spec.ts +0 -65
  31. package/src/primitive/index.ts +0 -7
  32. package/src/primitive/is-float.ts +0 -8
  33. package/src/primitive/is-int.ts +0 -8
  34. package/src/primitive/is-non-zero-uint.ts +0 -8
  35. package/src/primitive/is-quantity.ts +0 -38
  36. package/src/primitive/is-uint.ts +0 -15
  37. package/src/primitive/range.ts +0 -14
  38. package/src/primitive/split-unit.ts +0 -20
  39. package/src/rfc/is-bcp-47.spec.ts +0 -23
  40. package/src/rfc/is-bcp-47.ts +0 -13
  41. package/src/token/index.ts +0 -2
  42. package/src/token/token-collection.spec.ts +0 -147
  43. package/src/token/token-collection.ts +0 -444
  44. package/src/token/token.ts +0 -144
  45. package/src/types.schema.ts +0 -1062
  46. package/src/types.ts +0 -118
  47. package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
  48. package/src/w3c/check-serialized-permissions-policy.ts +0 -303
  49. package/src/whatwg/check-autocomplete.spec.ts +0 -387
  50. package/src/whatwg/check-autocomplete.ts +0 -380
  51. package/src/whatwg/check-datetime/date-string.ts +0 -44
  52. package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
  53. package/src/whatwg/check-datetime/duration-string.ts +0 -399
  54. package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
  55. package/src/whatwg/check-datetime/index.spec.ts +0 -333
  56. package/src/whatwg/check-datetime/index.ts +0 -36
  57. package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
  58. package/src/whatwg/check-datetime/month-string.ts +0 -31
  59. package/src/whatwg/check-datetime/time-string.ts +0 -49
  60. package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
  61. package/src/whatwg/check-datetime/week-string.ts +0 -41
  62. package/src/whatwg/check-datetime/year-string.ts +0 -26
  63. package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
  64. package/src/whatwg/check-mime-type.spec.ts +0 -59
  65. package/src/whatwg/check-mime-type.ts +0 -46
  66. package/src/whatwg/is-abs-url.spec.ts +0 -8
  67. package/src/whatwg/is-abs-url.ts +0 -31
  68. package/src/whatwg/is-browser-context-name.ts +0 -16
  69. package/src/whatwg/is-custom-element-name.ts +0 -76
  70. package/src/whatwg/is-itemprop-name.ts +0 -17
  71. package/tsconfig.test.json +0 -3
  72. package/tsconfig.tsbuildinfo +0 -1
@@ -1,144 +0,0 @@
1
- import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
2
-
3
- export class Token {
4
- /**
5
- * @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
6
- */
7
- static readonly Comma = 18;
8
- static readonly Ident = 1;
9
- static readonly WhiteSpace = 13;
10
-
11
- /**
12
- * ASCII whitespace is
13
- * - U+0009 TAB
14
- * - U+000A LF
15
- * - U+000C FF
16
- * - U+000D CR
17
- * - U+0020 SPACE.
18
- *
19
- * @see https://infra.spec.whatwg.org/#ascii-whitespace
20
- */
21
- static readonly whitespace: ReadonlyArray<string> = ['\u0009', '\u000A', '\u000C', '\u000D', '\u0020'];
22
-
23
- static getCol(value: string, offset: number) {
24
- const lines = value.slice(0, offset).split(/\n/g);
25
- return lines[lines.length - 1].length + 1;
26
- }
27
-
28
- static getLine(value: string, offset: number) {
29
- return value.slice(0, offset).split(/\n/g).length;
30
- }
31
-
32
- static getType(value: string, separators?: string[]) {
33
- if (Token.whitespace.includes(value[0])) {
34
- return Token.WhiteSpace;
35
- }
36
- if (separators?.includes(value[0])) {
37
- switch (value[0]) {
38
- case ',':
39
- return Token.Comma;
40
- }
41
- }
42
- return Token.Ident;
43
- }
44
-
45
- static shiftLocation(token: Token, offset: number) {
46
- const shifted = token.offset + offset;
47
- return {
48
- offset: shifted,
49
- line: Token.getLine(token.#originalValue, shifted),
50
- column: Token.getCol(token.#originalValue, shifted),
51
- };
52
- }
53
-
54
- readonly offset: number;
55
- #originalValue: string;
56
- readonly type: number;
57
- readonly value: string;
58
-
59
- constructor(value: string, offset: number, originalValue: string, separators?: string[]) {
60
- this.type = Token.getType(value, separators);
61
- this.value = value;
62
- this.offset = offset;
63
- this.#originalValue = originalValue;
64
- }
65
-
66
- get length() {
67
- return this.value.length;
68
- }
69
-
70
- get origin() {
71
- return this.#originalValue;
72
- }
73
-
74
- /**
75
- *
76
- * @param value The token value or the token type or its list
77
- */
78
- includes(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean {
79
- if (Array.isArray(value)) {
80
- return value.some(v => this.includes(v));
81
- }
82
- if (typeof value === 'string') {
83
- const a = caseInsensitive ? this.value.toLowerCase() : this.value;
84
- const b = caseInsensitive ? value.toLowerCase() : value;
85
- return a.indexOf(b) !== -1;
86
- }
87
- if (value instanceof RegExp) {
88
- const pattern = new RegExp(value, caseInsensitive ? 'i' : '');
89
- return pattern.test(this.value);
90
- }
91
- return this.type === value;
92
- }
93
-
94
- /**
95
- *
96
- * @param value The token value or the token type or its list
97
- */
98
- match(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean {
99
- if (Array.isArray(value)) {
100
- return value.some(v => this.match(v));
101
- }
102
- if (typeof value === 'string') {
103
- const a = caseInsensitive ? this.value.toLowerCase() : this.value;
104
- const b = caseInsensitive ? value.toLowerCase() : value;
105
- return a === b;
106
- }
107
- if (value instanceof RegExp) {
108
- const pattern = new RegExp(value, caseInsensitive ? 'i' : '');
109
- return pattern.test(this.value);
110
- }
111
- return this.type === value;
112
- }
113
-
114
- toJSON() {
115
- return {
116
- type: this.type,
117
- value: this.value,
118
- offset: this.offset,
119
- };
120
- }
121
-
122
- toNumber() {
123
- return parseFloat(this.value);
124
- }
125
-
126
- unmatched(
127
- options?: UnmatchedResultOptions & {
128
- ref?: string;
129
- reason?: UnmatchedResultReason;
130
- },
131
- ): UnmatchedResult {
132
- return {
133
- ...options,
134
- matched: false,
135
- ref: options?.ref || null,
136
- raw: this.value,
137
- offset: this.offset,
138
- length: this.value.length,
139
- line: Token.getLine(this.#originalValue, this.offset),
140
- column: Token.getCol(this.#originalValue, this.offset),
141
- reason: options?.reason ?? 'syntax-error',
142
- };
143
- }
144
- }