@markuplint/types 1.0.0-dev.20211213.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 (177) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +117 -0
  3. package/extends.json +12 -0
  4. package/gen/specific-schema.json +98 -0
  5. package/gen/types.ts +66 -0
  6. package/lib/check-multi-types.d.ts +2 -0
  7. package/lib/check-multi-types.js +29 -0
  8. package/lib/check.d.ts +8 -0
  9. package/lib/check.js +49 -0
  10. package/lib/check.spec.d.ts +1 -0
  11. package/lib/check.spec.js +57 -0
  12. package/lib/css-syntax.d.ts +2 -0
  13. package/lib/css-syntax.js +141 -0
  14. package/lib/css-syntax.spec.d.ts +1 -0
  15. package/lib/css-syntax.spec.js +157 -0
  16. package/lib/debug.d.ts +2 -0
  17. package/lib/debug.js +6 -0
  18. package/lib/defs.d.ts +3 -0
  19. package/lib/defs.js +752 -0
  20. package/lib/enum.d.ts +3 -0
  21. package/lib/enum.js +26 -0
  22. package/lib/get-candicate.d.ts +3 -0
  23. package/lib/get-candicate.js +26 -0
  24. package/lib/index.d.ts +3 -0
  25. package/lib/index.js +6 -0
  26. package/lib/keyword-type.d.ts +3 -0
  27. package/lib/keyword-type.js +46 -0
  28. package/lib/list.d.ts +3 -0
  29. package/lib/list.js +29 -0
  30. package/lib/list.spec.d.ts +1 -0
  31. package/lib/list.spec.js +129 -0
  32. package/lib/match-result.d.ts +9 -0
  33. package/lib/match-result.js +33 -0
  34. package/lib/number.d.ts +3 -0
  35. package/lib/number.js +41 -0
  36. package/lib/primitive/index.d.ts +7 -0
  37. package/lib/primitive/index.js +17 -0
  38. package/lib/primitive/index.spec.d.ts +1 -0
  39. package/lib/primitive/index.spec.js +62 -0
  40. package/lib/primitive/is-float.d.ts +6 -0
  41. package/lib/primitive/is-float.js +12 -0
  42. package/lib/primitive/is-int.d.ts +6 -0
  43. package/lib/primitive/is-int.js +12 -0
  44. package/lib/primitive/is-non-zero-uint.d.ts +6 -0
  45. package/lib/primitive/is-non-zero-uint.js +12 -0
  46. package/lib/primitive/is-quantity.d.ts +7 -0
  47. package/lib/primitive/is-quantity.js +41 -0
  48. package/lib/primitive/is-uint.d.ts +8 -0
  49. package/lib/primitive/is-uint.js +19 -0
  50. package/lib/primitive/range.d.ts +8 -0
  51. package/lib/primitive/range.js +18 -0
  52. package/lib/primitive/split-unit.d.ts +9 -0
  53. package/lib/primitive/split-unit.js +24 -0
  54. package/lib/rfc/is-bcp-47.d.ts +5 -0
  55. package/lib/rfc/is-bcp-47.js +14 -0
  56. package/lib/rfc/is-bcp-47.spec.d.ts +1 -0
  57. package/lib/rfc/is-bcp-47.spec.js +19 -0
  58. package/lib/token/index.d.ts +2 -0
  59. package/lib/token/index.js +7 -0
  60. package/lib/token/token-collection.d.ts +62 -0
  61. package/lib/token/token-collection.js +383 -0
  62. package/lib/token/token-collection.spec.d.ts +1 -0
  63. package/lib/token/token-collection.spec.js +144 -0
  64. package/lib/token/token.d.ts +55 -0
  65. package/lib/token/token.js +128 -0
  66. package/lib/types.d.ts +78 -0
  67. package/lib/types.js +2 -0
  68. package/lib/types.schema.d.ts +54 -0
  69. package/lib/types.schema.js +8 -0
  70. package/lib/w3c/check-serialized-permissions-policy.d.ts +15 -0
  71. package/lib/w3c/check-serialized-permissions-policy.js +251 -0
  72. package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +1 -0
  73. package/lib/w3c/check-serialized-permissions-policy.spec.js +26 -0
  74. package/lib/whatwg/check-autocomplete.d.ts +5 -0
  75. package/lib/whatwg/check-autocomplete.js +282 -0
  76. package/lib/whatwg/check-autocomplete.spec.d.ts +1 -0
  77. package/lib/whatwg/check-autocomplete.spec.js +370 -0
  78. package/lib/whatwg/check-datetime/date-string.d.ts +5 -0
  79. package/lib/whatwg/check-datetime/date-string.js +31 -0
  80. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +3 -0
  81. package/lib/whatwg/check-datetime/datetime-tokens.js +509 -0
  82. package/lib/whatwg/check-datetime/duration-string.d.ts +6 -0
  83. package/lib/whatwg/check-datetime/duration-string.js +322 -0
  84. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +5 -0
  85. package/lib/whatwg/check-datetime/global-date-and-time-string.js +66 -0
  86. package/lib/whatwg/check-datetime/index.d.ts +5 -0
  87. package/lib/whatwg/check-datetime/index.js +35 -0
  88. package/lib/whatwg/check-datetime/index.spec.d.ts +1 -0
  89. package/lib/whatwg/check-datetime/index.spec.js +318 -0
  90. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +9 -0
  91. package/lib/whatwg/check-datetime/local-date-and-time-string.js +116 -0
  92. package/lib/whatwg/check-datetime/month-string.d.ts +5 -0
  93. package/lib/whatwg/check-datetime/month-string.js +20 -0
  94. package/lib/whatwg/check-datetime/time-string.d.ts +5 -0
  95. package/lib/whatwg/check-datetime/time-string.js +35 -0
  96. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +7 -0
  97. package/lib/whatwg/check-datetime/time-zone-offset-string.js +75 -0
  98. package/lib/whatwg/check-datetime/week-string.d.ts +5 -0
  99. package/lib/whatwg/check-datetime/week-string.js +29 -0
  100. package/lib/whatwg/check-datetime/year-string.d.ts +5 -0
  101. package/lib/whatwg/check-datetime/year-string.js +20 -0
  102. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +5 -0
  103. package/lib/whatwg/check-datetime/yearless-date-string.js +27 -0
  104. package/lib/whatwg/check-mime-type.d.ts +11 -0
  105. package/lib/whatwg/check-mime-type.js +42 -0
  106. package/lib/whatwg/check-mime-type.spec.d.ts +1 -0
  107. package/lib/whatwg/check-mime-type.spec.js +58 -0
  108. package/lib/whatwg/is-abs-url.d.ts +15 -0
  109. package/lib/whatwg/is-abs-url.js +34 -0
  110. package/lib/whatwg/is-abs-url.spec.d.ts +1 -0
  111. package/lib/whatwg/is-abs-url.spec.js +8 -0
  112. package/lib/whatwg/is-browser-context-name.d.ts +11 -0
  113. package/lib/whatwg/is-browser-context-name.js +18 -0
  114. package/lib/whatwg/is-custom-element-name.d.ts +22 -0
  115. package/lib/whatwg/is-custom-element-name.js +77 -0
  116. package/lib/whatwg/is-itemprop-name.d.ts +12 -0
  117. package/lib/whatwg/is-itemprop-name.js +19 -0
  118. package/package.json +33 -0
  119. package/src/check-multi-types.ts +35 -0
  120. package/src/check.spec.ts +62 -0
  121. package/src/check.ts +48 -0
  122. package/src/css-syntax.spec.ts +167 -0
  123. package/src/css-syntax.ts +177 -0
  124. package/src/debug.ts +3 -0
  125. package/src/defs.ts +810 -0
  126. package/src/enum.ts +25 -0
  127. package/src/get-candicate.ts +24 -0
  128. package/src/index.ts +3 -0
  129. package/src/keyword-type.ts +52 -0
  130. package/src/list.spec.ts +133 -0
  131. package/src/list.ts +34 -0
  132. package/src/match-result.ts +49 -0
  133. package/src/number.ts +46 -0
  134. package/src/primitive/index.spec.ts +65 -0
  135. package/src/primitive/index.ts +7 -0
  136. package/src/primitive/is-float.ts +8 -0
  137. package/src/primitive/is-int.ts +8 -0
  138. package/src/primitive/is-non-zero-uint.ts +8 -0
  139. package/src/primitive/is-quantity.ts +38 -0
  140. package/src/primitive/is-uint.ts +15 -0
  141. package/src/primitive/range.ts +14 -0
  142. package/src/primitive/split-unit.ts +20 -0
  143. package/src/rfc/is-bcp-47.spec.ts +23 -0
  144. package/src/rfc/is-bcp-47.ts +13 -0
  145. package/src/token/index.ts +2 -0
  146. package/src/token/token-collection.spec.ts +147 -0
  147. package/src/token/token-collection.ts +444 -0
  148. package/src/token/token.ts +144 -0
  149. package/src/types.schema.ts +1059 -0
  150. package/src/types.ts +118 -0
  151. package/src/w3c/check-serialized-permissions-policy.spec.ts +27 -0
  152. package/src/w3c/check-serialized-permissions-policy.ts +287 -0
  153. package/src/whatwg/check-autocomplete.spec.ts +378 -0
  154. package/src/whatwg/check-autocomplete.ts +324 -0
  155. package/src/whatwg/check-datetime/date-string.ts +44 -0
  156. package/src/whatwg/check-datetime/datetime-tokens.ts +600 -0
  157. package/src/whatwg/check-datetime/duration-string.ts +399 -0
  158. package/src/whatwg/check-datetime/global-date-and-time-string.ts +96 -0
  159. package/src/whatwg/check-datetime/index.spec.ts +333 -0
  160. package/src/whatwg/check-datetime/index.ts +36 -0
  161. package/src/whatwg/check-datetime/local-date-and-time-string.ts +163 -0
  162. package/src/whatwg/check-datetime/month-string.ts +31 -0
  163. package/src/whatwg/check-datetime/time-string.ts +49 -0
  164. package/src/whatwg/check-datetime/time-zone-offset-string.ts +93 -0
  165. package/src/whatwg/check-datetime/week-string.ts +41 -0
  166. package/src/whatwg/check-datetime/year-string.ts +26 -0
  167. package/src/whatwg/check-datetime/yearless-date-string.ts +38 -0
  168. package/src/whatwg/check-mime-type.spec.ts +59 -0
  169. package/src/whatwg/check-mime-type.ts +46 -0
  170. package/src/whatwg/is-abs-url.spec.ts +8 -0
  171. package/src/whatwg/is-abs-url.ts +31 -0
  172. package/src/whatwg/is-browser-context-name.ts +16 -0
  173. package/src/whatwg/is-custom-element-name.ts +76 -0
  174. package/src/whatwg/is-itemprop-name.ts +17 -0
  175. package/tsconfig.test.json +3 -0
  176. package/tsconfig.tsbuildinfo +1 -0
  177. package/types.schema.json +1092 -0
@@ -0,0 +1,318 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const date_string_1 = require("./date-string");
5
+ const datetime_tokens_1 = require("./datetime-tokens");
6
+ const duration_string_1 = require("./duration-string");
7
+ const global_date_and_time_string_1 = require("./global-date-and-time-string");
8
+ const local_date_and_time_string_1 = require("./local-date-and-time-string");
9
+ const month_string_1 = require("./month-string");
10
+ const time_string_1 = require("./time-string");
11
+ const time_zone_offset_string_1 = require("./time-zone-offset-string");
12
+ const week_string_1 = require("./week-string");
13
+ const year_string_1 = require("./year-string");
14
+ const yearless_date_string_1 = require("./yearless-date-string");
15
+ const _1 = require(".");
16
+ const isMonth = (0, month_string_1.checkMonthString)();
17
+ const isDate = (0, date_string_1.checkDateString)();
18
+ const isYearlessDate = (0, yearless_date_string_1.checkYearlessDateString)();
19
+ const isTimeString = (0, time_string_1.checkTimeString)();
20
+ const isLocalDateAndTime = (0, local_date_and_time_string_1.checkLocalDateAndTimeString)();
21
+ const isNormalizedLocalDateAndTime = (0, local_date_and_time_string_1.checkNormalizedLocalDateAndTimeString)();
22
+ const isTimeZoneOffset = (0, time_zone_offset_string_1.checkTimeZoneOffsetString)();
23
+ const isGlobalDateAndTime = (0, global_date_and_time_string_1.checkGlobalDateAndTimeString)();
24
+ const isWeek = (0, week_string_1.checkWeekString)();
25
+ const isYear = (0, year_string_1.checkYearString)();
26
+ const isDurationISO8601Like = (0, duration_string_1.checkDurationISO8601LikeString)();
27
+ const isDurationComponentList = (0, duration_string_1.checkDurationComponentListString)();
28
+ const isDateTime = (0, _1.checkDateTime)();
29
+ test('max-week', () => {
30
+ expect((0, datetime_tokens_1.getMaxWeekNum)(1976)).toBe(53);
31
+ expect((0, datetime_tokens_1.getMaxWeekNum)(1977)).toBe(52);
32
+ expect((0, datetime_tokens_1.getMaxWeekNum)(1978)).toBe(52);
33
+ expect((0, datetime_tokens_1.getMaxWeekNum)(1979)).toBe(52);
34
+ expect((0, datetime_tokens_1.getMaxWeekNum)(1981)).toBe(53);
35
+ });
36
+ test('month-string', () => {
37
+ expect(isMonth('').reason).toBe('empty-token');
38
+ expect(isMonth(' ').reason).toBe('unexpected-token');
39
+ expect(isMonth('a').reason).toBe('unexpected-token');
40
+ expect(isMonth('0').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 4 });
41
+ expect(isMonth('0000').reason).toStrictEqual({ type: 'out-of-range', gt: 0 });
42
+ expect(isMonth('0001').reason).toBe('missing-token');
43
+ expect(isMonth('0001:').reason).toBe('unexpected-token');
44
+ expect(isMonth('0001-').reason).toBe('missing-token');
45
+ expect(isMonth('0001-a').reason).toBe('unexpected-token');
46
+ expect(isMonth('0001-0').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
47
+ expect(isMonth('0001-001').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
48
+ expect(isMonth('0001-00').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 12 });
49
+ expect(isMonth('0001-13').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 12 });
50
+ expect(isMonth('0001-01').matched).toBe(true);
51
+ expect(isMonth('0001-12').matched).toBe(true);
52
+ expect(isMonth('10001-01').matched).toBe(true);
53
+ expect(isMonth('0001-01-').reason).toBe('extra-token');
54
+ });
55
+ test('date-string', () => {
56
+ expect(isDate('').reason).toBe('empty-token');
57
+ expect(isDate(' ').reason).toBe('unexpected-token');
58
+ expect(isDate('a').reason).toBe('unexpected-token');
59
+ expect(isDate('0').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 4 });
60
+ expect(isDate('0000').reason).toStrictEqual({ type: 'out-of-range', gt: 0 });
61
+ expect(isDate('2000').reason).toBe('missing-token');
62
+ expect(isDate('2000:').reason).toBe('unexpected-token');
63
+ expect(isDate('2000-').reason).toBe('missing-token');
64
+ expect(isDate('2000-a').reason).toBe('unexpected-token');
65
+ expect(isDate('2000-0').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
66
+ expect(isDate('2000-00').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 12 });
67
+ expect(isDate('2000-01').reason).toBe('missing-token');
68
+ expect(isDate('2000-01:').reason).toBe('unexpected-token');
69
+ expect(isDate('2000-01-').reason).toBe('missing-token');
70
+ expect(isDate('2000-01-a').reason).toBe('unexpected-token');
71
+ expect(isDate('2000-01-0').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
72
+ expect(isDate('2000-01-001').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
73
+ expect(isDate('2000-01-00').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 31 });
74
+ expect(isDate('2000-01-01').matched).toBe(true);
75
+ expect(isDate('2000-01-31').matched).toBe(true);
76
+ expect(isDate('2000-01-32').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 31 });
77
+ expect(isDate('2000-02-28').matched).toBe(true);
78
+ expect(isDate('2000-02-29').matched).toBe(true);
79
+ expect(isDate('2000-02-30').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 29 });
80
+ expect(isDate('2001-02-28').matched).toBe(true);
81
+ expect(isDate('2001-02-29').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 28 });
82
+ });
83
+ test('yearless-date-string', () => {
84
+ expect(isYearlessDate('').reason).toBe('empty-token');
85
+ expect(isYearlessDate(' ').reason).toBe('unexpected-token');
86
+ expect(isYearlessDate('a').reason).toBe('unexpected-token');
87
+ expect(isYearlessDate('0').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
88
+ expect(isYearlessDate('00').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 12 });
89
+ expect(isYearlessDate('01').reason).toBe('missing-token');
90
+ expect(isYearlessDate('01:').reason).toBe('unexpected-token');
91
+ expect(isYearlessDate('01-').reason).toBe('missing-token');
92
+ expect(isYearlessDate('01-a').reason).toBe('unexpected-token');
93
+ expect(isYearlessDate('01-0').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
94
+ expect(isYearlessDate('01-00').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 31 });
95
+ expect(isYearlessDate('01-01').matched).toBe(true);
96
+ expect(isYearlessDate('01-31').matched).toBe(true);
97
+ expect(isYearlessDate('01-32').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 31 });
98
+ expect(isYearlessDate('02-28').matched).toBe(true);
99
+ expect(isYearlessDate('02-29').matched).toBe(true);
100
+ expect(isYearlessDate('02-30').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 29 });
101
+ });
102
+ test('time-string', () => {
103
+ expect(isTimeString('').reason).toBe('empty-token');
104
+ expect(isTimeString(' ').reason).toBe('unexpected-token');
105
+ expect(isTimeString('a').reason).toBe('unexpected-token');
106
+ expect(isTimeString('0').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
107
+ expect(isTimeString('000').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
108
+ expect(isTimeString('24').reason).toStrictEqual({ type: 'out-of-range', gte: 0, lte: 23 });
109
+ expect(isTimeString('00').reason).toBe('missing-token');
110
+ expect(isTimeString('00-').reason).toBe('unexpected-token');
111
+ expect(isTimeString('00:').reason).toBe('missing-token');
112
+ expect(isTimeString('00:a').reason).toBe('unexpected-token');
113
+ expect(isTimeString('00:0').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
114
+ expect(isTimeString('00:000').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
115
+ expect(isTimeString('00:00').matched).toBe(true);
116
+ expect(isTimeString('00:59').matched).toBe(true);
117
+ expect(isTimeString('00:60').reason).toStrictEqual({ type: 'out-of-range', gte: 0, lte: 59 });
118
+ expect(isTimeString('00:00-').reason).toBe('unexpected-token');
119
+ expect(isTimeString('00:00:').reason).toBe('missing-token');
120
+ expect(isTimeString('00:00:a').reason).toBe('unexpected-token');
121
+ expect(isTimeString('00:00:0').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
122
+ expect(isTimeString('00:00:000').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
123
+ expect(isTimeString('00:00:00').matched).toBe(true);
124
+ expect(isTimeString('00:00:59').matched).toBe(true);
125
+ expect(isTimeString('00:00:60').reason).toStrictEqual({ type: 'out-of-range', gte: 0, lte: 59 });
126
+ expect(isTimeString('00:00:00:').reason).toBe('unexpected-token');
127
+ expect(isTimeString('00:00:00.').reason).toBe('missing-token');
128
+ expect(isTimeString('00:00:00.a').reason).toBe('unexpected-token');
129
+ expect(isTimeString('00:00:00.0').matched).toBe(true);
130
+ expect(isTimeString('00:00:00.9').matched).toBe(true);
131
+ expect(isTimeString('00:00:00.00').matched).toBe(true);
132
+ expect(isTimeString('00:00:00.99').matched).toBe(true);
133
+ expect(isTimeString('00:00:00.000').matched).toBe(true);
134
+ expect(isTimeString('00:00:00.999').matched).toBe(true);
135
+ expect(isTimeString('00:00:00.0000').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 1, lte: 3 });
136
+ expect(isTimeString('00:00:00.1000').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 1, lte: 3 });
137
+ });
138
+ test('local-date-and-time-string', () => {
139
+ expect(isLocalDateAndTime('').reason).toBe('empty-token');
140
+ expect(isLocalDateAndTime(' ').reason).toBe('unexpected-token');
141
+ expect(isLocalDateAndTime('2020-12-31').reason).toBe('missing-token');
142
+ expect(isLocalDateAndTime('2020-12-31:').reason).toBe('unexpected-token');
143
+ expect(isLocalDateAndTime('2020-12-31T').reason).toBe('missing-token');
144
+ expect(isLocalDateAndTime('2020-12-31 ').reason).toBe('missing-token');
145
+ expect(isLocalDateAndTime('2020-12-31 ').reason).toBe('unexpected-token');
146
+ expect(isLocalDateAndTime('2020-12-31T00:00:00.000').matched).toBe(true);
147
+ });
148
+ test('normalized-local-date-and-time-string', () => {
149
+ expect(isNormalizedLocalDateAndTime('').reason).toBe('empty-token');
150
+ expect(isNormalizedLocalDateAndTime(' ').reason).toBe('unexpected-token');
151
+ expect(isNormalizedLocalDateAndTime('2020-12-31').reason).toBe('missing-token');
152
+ expect(isNormalizedLocalDateAndTime('2020-12-31:').reason).toBe('unexpected-token');
153
+ expect(isNormalizedLocalDateAndTime('2020-12-31T').reason).toBe('missing-token');
154
+ expect(isNormalizedLocalDateAndTime('2020-12-31 ').reason).toBe('unexpected-token');
155
+ expect(isNormalizedLocalDateAndTime('2020-12-31T00:00').matched).toBe(true);
156
+ expect(isNormalizedLocalDateAndTime('2020-12-31T00:00:00').reason).toBe('extra-token');
157
+ expect(isNormalizedLocalDateAndTime('2020-12-31T00:00:01').matched).toBe(true);
158
+ expect(isNormalizedLocalDateAndTime('2020-12-31T00:00:00.0').reason).toBe('extra-token');
159
+ expect(isNormalizedLocalDateAndTime('2020-12-31T00:00:00.00').reason).toBe('extra-token');
160
+ expect(isNormalizedLocalDateAndTime('2020-12-31T00:00:00.000').reason).toBe('extra-token');
161
+ expect(isNormalizedLocalDateAndTime('2020-12-31T00:00:00.001').matched).toBe(true);
162
+ });
163
+ test('time-zone-offset', () => {
164
+ expect(isTimeZoneOffset('').reason).toBe('empty-token');
165
+ expect(isTimeZoneOffset(' ').reason).toBe('unexpected-token');
166
+ expect(isTimeZoneOffset('a').reason).toBe('unexpected-token');
167
+ expect(isTimeZoneOffset('z').reason).toBe('unexpected-token');
168
+ expect(isTimeZoneOffset('Z').matched).toBe(true);
169
+ expect(isTimeZoneOffset('Z:').reason).toBe('extra-token');
170
+ expect(isTimeZoneOffset('ZZ').reason).toBe('extra-token');
171
+ expect(isTimeZoneOffset('+').reason).toBe('missing-token');
172
+ expect(isTimeZoneOffset('-').reason).toBe('missing-token');
173
+ expect(isTimeZoneOffset('+-').reason).toBe('unexpected-token');
174
+ expect(isTimeZoneOffset('+00').reason).toBe('missing-token');
175
+ expect(isTimeZoneOffset('+00:').reason).toBe('missing-token');
176
+ expect(isTimeZoneOffset('+00:00').matched).toBe(true);
177
+ expect(isTimeZoneOffset('+24:00').matched).toBe(false);
178
+ expect(isTimeZoneOffset('+00:60').matched).toBe(false);
179
+ expect(isTimeZoneOffset('+000:00').matched).toBe(false);
180
+ expect(isTimeZoneOffset('+00:000').matched).toBe(false);
181
+ expect(isTimeZoneOffset('+00:00:').reason).toBe('extra-token');
182
+ expect(isTimeZoneOffset('+0000').matched).toBe(true);
183
+ expect(isTimeZoneOffset('+2400').matched).toBe(false);
184
+ expect(isTimeZoneOffset('+0060').matched).toBe(false);
185
+ expect(isTimeZoneOffset('+00000').matched).toBe(false);
186
+ expect(isTimeZoneOffset('+0000:').reason).toBe('extra-token');
187
+ });
188
+ test('global-date-and-time-string', () => {
189
+ expect(isGlobalDateAndTime('2000-01-01').reason).toBe('missing-token');
190
+ expect(isGlobalDateAndTime('2000-01-01T00:00').reason).toBe('missing-token');
191
+ expect(isGlobalDateAndTime('2000-01-01T00:00').reason).toBe('missing-token');
192
+ expect(isGlobalDateAndTime('2000-01-01T00:00+').reason).toBe('missing-token');
193
+ expect(isGlobalDateAndTime('2000-01-01T00:00Z').matched).toBe(true);
194
+ expect(isGlobalDateAndTime('2000-01-01T00:00+00').reason).toBe('missing-token');
195
+ expect(isGlobalDateAndTime('2000-01-01T00:00+0000').matched).toBe(true);
196
+ expect(isGlobalDateAndTime('2000-01-01T00:00+00:00').matched).toBe(true);
197
+ expect(isGlobalDateAndTime('2000-01-01T00:00-2359').matched).toBe(true);
198
+ expect(isGlobalDateAndTime('2000-01-01T00:00-23:59').matched).toBe(true);
199
+ expect(isGlobalDateAndTime('2000-01-01T00:00:00+0000').matched).toBe(true);
200
+ expect(isGlobalDateAndTime('2000-01-01T00:00:00.000+0000').matched).toBe(true);
201
+ expect(isGlobalDateAndTime('2000-01-01T00:00:00.000+0000a').reason).toBe('extra-token');
202
+ });
203
+ test('week-string', () => {
204
+ expect(isWeek('').reason).toBe('empty-token');
205
+ expect(isWeek(' ').reason).toBe('unexpected-token');
206
+ expect(isWeek('a').reason).toBe('unexpected-token');
207
+ expect(isWeek('2000').reason).toBe('missing-token');
208
+ expect(isWeek('2000-').reason).toBe('missing-token');
209
+ expect(isWeek('2000-a').reason).toBe('unexpected-token');
210
+ expect(isWeek('2000-W').reason).toBe('missing-token');
211
+ expect(isWeek('2000-Wa').reason).toBe('unexpected-token');
212
+ expect(isWeek('2000-W0').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 2, lte: 2 });
213
+ expect(isWeek('2000-W00').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 52 });
214
+ expect(isWeek('2000-W53').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 52 });
215
+ expect(isWeek('2000-W01').matched).toBe(true);
216
+ expect(isWeek('2000-W52').matched).toBe(true);
217
+ expect(isWeek('2004-W00').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 53 });
218
+ expect(isWeek('2004-W54').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 53 });
219
+ expect(isWeek('2004-W01').matched).toBe(true);
220
+ expect(isWeek('2004-W53').matched).toBe(true);
221
+ expect(isWeek('2000-W01a').reason).toBe('extra-token');
222
+ });
223
+ test('year-string', () => {
224
+ expect(isYear('').reason).toBe('empty-token');
225
+ expect(isYear(' ').reason).toBe('unexpected-token');
226
+ expect(isYear('a').reason).toBe('unexpected-token');
227
+ expect(isYear('200').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 4 });
228
+ expect(isYear('2000').matched).toBe(true);
229
+ expect(isYear('20000').matched).toBe(true);
230
+ });
231
+ test('duration-string (IS08601 like)', () => {
232
+ expect(isDurationISO8601Like('').reason).toBe('empty-token');
233
+ expect(isDurationISO8601Like(' ').reason).toBe('unexpected-token');
234
+ expect(isDurationISO8601Like('a').reason).toBe('unexpected-token');
235
+ expect(isDurationISO8601Like('P').reason).toBe('missing-token');
236
+ expect(isDurationISO8601Like('P0').reason).toBe('missing-token');
237
+ expect(isDurationISO8601Like('P0D').reason).toBe('missing-token');
238
+ expect(isDurationISO8601Like('P0H').reason).toBe('unexpected-token');
239
+ expect(isDurationISO8601Like('P0Dt').reason).toBe('unexpected-token');
240
+ expect(isDurationISO8601Like('P0DT').reason).toBe('missing-token');
241
+ expect(isDurationISO8601Like('P0DT0').reason).toBe('missing-token');
242
+ expect(isDurationISO8601Like('P0DT0H').matched).toBe(true);
243
+ expect(isDurationISO8601Like('P0DT0H0').reason).toBe('missing-token');
244
+ expect(isDurationISO8601Like('P0DT0H0M').matched).toBe(true);
245
+ expect(isDurationISO8601Like('P0DT0H0M0').reason).toBe('missing-token');
246
+ expect(isDurationISO8601Like('P0DT0H0M0S').matched).toBe(true);
247
+ expect(isDurationISO8601Like('P0DT0H0M0.').reason).toBe('missing-token');
248
+ expect(isDurationISO8601Like('P0DT0H0M0M').reason).toBe('unexpected-token');
249
+ expect(isDurationISO8601Like('P0DT0H0M0.0').reason).toBe('missing-token');
250
+ expect(isDurationISO8601Like('P0DT0H0M0.0M').reason).toBe('unexpected-token');
251
+ expect(isDurationISO8601Like('P0DT0H0M0.000').reason).toBe('missing-token');
252
+ expect(isDurationISO8601Like('P0DT0H0M0.0000').reason).toStrictEqual({
253
+ gte: 1,
254
+ lte: 3,
255
+ type: 'out-of-range-length-digit',
256
+ });
257
+ expect(isDurationISO8601Like('P0DT0H0M0.000S').matched).toBe(true);
258
+ expect(isDurationISO8601Like('P0DT0H0M0.000S0').reason).toBe('extra-token');
259
+ expect(isDurationISO8601Like('P0DT0H0M0.000S0H').reason).toBe('extra-token');
260
+ expect(isDurationISO8601Like('P0DT0M').matched).toBe(true);
261
+ expect(isDurationISO8601Like('P0DT0S').matched).toBe(true);
262
+ expect(isDurationISO8601Like('P0DT0.0S').matched).toBe(true);
263
+ expect(isDurationISO8601Like('P0DT0M0S').matched).toBe(true);
264
+ expect(isDurationISO8601Like('P0DT0H0S').matched).toBe(true);
265
+ expect(isDurationISO8601Like('P0DT0H0.0S').matched).toBe(true);
266
+ expect(isDurationISO8601Like('P0DT0M0H').reason).toBe('unexpected-token');
267
+ expect(isDurationISO8601Like('P0DT0S0M').reason).toBe('extra-token');
268
+ expect(isDurationISO8601Like('P0DT0.0S0M').reason).toBe('extra-token');
269
+ expect(isDurationISO8601Like('PT4H18M3S').matched).toBe(true);
270
+ });
271
+ test('duration-string (duration component list)', () => {
272
+ expect(isDurationComponentList('').reason).toBe('empty-token');
273
+ expect(isDurationComponentList(' ').reason).toBe('missing-token');
274
+ expect(isDurationComponentList(' a').reason).toBe('unexpected-token');
275
+ expect(isDurationComponentList(' 0').reason).toBe('missing-token');
276
+ expect(isDurationComponentList(' 0a').reason).toBe('unexpected-token');
277
+ expect(isDurationComponentList(' 0w').matched).toBe(true);
278
+ expect(isDurationComponentList(' 0ww').reason).toBe('unexpected-token');
279
+ expect(isDurationComponentList('0w').matched).toBe(true);
280
+ expect(isDurationComponentList('0w ').matched).toBe(true);
281
+ expect(isDurationComponentList('0w 0').reason).toBe('missing-token');
282
+ expect(isDurationComponentList('0w 0w').reason).toBe('duplicated');
283
+ expect(isDurationComponentList('0w 0d').matched).toBe(true);
284
+ expect(isDurationComponentList('0w 0d').matched).toBe(true);
285
+ expect(isDurationComponentList(' 0w 0d').matched).toBe(true);
286
+ expect(isDurationComponentList(' 0w 0d ').matched).toBe(true);
287
+ expect(isDurationComponentList('0w 0d ').matched).toBe(true);
288
+ expect(isDurationComponentList('\n0w\n0d\n').matched).toBe(true);
289
+ expect(isDurationComponentList('0w 0.').reason).toBe('missing-token');
290
+ expect(isDurationComponentList('0w 0.0').reason).toBe('missing-token');
291
+ expect(isDurationComponentList('0w 0.0s').matched).toBe(true);
292
+ expect(isDurationComponentList('0w 0.0d').reason).toBe('unexpected-token');
293
+ expect(isDurationComponentList('0s 0.').reason).toBe('unexpected-token');
294
+ expect(isDurationComponentList('0s 0.0').reason).toBe('unexpected-token');
295
+ expect(isDurationComponentList('0s 0.0s').reason).toBe('unexpected-token');
296
+ expect(isDurationComponentList('0w 0.00s').matched).toBe(true);
297
+ expect(isDurationComponentList('0w 0.000s').matched).toBe(true);
298
+ expect(isDurationComponentList('0w 0.0000s').reason).toStrictEqual({
299
+ gte: 1,
300
+ lte: 3,
301
+ type: 'out-of-range-length-digit',
302
+ });
303
+ expect(isDurationComponentList('0s 0.000s').reason).toBe('unexpected-token');
304
+ expect(isDurationComponentList('0.000s 0s').reason).toBe('duplicated');
305
+ expect(isDurationComponentList('0w0d0h0m0.000s').matched).toBe(true);
306
+ expect(isDurationComponentList('0w 0d 0h 0m 0.000s').matched).toBe(true);
307
+ expect(isDurationComponentList('0w 0d0h 0m0.000s').matched).toBe(true);
308
+ expect(isDurationComponentList(' 2w 3d6m 3.4s 93xxxxxxx').reason).toBe('unexpected-token');
309
+ });
310
+ test('date-time', () => {
311
+ expect(isDateTime('200-1-1').reason).toStrictEqual({ type: 'out-of-range-length-digit', gte: 4 });
312
+ expect(isDateTime('2001-02-29').reason).toStrictEqual({ type: 'out-of-range', gte: 1, lte: 28 });
313
+ expect(isDateTime('2001-02-28T').reason).toBe('missing-token');
314
+ expect(isDateTime('2001-02-28T00').reason).toBe('missing-token');
315
+ expect(isDateTime('2001-02-28T00:0').reason).toStrictEqual({ gte: 2, lte: 2, type: 'out-of-range-length-digit' });
316
+ expect(isDateTime('2000-01-01T00:00:00.000+0000a').reason).toBe('extra-token');
317
+ expect(isDateTime('P0DT0M0H').reason).toBe('unexpected-token');
318
+ });
@@ -0,0 +1,9 @@
1
+ import type { CustomSyntaxChecker } from '../../types';
2
+ /**
3
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string
4
+ */
5
+ export declare const checkLocalDateAndTimeString: CustomSyntaxChecker;
6
+ /**
7
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-normalised-local-date-and-time-string
8
+ */
9
+ export declare const checkNormalizedLocalDateAndTimeString: CustomSyntaxChecker;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkNormalizedLocalDateAndTimeString = exports.checkLocalDateAndTimeString = void 0;
4
+ const debug_1 = require("../../debug");
5
+ const token_1 = require("../../token");
6
+ const datetime_tokens_1 = require("./datetime-tokens");
7
+ /**
8
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string
9
+ */
10
+ const checkLocalDateAndTimeString = () => function checkLocalDateAndTimeString(value) {
11
+ (0, debug_1.log)('CHECK: local-date-and-time-string');
12
+ const tokens = token_1.TokenCollection.fromPatterns(value, [
13
+ // YYYY
14
+ /[^-]*/,
15
+ // -
16
+ /[^0-9]?/,
17
+ // MM
18
+ /[^-]*/,
19
+ // -
20
+ /[^0-9]?/,
21
+ // DD
22
+ /[^T\s]*/,
23
+ // T
24
+ /[^0-9]?/,
25
+ // hh
26
+ /[^:]*/,
27
+ // :
28
+ /[^0-9]?/,
29
+ // mm
30
+ /[^:]*/,
31
+ // :
32
+ /[^0-9]?/,
33
+ // ss
34
+ /[^.]*/,
35
+ // .
36
+ /[^0-9]?/,
37
+ // sss
38
+ /.[0-9]*/,
39
+ ]);
40
+ (0, debug_1.log)('Local Date and Time: "%s" => %O', tokens.value, tokens);
41
+ const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.month, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.date, datetime_tokens_1.datetimeTokenCheck.localDateTimeSeparator, datetime_tokens_1.datetimeTokenCheck.hour, datetime_tokens_1.datetimeTokenCheck.coron, datetime_tokens_1.datetimeTokenCheck.minute, datetime_tokens_1.datetimeTokenCheck.coronOrEnd, datetime_tokens_1.datetimeTokenCheck.second, datetime_tokens_1.datetimeTokenCheck.decimalPointOrEnd, datetime_tokens_1.datetimeTokenCheck.secondFractionalPart, datetime_tokens_1.datetimeTokenCheck.extra);
42
+ if (!res.matched) {
43
+ (0, debug_1.log)('Failed: %O', res);
44
+ }
45
+ return res;
46
+ };
47
+ exports.checkLocalDateAndTimeString = checkLocalDateAndTimeString;
48
+ /**
49
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-normalised-local-date-and-time-string
50
+ */
51
+ const checkNormalizedLocalDateAndTimeString = () => function checkNormalizedLocalDateAndTimeString(value) {
52
+ (0, debug_1.log)('CHECK: normalized-local-date-and-time-string');
53
+ const tokens = token_1.TokenCollection.fromPatterns(value, [
54
+ // YYYY
55
+ /[^-]*/,
56
+ // -
57
+ /[^0-9]?/,
58
+ // MM
59
+ /[^-]*/,
60
+ // -
61
+ /[^0-9]?/,
62
+ // DD
63
+ /[^T]*/,
64
+ // T
65
+ /[^0-9]?/,
66
+ // hh
67
+ /[^:]*/,
68
+ // :
69
+ /[^0-9]?/,
70
+ // mm
71
+ /[^:]*/,
72
+ // :
73
+ /[^0-9]?/,
74
+ // ss
75
+ /[^.]*/,
76
+ // .
77
+ /[^0-9]?/,
78
+ // sss
79
+ /.[0-9]*/,
80
+ ]);
81
+ (0, debug_1.log)('Normalized Local Date and Time: "%s" => %O', tokens.value, tokens);
82
+ const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.month, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.date, datetime_tokens_1.datetimeTokenCheck.normalizedlocalDateTimeSeparator, datetime_tokens_1.datetimeTokenCheck.hour, datetime_tokens_1.datetimeTokenCheck.coron, datetime_tokens_1.datetimeTokenCheck.minute, datetime_tokens_1.datetimeTokenCheck.coronOrEnd, datetime_tokens_1.datetimeTokenCheck.second, datetime_tokens_1.datetimeTokenCheck.decimalPointOrEnd, datetime_tokens_1.datetimeTokenCheck.secondFractionalPart, datetime_tokens_1.datetimeTokenCheck.extra);
83
+ if (!res.matched) {
84
+ (0, debug_1.log)('Failed: %O', res);
85
+ return res;
86
+ }
87
+ /**
88
+ * > A valid time string representing the time,
89
+ * > expressed as the shortest possible string for the given time
90
+ * > (e.g. omitting the seconds component entirely
91
+ * > if the given time is zero seconds past the minute)
92
+ */
93
+ const [, , , , , , , , , , second, , fp] = tokens;
94
+ const _second = second.toNumber() || 0;
95
+ const _fp = fp.toNumber() || 0;
96
+ (0, debug_1.log)('Omitting the seconds component: "%s.%s" => %d, %d', second === null || second === void 0 ? void 0 : second.value, fp === null || fp === void 0 ? void 0 : fp.value, _second, _fp);
97
+ if (second.value && _second === 0 && (!fp.value || (fp.value && _fp === 0))) {
98
+ const res = second.unmatched({
99
+ partName: 'second',
100
+ reason: 'extra-token',
101
+ });
102
+ (0, debug_1.log)('Failed: %O', res);
103
+ return res;
104
+ }
105
+ if (fp.value && _fp === 0) {
106
+ const res = fp.unmatched({
107
+ partName: 'fractional part',
108
+ reason: 'extra-token',
109
+ });
110
+ (0, debug_1.log)('Failed: %O', res);
111
+ return res;
112
+ }
113
+ (0, debug_1.log)('Failed: %O', res);
114
+ return res;
115
+ };
116
+ exports.checkNormalizedLocalDateAndTimeString = checkNormalizedLocalDateAndTimeString;
@@ -0,0 +1,5 @@
1
+ import type { CustomSyntaxChecker } from '../../types';
2
+ /**
3
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-month-string
4
+ */
5
+ export declare const checkMonthString: CustomSyntaxChecker;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkMonthString = void 0;
4
+ const debug_1 = require("../../debug");
5
+ const token_1 = require("../../token");
6
+ const datetime_tokens_1 = require("./datetime-tokens");
7
+ /**
8
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-month-string
9
+ */
10
+ const checkMonthString = () => function checkMonthString(value) {
11
+ (0, debug_1.log)('CHECK: month-string');
12
+ const tokens = token_1.TokenCollection.fromPatterns(value, [/[^-]*/, /[^0-9]?/, /.[0-9]*/]);
13
+ (0, debug_1.log)('Month: "%s" => %O', tokens.value, tokens);
14
+ const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.month, datetime_tokens_1.datetimeTokenCheck.extra);
15
+ if (!res.matched) {
16
+ (0, debug_1.log)('Failed: %O', res);
17
+ }
18
+ return res;
19
+ };
20
+ exports.checkMonthString = checkMonthString;
@@ -0,0 +1,5 @@
1
+ import type { CustomSyntaxChecker } from '../../types';
2
+ /**
3
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#times
4
+ */
5
+ export declare const checkTimeString: CustomSyntaxChecker;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkTimeString = void 0;
4
+ const debug_1 = require("../../debug");
5
+ const token_1 = require("../../token");
6
+ const datetime_tokens_1 = require("./datetime-tokens");
7
+ /**
8
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#times
9
+ */
10
+ const checkTimeString = () => function checkTimeString(value) {
11
+ (0, debug_1.log)('CHECK: time-string');
12
+ const tokens = token_1.TokenCollection.fromPatterns(value, [
13
+ // hh
14
+ /[^:]*/,
15
+ // :
16
+ /[^0-9]?/,
17
+ // mm
18
+ /[^:]*/,
19
+ // :
20
+ /[^0-9]?/,
21
+ // ss
22
+ /[^.]*/,
23
+ // .
24
+ /[^0-9]?/,
25
+ // sss
26
+ /.[0-9]*/,
27
+ ]);
28
+ (0, debug_1.log)('Time: "%s" => %O', tokens.value, tokens);
29
+ const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.hour, datetime_tokens_1.datetimeTokenCheck.coron, datetime_tokens_1.datetimeTokenCheck.minute, datetime_tokens_1.datetimeTokenCheck.coronOrEnd, datetime_tokens_1.datetimeTokenCheck.second, datetime_tokens_1.datetimeTokenCheck.decimalPointOrEnd, datetime_tokens_1.datetimeTokenCheck.secondFractionalPart);
30
+ if (!res.matched) {
31
+ (0, debug_1.log)('Failed: %O', res);
32
+ }
33
+ return res;
34
+ };
35
+ exports.checkTimeString = checkTimeString;
@@ -0,0 +1,7 @@
1
+ import type { Token } from '../../token';
2
+ import type { CustomSyntaxChecker } from '../../types';
3
+ /**
4
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#time-zones
5
+ */
6
+ export declare const checkTimeZoneOffsetString: CustomSyntaxChecker;
7
+ export declare function parseTimeZone(zone: string | Token): import("../../types").Result;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTimeZone = exports.checkTimeZoneOffsetString = void 0;
4
+ const debug_1 = require("../../debug");
5
+ const match_result_1 = require("../../match-result");
6
+ const token_1 = require("../../token");
7
+ const datetime_tokens_1 = require("./datetime-tokens");
8
+ /**
9
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#time-zones
10
+ */
11
+ const checkTimeZoneOffsetString = () => function checkTimeZoneOffsetString(value) {
12
+ (0, debug_1.log)('CHECK: time-zone-offset-string');
13
+ return parseTimeZone(value);
14
+ };
15
+ exports.checkTimeZoneOffsetString = checkTimeZoneOffsetString;
16
+ function parseTimeZone(zone) {
17
+ const value = typeof zone === 'string' ? zone : zone.value;
18
+ const zoneTokens = token_1.TokenCollection.fromPatterns(zone, [
19
+ // Z + -
20
+ /[^0-9]?/,
21
+ // hh
22
+ /[^:]{0,2}/,
23
+ // :
24
+ /[^0-9]?/,
25
+ // mm
26
+ /.[0-9]*/,
27
+ ]);
28
+ (0, debug_1.log)('Time-zone Part: "%s" => %O', value, zoneTokens);
29
+ const res = zoneTokens.eachCheck((sign, tail) => {
30
+ if (!sign || !sign.value) {
31
+ return (0, match_result_1.unmatched)(value, 'missing-token', {
32
+ expects: [
33
+ { type: 'const', value: 'Z' },
34
+ { type: 'const', value: '+' },
35
+ { type: 'const', value: '-' },
36
+ ],
37
+ partName: 'time-zone',
38
+ });
39
+ }
40
+ if (sign.match('Z')) {
41
+ if (tail.value) {
42
+ return tail[0].unmatched({
43
+ reason: 'extra-token',
44
+ });
45
+ }
46
+ return (0, match_result_1.matched)();
47
+ }
48
+ if (!sign.match(['+', '-'])) {
49
+ return sign.unmatched({
50
+ reason: 'unexpected-token',
51
+ expects: [
52
+ { type: 'const', value: '+' },
53
+ { type: 'const', value: '-' },
54
+ ],
55
+ partName: 'time-zone',
56
+ });
57
+ }
58
+ }, datetime_tokens_1.datetimeTokenCheck.hour, coron => {
59
+ if (!coron || !coron.value) {
60
+ return;
61
+ }
62
+ if (!coron.match(':')) {
63
+ return coron.unmatched({
64
+ reason: 'unexpected-token',
65
+ expects: [{ type: 'const', value: ':' }],
66
+ partName: 'time-zone',
67
+ });
68
+ }
69
+ }, datetime_tokens_1.datetimeTokenCheck.minute, datetime_tokens_1.datetimeTokenCheck.extra);
70
+ if (!res.matched) {
71
+ (0, debug_1.log)('Failed: %O', res);
72
+ }
73
+ return res;
74
+ }
75
+ exports.parseTimeZone = parseTimeZone;
@@ -0,0 +1,5 @@
1
+ import type { CustomSyntaxChecker } from '../../types';
2
+ /**
3
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#weeks
4
+ */
5
+ export declare const checkWeekString: CustomSyntaxChecker;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkWeekString = void 0;
4
+ const debug_1 = require("../../debug");
5
+ const token_1 = require("../../token");
6
+ const datetime_tokens_1 = require("./datetime-tokens");
7
+ /**
8
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#weeks
9
+ */
10
+ const checkWeekString = () => function checkWeekString(value) {
11
+ (0, debug_1.log)('CHECK: week-string');
12
+ const tokens = token_1.TokenCollection.fromPatterns(value, [
13
+ // YYYY
14
+ /[^-]+/,
15
+ // -
16
+ /[^W]?/,
17
+ // W
18
+ /[^0-9]?/,
19
+ // ww
20
+ /.[0-9]*/,
21
+ ]);
22
+ (0, debug_1.log)('Week: "%s" => %O', tokens.value, tokens);
23
+ const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.weekSign, datetime_tokens_1.datetimeTokenCheck.week, datetime_tokens_1.datetimeTokenCheck.extra);
24
+ if (!res.matched) {
25
+ (0, debug_1.log)('Failed: %O', res);
26
+ }
27
+ return res;
28
+ };
29
+ exports.checkWeekString = checkWeekString;
@@ -0,0 +1,5 @@
1
+ import type { CustomSyntaxChecker } from '../../types';
2
+ /**
3
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html
4
+ */
5
+ export declare const checkYearString: CustomSyntaxChecker;