@markuplint/types 3.0.0-alpha.1 → 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 (75) hide show
  1. package/README.md +12 -8
  2. package/lib/check-multi-types.d.ts +1 -1
  3. package/lib/css-syntax.js +6 -6
  4. package/lib/defs.js +1 -0
  5. package/lib/get-candidate.d.ts +1 -1
  6. package/lib/match-result.d.ts +1 -1
  7. package/lib/token/token-collection.d.ts +3 -3
  8. package/lib/token/token-collection.js +47 -47
  9. package/lib/token/token.d.ts +1 -1
  10. package/lib/token/token.js +7 -7
  11. package/lib/types.d.ts +16 -16
  12. package/lib/types.schema.d.ts +5 -5
  13. package/package.json +7 -5
  14. package/patches/css-tree+2.3.1.patch +23 -0
  15. package/types.schema.json +67 -16
  16. package/gen/specific-schema.json +0 -98
  17. package/gen/types.ts +0 -66
  18. package/src/check-multi-types.ts +0 -35
  19. package/src/check.spec.ts +0 -83
  20. package/src/check.ts +0 -48
  21. package/src/css-syntax.spec.ts +0 -167
  22. package/src/css-syntax.ts +0 -188
  23. package/src/debug.ts +0 -3
  24. package/src/defs.ts +0 -810
  25. package/src/enum.ts +0 -25
  26. package/src/get-candidate.ts +0 -24
  27. package/src/index.ts +0 -3
  28. package/src/keyword-type.ts +0 -64
  29. package/src/list.spec.ts +0 -133
  30. package/src/list.ts +0 -34
  31. package/src/match-result.ts +0 -49
  32. package/src/number.ts +0 -46
  33. package/src/primitive/index.spec.ts +0 -65
  34. package/src/primitive/index.ts +0 -7
  35. package/src/primitive/is-float.ts +0 -8
  36. package/src/primitive/is-int.ts +0 -8
  37. package/src/primitive/is-non-zero-uint.ts +0 -8
  38. package/src/primitive/is-quantity.ts +0 -38
  39. package/src/primitive/is-uint.ts +0 -15
  40. package/src/primitive/range.ts +0 -14
  41. package/src/primitive/split-unit.ts +0 -20
  42. package/src/rfc/is-bcp-47.spec.ts +0 -23
  43. package/src/rfc/is-bcp-47.ts +0 -13
  44. package/src/token/index.ts +0 -2
  45. package/src/token/token-collection.spec.ts +0 -147
  46. package/src/token/token-collection.ts +0 -444
  47. package/src/token/token.ts +0 -144
  48. package/src/types.schema.ts +0 -1062
  49. package/src/types.ts +0 -118
  50. package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
  51. package/src/w3c/check-serialized-permissions-policy.ts +0 -303
  52. package/src/whatwg/check-autocomplete.spec.ts +0 -387
  53. package/src/whatwg/check-autocomplete.ts +0 -380
  54. package/src/whatwg/check-datetime/date-string.ts +0 -44
  55. package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
  56. package/src/whatwg/check-datetime/duration-string.ts +0 -399
  57. package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
  58. package/src/whatwg/check-datetime/index.spec.ts +0 -333
  59. package/src/whatwg/check-datetime/index.ts +0 -36
  60. package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
  61. package/src/whatwg/check-datetime/month-string.ts +0 -31
  62. package/src/whatwg/check-datetime/time-string.ts +0 -49
  63. package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
  64. package/src/whatwg/check-datetime/week-string.ts +0 -41
  65. package/src/whatwg/check-datetime/year-string.ts +0 -26
  66. package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
  67. package/src/whatwg/check-mime-type.spec.ts +0 -59
  68. package/src/whatwg/check-mime-type.ts +0 -46
  69. package/src/whatwg/is-abs-url.spec.ts +0 -8
  70. package/src/whatwg/is-abs-url.ts +0 -31
  71. package/src/whatwg/is-browser-context-name.ts +0 -16
  72. package/src/whatwg/is-custom-element-name.ts +0 -76
  73. package/src/whatwg/is-itemprop-name.ts +0 -17
  74. package/tsconfig.test.json +0 -3
  75. 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
- }