@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
@@ -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
- }