@markuplint/types 3.0.0-dev.24 → 3.0.0-dev.290

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 (173) hide show
  1. package/README.md +63 -61
  2. package/lib/check-multi-types.d.ts +2 -2
  3. package/lib/check-multi-types.js +9 -13
  4. package/lib/check.d.ts +7 -6
  5. package/lib/check.js +20 -30
  6. package/lib/css-syntax.d.ts +1 -1
  7. package/lib/css-syntax.js +60 -63
  8. package/lib/debug.js +2 -6
  9. package/lib/defs.d.ts +1 -1
  10. package/lib/defs.js +163 -91
  11. package/lib/enum.d.ts +4 -3
  12. package/lib/enum.js +7 -12
  13. package/lib/get-candidate.d.ts +1 -1
  14. package/lib/get-candidate.js +3 -8
  15. package/lib/index.d.ts +3 -3
  16. package/lib/index.js +3 -6
  17. package/lib/keyword-type.d.ts +2 -2
  18. package/lib/keyword-type.js +17 -21
  19. package/lib/list.d.ts +4 -3
  20. package/lib/list.js +9 -13
  21. package/lib/match-result.d.ts +4 -4
  22. package/lib/match-result.js +6 -12
  23. package/lib/number.d.ts +3 -3
  24. package/lib/number.js +11 -15
  25. package/lib/primitive/index.d.ts +7 -7
  26. package/lib/primitive/index.js +7 -17
  27. package/lib/primitive/is-float.js +1 -5
  28. package/lib/primitive/is-int.js +1 -5
  29. package/lib/primitive/is-non-zero-uint.js +1 -5
  30. package/lib/primitive/is-quantity.d.ts +1 -1
  31. package/lib/primitive/is-quantity.js +9 -13
  32. package/lib/primitive/is-uint.d.ts +1 -1
  33. package/lib/primitive/is-uint.js +1 -5
  34. package/lib/primitive/range.js +1 -5
  35. package/lib/primitive/split-unit.js +3 -7
  36. package/lib/rfc/is-bcp-47.d.ts +1 -1
  37. package/lib/rfc/is-bcp-47.js +3 -7
  38. package/lib/token/index.d.ts +2 -2
  39. package/lib/token/index.js +2 -7
  40. package/lib/token/token-collection.d.ts +13 -13
  41. package/lib/token/token-collection.js +55 -50
  42. package/lib/token/token.d.ts +11 -10
  43. package/lib/token/token.js +16 -24
  44. package/lib/token/types.d.ts +3 -0
  45. package/lib/types.d.ts +47 -46
  46. package/lib/types.js +1 -2
  47. package/lib/types.schema.d.ts +2 -2
  48. package/lib/types.schema.js +1 -3
  49. package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
  50. package/lib/w3c/check-serialized-permissions-policy.js +16 -20
  51. package/lib/whatwg/check-autocomplete.d.ts +1 -1
  52. package/lib/whatwg/check-autocomplete.js +28 -32
  53. package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
  54. package/lib/whatwg/check-datetime/date-string.js +9 -13
  55. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -1
  56. package/lib/whatwg/check-datetime/datetime-tokens.js +43 -46
  57. package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
  58. package/lib/whatwg/check-datetime/duration-string.js +48 -44
  59. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
  60. package/lib/whatwg/check-datetime/global-date-and-time-string.js +17 -21
  61. package/lib/whatwg/check-datetime/index.d.ts +1 -1
  62. package/lib/whatwg/check-datetime/index.js +25 -29
  63. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
  64. package/lib/whatwg/check-datetime/local-date-and-time-string.js +25 -26
  65. package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
  66. package/lib/whatwg/check-datetime/month-string.js +9 -13
  67. package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
  68. package/lib/whatwg/check-datetime/time-string.js +9 -13
  69. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
  70. package/lib/whatwg/check-datetime/time-zone-offset-string.js +16 -21
  71. package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
  72. package/lib/whatwg/check-datetime/week-string.js +9 -13
  73. package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
  74. package/lib/whatwg/check-datetime/year-string.js +9 -13
  75. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
  76. package/lib/whatwg/check-datetime/yearless-date-string.js +9 -13
  77. package/lib/whatwg/check-mime-type.d.ts +1 -1
  78. package/lib/whatwg/check-mime-type.js +12 -18
  79. package/lib/whatwg/is-abs-url.d.ts +1 -1
  80. package/lib/whatwg/is-abs-url.js +1 -5
  81. package/lib/whatwg/is-browser-context-name.d.ts +3 -1
  82. package/lib/whatwg/is-browser-context-name.js +3 -5
  83. package/lib/whatwg/is-custom-element-name.d.ts +1 -1
  84. package/lib/whatwg/is-custom-element-name.js +1 -5
  85. package/lib/whatwg/is-itemprop-name.d.ts +1 -1
  86. package/lib/whatwg/is-itemprop-name.js +2 -6
  87. package/lib/whatwg/is-navigable-target-name.d.ts +11 -0
  88. package/lib/whatwg/is-navigable-target-name.js +20 -0
  89. package/package.json +19 -13
  90. package/types.schema.json +314 -311
  91. package/gen/specific-schema.json +0 -98
  92. package/gen/types.ts +0 -66
  93. package/lib/check.spec.js +0 -76
  94. package/lib/css-syntax.spec.d.ts +0 -1
  95. package/lib/css-syntax.spec.js +0 -157
  96. package/lib/list.spec.d.ts +0 -1
  97. package/lib/list.spec.js +0 -129
  98. package/lib/primitive/index.spec.d.ts +0 -1
  99. package/lib/primitive/index.spec.js +0 -62
  100. package/lib/rfc/is-bcp-47.spec.d.ts +0 -1
  101. package/lib/rfc/is-bcp-47.spec.js +0 -19
  102. package/lib/token/token-collection.spec.d.ts +0 -1
  103. package/lib/token/token-collection.spec.js +0 -144
  104. package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +0 -1
  105. package/lib/w3c/check-serialized-permissions-policy.spec.js +0 -34
  106. package/lib/whatwg/check-autocomplete.spec.d.ts +0 -1
  107. package/lib/whatwg/check-autocomplete.spec.js +0 -379
  108. package/lib/whatwg/check-datetime/index.spec.d.ts +0 -1
  109. package/lib/whatwg/check-datetime/index.spec.js +0 -318
  110. package/lib/whatwg/check-mime-type.spec.d.ts +0 -1
  111. package/lib/whatwg/check-mime-type.spec.js +0 -58
  112. package/lib/whatwg/is-abs-url.spec.d.ts +0 -1
  113. package/lib/whatwg/is-abs-url.spec.js +0 -8
  114. package/patches/css-tree+2.3.1.patch +0 -23
  115. package/src/check-multi-types.ts +0 -35
  116. package/src/check.spec.ts +0 -83
  117. package/src/check.ts +0 -48
  118. package/src/css-syntax.spec.ts +0 -167
  119. package/src/css-syntax.ts +0 -188
  120. package/src/debug.ts +0 -3
  121. package/src/defs.ts +0 -811
  122. package/src/enum.ts +0 -25
  123. package/src/get-candidate.ts +0 -24
  124. package/src/index.ts +0 -3
  125. package/src/keyword-type.ts +0 -64
  126. package/src/list.spec.ts +0 -133
  127. package/src/list.ts +0 -34
  128. package/src/match-result.ts +0 -49
  129. package/src/number.ts +0 -46
  130. package/src/primitive/index.spec.ts +0 -65
  131. package/src/primitive/index.ts +0 -7
  132. package/src/primitive/is-float.ts +0 -8
  133. package/src/primitive/is-int.ts +0 -8
  134. package/src/primitive/is-non-zero-uint.ts +0 -8
  135. package/src/primitive/is-quantity.ts +0 -38
  136. package/src/primitive/is-uint.ts +0 -15
  137. package/src/primitive/range.ts +0 -14
  138. package/src/primitive/split-unit.ts +0 -20
  139. package/src/rfc/is-bcp-47.spec.ts +0 -23
  140. package/src/rfc/is-bcp-47.ts +0 -13
  141. package/src/token/index.ts +0 -2
  142. package/src/token/token-collection.spec.ts +0 -147
  143. package/src/token/token-collection.ts +0 -444
  144. package/src/token/token.ts +0 -144
  145. package/src/types.schema.ts +0 -1113
  146. package/src/types.ts +0 -118
  147. package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
  148. package/src/w3c/check-serialized-permissions-policy.ts +0 -303
  149. package/src/whatwg/check-autocomplete.spec.ts +0 -387
  150. package/src/whatwg/check-autocomplete.ts +0 -380
  151. package/src/whatwg/check-datetime/date-string.ts +0 -44
  152. package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
  153. package/src/whatwg/check-datetime/duration-string.ts +0 -399
  154. package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
  155. package/src/whatwg/check-datetime/index.spec.ts +0 -333
  156. package/src/whatwg/check-datetime/index.ts +0 -36
  157. package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
  158. package/src/whatwg/check-datetime/month-string.ts +0 -31
  159. package/src/whatwg/check-datetime/time-string.ts +0 -49
  160. package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
  161. package/src/whatwg/check-datetime/week-string.ts +0 -41
  162. package/src/whatwg/check-datetime/year-string.ts +0 -26
  163. package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
  164. package/src/whatwg/check-mime-type.spec.ts +0 -59
  165. package/src/whatwg/check-mime-type.ts +0 -46
  166. package/src/whatwg/is-abs-url.spec.ts +0 -8
  167. package/src/whatwg/is-abs-url.ts +0 -31
  168. package/src/whatwg/is-browser-context-name.ts +0 -16
  169. package/src/whatwg/is-custom-element-name.ts +0 -76
  170. package/src/whatwg/is-itemprop-name.ts +0 -17
  171. package/tsconfig.test.json +0 -3
  172. package/tsconfig.tsbuildinfo +0 -1
  173. /package/lib/{check.spec.d.ts → token/types.js} +0 -0
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMaxWeekNum = exports.datetimeTokenCheck = void 0;
4
- const debug_1 = require("../../debug");
5
- const match_result_1 = require("../../match-result");
6
- exports.datetimeTokenCheck = {
1
+ import { log } from '../../debug.js';
2
+ import { matched, unmatched } from '../../match-result.js';
3
+ export const datetimeTokenCheck = {
7
4
  /**
8
5
  * Temporary year state
9
6
  */
@@ -16,10 +13,10 @@ exports.datetimeTokenCheck = {
16
13
  * > Four or more ASCII digits, representing year, where year > 0
17
14
  */
18
15
  year(year) {
19
- (0, debug_1.log)('Parsing Datetime Year: "%s"', year === null || year === void 0 ? void 0 : year.value);
16
+ log('Parsing Datetime Year: "%s"', year?.value);
20
17
  this._year = null;
21
18
  if (!year || !year.value) {
22
- return (0, match_result_1.unmatched)('', 'missing-token', {
19
+ return unmatched('', 'missing-token', {
23
20
  expects: [{ type: 'common', value: 'year' }],
24
21
  partName: 'year',
25
22
  });
@@ -51,10 +48,10 @@ exports.datetimeTokenCheck = {
51
48
  * > Two ASCII digits, representing the month month, in the range 1 ≤ month ≤ 12
52
49
  */
53
50
  month(month) {
54
- (0, debug_1.log)('Parsing Datetime Month: "%s"', month === null || month === void 0 ? void 0 : month.value);
51
+ log('Parsing Datetime Month: "%s"', month?.value);
55
52
  this._month = null;
56
53
  if (!month || !month.value) {
57
- return (0, match_result_1.unmatched)('', 'missing-token', {
54
+ return unmatched('', 'missing-token', {
58
55
  expects: [{ type: 'common', value: 'month' }],
59
56
  partName: 'month',
60
57
  });
@@ -95,9 +92,9 @@ exports.datetimeTokenCheck = {
95
92
  * > then the day can be 29, as if the year was a leap year.
96
93
  */
97
94
  date(date) {
98
- (0, debug_1.log)('Parsing Datetime Date: "%s"', date === null || date === void 0 ? void 0 : date.value);
95
+ log('Parsing Datetime Date: "%s"', date?.value);
99
96
  if (!date || !date.value) {
100
- return (0, match_result_1.unmatched)('', 'missing-token', {
97
+ return unmatched('', 'missing-token', {
101
98
  expects: [{ type: 'common', value: 'date' }],
102
99
  partName: 'date',
103
100
  });
@@ -117,13 +114,13 @@ exports.datetimeTokenCheck = {
117
114
  });
118
115
  }
119
116
  // Set the leap year if _year is null
120
- const year = this._year || 2000;
117
+ const year = this._year ?? 2000;
121
118
  const isLeap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
122
- const month = this._month || 1;
123
- const dayOfMonth = daysOfMonth[month] + (month === 2 && isLeap ? 1 : 0);
119
+ const month = this._month ?? 1;
120
+ const dayOfMonth = (daysOfMonth[month] ?? 0) + (month === 2 && isLeap ? 1 : 0);
124
121
  const _date = date.toNumber();
125
- (0, debug_1.log)('Temporary Year and Month: %s, %s', this._year, this._month);
126
- (0, debug_1.log)('Computed Year, Month, and Day of Month: %s, %s, %s', year, month, dayOfMonth);
122
+ log('Temporary Year and Month: %s, %s', this._year, this._month);
123
+ log('Computed Year, Month, and Day of Month: %s, %s, %s', year, month, dayOfMonth);
127
124
  if (!(1 <= _date && _date <= dayOfMonth)) {
128
125
  return date.unmatched({
129
126
  reason: { type: 'out-of-range', gte: 1, lte: dayOfMonth },
@@ -136,9 +133,9 @@ exports.datetimeTokenCheck = {
136
133
  * > Two ASCII digits, representing hour, in the range 0 ≤ hour ≤ 23
137
134
  */
138
135
  hour(hour) {
139
- (0, debug_1.log)('Parsing Datetime Hour: "%s"', hour === null || hour === void 0 ? void 0 : hour.value);
136
+ log('Parsing Datetime Hour: "%s"', hour?.value);
140
137
  if (!hour || !hour.value) {
141
- return (0, match_result_1.unmatched)('', 'missing-token', {
138
+ return unmatched('', 'missing-token', {
142
139
  expects: [{ type: 'common', value: 'hour' }],
143
140
  partName: 'hour',
144
141
  });
@@ -170,9 +167,9 @@ exports.datetimeTokenCheck = {
170
167
  * > Two ASCII digits, representing minute, in the range 0 ≤ minute ≤ 59
171
168
  */
172
169
  minute(minute) {
173
- (0, debug_1.log)('Parsing Datetime Minute: "%s"', minute === null || minute === void 0 ? void 0 : minute.value);
170
+ log('Parsing Datetime Minute: "%s"', minute?.value);
174
171
  if (!minute || !minute.value) {
175
- return (0, match_result_1.unmatched)('', 'missing-token', {
172
+ return unmatched('', 'missing-token', {
176
173
  expects: [{ type: 'common', value: 'minute' }],
177
174
  partName: 'minute',
178
175
  });
@@ -204,9 +201,9 @@ exports.datetimeTokenCheck = {
204
201
  * > Two ASCII digits, representing the integer part of second, in the range 0 ≤ s ≤ 59
205
202
  */
206
203
  second(second) {
207
- (0, debug_1.log)('Parsing Datetime Second: "%s"', second === null || second === void 0 ? void 0 : second.value);
204
+ log('Parsing Datetime Second: "%s"', second?.value);
208
205
  if (!second || !second.value) {
209
- return (0, match_result_1.unmatched)('', 'missing-token', {
206
+ return unmatched('', 'missing-token', {
210
207
  expects: [{ type: 'common', value: 'second' }],
211
208
  partName: 'second',
212
209
  });
@@ -238,9 +235,9 @@ exports.datetimeTokenCheck = {
238
235
  * > One, two, or three ASCII digits, representing the fractional part of second
239
236
  */
240
237
  secondFractionalPart(secondFP) {
241
- (0, debug_1.log)('Parsing Datetime Second Fractional Part: "%s"', secondFP === null || secondFP === void 0 ? void 0 : secondFP.value);
238
+ log('Parsing Datetime Second Fractional Part: "%s"', secondFP?.value);
242
239
  if (!secondFP || !secondFP.value) {
243
- return (0, match_result_1.unmatched)('', 'missing-token', {
240
+ return unmatched('', 'missing-token', {
244
241
  expects: [{ type: 'common', value: 'fractional part' }],
245
242
  partName: 'fractional part',
246
243
  });
@@ -264,9 +261,9 @@ exports.datetimeTokenCheck = {
264
261
  * > Two ASCII digits, representing the week week, in the range 1 ≤ week ≤ maxweek, where maxweek is the week number of the last day of week-year year
265
262
  */
266
263
  week(week) {
267
- (0, debug_1.log)('Parsing Datetime Week: "%s"', week === null || week === void 0 ? void 0 : week.value);
264
+ log('Parsing Datetime Week: "%s"', week?.value);
268
265
  if (!week || !week.value) {
269
- return (0, match_result_1.unmatched)('', 'missing-token', {
266
+ return unmatched('', 'missing-token', {
270
267
  expects: [{ type: 'common', value: 'week' }],
271
268
  partName: 'week',
272
269
  });
@@ -285,7 +282,7 @@ exports.datetimeTokenCheck = {
285
282
  partName: 'week',
286
283
  });
287
284
  }
288
- const maxweek = getMaxWeekNum(this._year || 0);
285
+ const maxweek = getMaxWeekNum(this._year ?? 0);
289
286
  const _week = week.toNumber();
290
287
  if (!(1 <= _week && _week <= maxweek)) {
291
288
  return week.unmatched({
@@ -299,9 +296,9 @@ exports.datetimeTokenCheck = {
299
296
  * > A U+002D HYPHEN-MINUS character (-)
300
297
  */
301
298
  hyphen(hyphen) {
302
- (0, debug_1.log)('Parsing Datetime hyphen: "%s"', hyphen === null || hyphen === void 0 ? void 0 : hyphen.value);
299
+ log('Parsing Datetime hyphen: "%s"', hyphen?.value);
303
300
  if (!hyphen || !hyphen.value) {
304
- return (0, match_result_1.unmatched)('', 'missing-token', {
301
+ return unmatched('', 'missing-token', {
305
302
  expects: [{ type: 'common', value: 'hyphen' }],
306
303
  partName: 'datetime',
307
304
  });
@@ -318,9 +315,9 @@ exports.datetimeTokenCheck = {
318
315
  * > A U+003A COLON character (:)
319
316
  */
320
317
  colon(colon) {
321
- (0, debug_1.log)('Parsing Datetime colon: "%s"', colon === null || colon === void 0 ? void 0 : colon.value);
318
+ log('Parsing Datetime colon: "%s"', colon?.value);
322
319
  if (!colon || !colon.value) {
323
- return (0, match_result_1.unmatched)('', 'missing-token', {
320
+ return unmatched('', 'missing-token', {
324
321
  expects: [{ type: 'common', value: 'colon' }],
325
322
  partName: 'time',
326
323
  });
@@ -340,7 +337,7 @@ exports.datetimeTokenCheck = {
340
337
  */
341
338
  colonOrEnd(colon) {
342
339
  if (!colon || !colon.value) {
343
- return (0, match_result_1.matched)();
340
+ return matched();
344
341
  }
345
342
  if (!colon.match(':')) {
346
343
  return colon.unmatched({
@@ -357,7 +354,7 @@ exports.datetimeTokenCheck = {
357
354
  */
358
355
  decimalPointOrEnd(dot) {
359
356
  if (!dot || !dot.value) {
360
- return (0, match_result_1.matched)();
357
+ return matched();
361
358
  }
362
359
  if (!dot.match('.')) {
363
360
  return dot.unmatched({
@@ -371,9 +368,9 @@ exports.datetimeTokenCheck = {
371
368
  * > A U+0054 LATIN CAPITAL LETTER T character (T) or a U+0020 SPACE character
372
369
  */
373
370
  localDateTimeSeparator(sep) {
374
- (0, debug_1.log)('Parsing Datetime Local-Date-Time separator: "%s"', sep === null || sep === void 0 ? void 0 : sep.value);
371
+ log('Parsing Datetime Local-Date-Time separator: "%s"', sep?.value);
375
372
  if (!sep || !sep.value) {
376
- return (0, match_result_1.unmatched)('', 'missing-token', {
373
+ return unmatched('', 'missing-token', {
377
374
  expects: [
378
375
  { type: 'const', value: 'T' },
379
376
  { type: 'common', value: 'space' },
@@ -394,9 +391,9 @@ exports.datetimeTokenCheck = {
394
391
  * > A U+0054 LATIN CAPITAL LETTER T character (T)
395
392
  */
396
393
  normalizedlocalDateTimeSeparator(sep) {
397
- (0, debug_1.log)('Parsing Datetime Normalized-Local-Date-Time separator: %s', sep === null || sep === void 0 ? void 0 : sep.value);
394
+ log('Parsing Datetime Normalized-Local-Date-Time separator: %s', sep?.value);
398
395
  if (!sep || !sep.value) {
399
- return (0, match_result_1.unmatched)('', 'missing-token', {
396
+ return unmatched('', 'missing-token', {
400
397
  expects: [{ type: 'const', value: 'T' }],
401
398
  });
402
399
  }
@@ -415,7 +412,7 @@ exports.datetimeTokenCheck = {
415
412
  */
416
413
  plusOrMinusSign(colon) {
417
414
  if (!colon) {
418
- return (0, match_result_1.unmatched)('', 'missing-token', {
415
+ return unmatched('', 'missing-token', {
419
416
  expects: [
420
417
  { type: 'const', value: '+' },
421
418
  { type: 'const', value: '-' },
@@ -438,9 +435,9 @@ exports.datetimeTokenCheck = {
438
435
  * > A U+0057 LATIN CAPITAL LETTER W character (W)
439
436
  */
440
437
  weekSign(weekSign) {
441
- (0, debug_1.log)('Parsing Datetime W sign: "%s"', weekSign === null || weekSign === void 0 ? void 0 : weekSign.value);
438
+ log('Parsing Datetime W sign: "%s"', weekSign?.value);
442
439
  if (!weekSign || !weekSign.value) {
443
- return (0, match_result_1.unmatched)('', 'missing-token', {
440
+ return unmatched('', 'missing-token', {
444
441
  expects: [{ type: 'const', value: 'W' }],
445
442
  partName: 'time-zone',
446
443
  });
@@ -457,7 +454,7 @@ exports.datetimeTokenCheck = {
457
454
  * Extra token
458
455
  */
459
456
  extra(extra) {
460
- (0, debug_1.log)('Parsing Datetime EXTRA STRING: "%s"', extra === null || extra === void 0 ? void 0 : extra.value);
457
+ log('Parsing Datetime EXTRA STRING: "%s"', extra?.value);
461
458
  if (extra && extra.value) {
462
459
  return extra.unmatched({
463
460
  reason: 'extra-token',
@@ -492,11 +489,12 @@ const daysOfMonth = [
492
489
  // 12
493
490
  31,
494
491
  ];
495
- function getMaxWeekNum(year) {
492
+ export function getMaxWeekNum(year) {
496
493
  let date = 31;
497
- while (date) {
494
+ while (date > 0) {
498
495
  const d = new Date(Date.UTC(year, 11, date, 0, 0, 0, 0));
499
- d.setDate(d.getDate() + 4 - (d.getDay() || 7));
496
+ const day = d.getDay();
497
+ d.setDate(d.getDate() + 4 - (day > 0 ? day : 7));
500
498
  const yearStart = new Date(d.getFullYear(), 0, 1);
501
499
  const weekNo = Math.ceil(((d.valueOf() - yearStart.valueOf()) / 86400000 + 1) / 7);
502
500
  if (weekNo !== 1) {
@@ -506,4 +504,3 @@ function getMaxWeekNum(year) {
506
504
  }
507
505
  return NaN;
508
506
  }
509
- exports.getMaxWeekNum = getMaxWeekNum;
@@ -1,4 +1,4 @@
1
- import type { CustomSyntaxChecker } from '../../types';
1
+ import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
3
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#durations
4
4
  */
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkDurationComponentListString = exports.checkDurationISO8601LikeString = 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");
1
+ import { log } from '../../debug.js';
2
+ import { matched, unmatched } from '../../match-result.js';
3
+ import { TokenCollection } from '../../token/index.js';
4
+ import { datetimeTokenCheck } from './datetime-tokens.js';
8
5
  /**
9
6
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#durations
10
7
  */
11
- const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeString(value) {
12
- (0, debug_1.log)('CHECK: duration-string (ISO8601 like)');
8
+ export const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeString(value) {
9
+ log('CHECK: duration-string (ISO8601 like)');
13
10
  // PnDTnHnMnS
14
- const tokens = token_1.TokenCollection.fromPatterns(value, [
11
+ const tokens = TokenCollection.fromPatterns(value, [
15
12
  // Start sign P
16
13
  /[^0-9T]?/,
17
14
  // date part
@@ -21,10 +18,10 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
21
18
  // Time part
22
19
  /.*/,
23
20
  ]);
24
- (0, debug_1.log)('Duration ISO8601: "%s" => %O', tokens.value, tokens);
21
+ log('Duration ISO8601: "%s" => %O', tokens.value, tokens);
25
22
  const res = tokens.eachCheck(p => {
26
23
  if (!p || !p.value) {
27
- return (0, match_result_1.unmatched)('', 'missing-token', {
24
+ return unmatched('', 'missing-token', {
28
25
  expects: [{ type: 'const', value: 'P' }],
29
26
  partName: 'duration',
30
27
  });
@@ -40,8 +37,11 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
40
37
  if (!d || !d.value) {
41
38
  return;
42
39
  }
43
- const [num, sign, extra] = token_1.TokenCollection.fromPatterns(d, [/[0-9]+/, /./]);
44
- (0, debug_1.log)('Date part: "%s" => %O', d.value, { num, sign });
40
+ const [num, sign, extra] = TokenCollection.fromPatterns(d, [/[0-9]+/, /./]);
41
+ if (!num) {
42
+ return;
43
+ }
44
+ log('Date part: "%s" => %O', d.value, { num, sign });
45
45
  if (!num.match(/^[0-9]+$/)) {
46
46
  return num.unmatched({
47
47
  reason: 'unexpected-token',
@@ -50,7 +50,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
50
50
  });
51
51
  }
52
52
  if (!sign || !sign.value) {
53
- return (0, match_result_1.unmatched)('', 'missing-token', {
53
+ return unmatched('', 'missing-token', {
54
54
  expects: [{ type: 'const', value: 'D' }],
55
55
  partName: 'date',
56
56
  });
@@ -70,7 +70,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
70
70
  }
71
71
  }, t => {
72
72
  if (!t || !t.value) {
73
- return (0, match_result_1.unmatched)('', 'missing-token', {
73
+ return unmatched('', 'missing-token', {
74
74
  expects: [{ type: 'const', value: 'T' }],
75
75
  });
76
76
  }
@@ -82,7 +82,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
82
82
  }
83
83
  }, time => {
84
84
  if (!time) {
85
- return (0, match_result_1.unmatched)('', 'missing-token', {
85
+ return unmatched('', 'missing-token', {
86
86
  expects: [
87
87
  { type: 'common', value: 'hour' },
88
88
  { type: 'common', value: 'minute' },
@@ -91,7 +91,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
91
91
  partName: 'time',
92
92
  });
93
93
  }
94
- const timeTokens = token_1.TokenCollection.fromPatterns(time, [
94
+ const timeTokens = TokenCollection.fromPatterns(time, [
95
95
  // Hour part
96
96
  /[0-9]+(\.[0-9]*)?[^0-9]?/,
97
97
  // Minute part
@@ -99,10 +99,10 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
99
99
  // Second part
100
100
  /[0-9]+(\.[0-9]*)?[^0-9]?/,
101
101
  ]);
102
- (0, debug_1.log)('Time part: "%s" => %O', timeTokens.value, timeTokens);
102
+ log('Time part: "%s" => %O', timeTokens.value, timeTokens);
103
103
  const [h, m, s] = timeTokens;
104
- if (((h === null || h === void 0 ? void 0 : h.value) || '') + ((m === null || m === void 0 ? void 0 : m.value) || '') + ((s === null || s === void 0 ? void 0 : s.value) || '') === '') {
105
- return (0, match_result_1.unmatched)('', 'missing-token', {
104
+ if ((h?.value ?? '') + (m?.value ?? '') + (s?.value ?? '') === '') {
105
+ return unmatched('', 'missing-token', {
106
106
  expects: [
107
107
  { type: 'common', value: 'hour' },
108
108
  { type: 'common', value: 'minute' },
@@ -112,7 +112,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
112
112
  }
113
113
  const specified = new Set();
114
114
  for (const t of timeTokens) {
115
- if (!t || !t.value) {
115
+ if (!t.value) {
116
116
  continue;
117
117
  }
118
118
  if (specified.has('S')) {
@@ -120,8 +120,11 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
120
120
  reason: 'extra-token',
121
121
  });
122
122
  }
123
- const [num, dpfp, sign] = token_1.TokenCollection.fromPatterns(t, [/[0-9]+/, /(\.[0-9]*)?/, /[^0-9]+/]);
124
- (0, debug_1.log)('Time part (h|m|s): "%s" => %O', t.value, { num, dpfp, sign });
123
+ const [num, dpfp, sign] = TokenCollection.fromPatterns(t, [/[0-9]+/, /(\.[0-9]*)?/, /[^0-9]+/]);
124
+ if (!num) {
125
+ continue;
126
+ }
127
+ log('Time part (h|m|s): "%s" => %O', t.value, { num, dpfp, sign });
125
128
  if (!num.match(/^[0-9]+$/)) {
126
129
  return num.unmatched({
127
130
  reason: 'unexpected-token',
@@ -130,8 +133,11 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
130
133
  });
131
134
  }
132
135
  if (dpfp && dpfp.value) {
133
- const [dp, fp] = token_1.TokenCollection.fromPatterns(dpfp, [/\./, /[0-9]+/]);
134
- (0, debug_1.log)('Second fractional part (h|m|s): "%s" => %O', dpfp.value, { dp, fp });
136
+ const [dp, fp] = TokenCollection.fromPatterns(dpfp, [/\./, /[0-9]+/]);
137
+ if (!dp) {
138
+ continue;
139
+ }
140
+ log('Second fractional part (h|m|s): "%s" => %O', dpfp.value, { dp, fp });
135
141
  if (!dp.match('.')) {
136
142
  return dp.unmatched({
137
143
  reason: 'unexpected-token',
@@ -140,7 +146,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
140
146
  });
141
147
  }
142
148
  if (!fp || !fp.value) {
143
- return (0, match_result_1.unmatched)('', 'missing-token', {
149
+ return unmatched('', 'missing-token', {
144
150
  expects: [{ type: 'common', value: 'fractional part' }],
145
151
  partName: 'second',
146
152
  });
@@ -166,7 +172,7 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
166
172
  { type: 'const', value: 'S' },
167
173
  ];
168
174
  if (!sign || !sign.value) {
169
- return (0, match_result_1.unmatched)('', 'missing-token', {
175
+ return unmatched('', 'missing-token', {
170
176
  expects: expects.filter(e => !specified.has(e.value)),
171
177
  partName: 'time',
172
178
  });
@@ -189,17 +195,16 @@ const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeSt
189
195
  }
190
196
  specified.add(sign.value);
191
197
  }
192
- }, datetime_tokens_1.datetimeTokenCheck.extra);
198
+ }, datetimeTokenCheck.extra);
193
199
  if (!res.matched) {
194
- (0, debug_1.log)('Failed: %O', res);
200
+ log('Failed: %O', res);
195
201
  }
196
202
  return res;
197
203
  };
198
- exports.checkDurationISO8601LikeString = checkDurationISO8601LikeString;
199
- const checkDurationComponentListString = () => function checkDurationComponentListString(value) {
200
- (0, debug_1.log)('CHECK: duration-string (duration component list)');
204
+ export const checkDurationComponentListString = () => function checkDurationComponentListString(value) {
205
+ log('CHECK: duration-string (duration component list)');
201
206
  if (!value) {
202
- return (0, match_result_1.unmatched)('', 'empty-token', {
207
+ return unmatched('', 'empty-token', {
203
208
  expects: [{ type: 'common', value: 'time' }],
204
209
  });
205
210
  }
@@ -222,16 +227,16 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
222
227
  // 6. Zero or more ASCII whitespace.
223
228
  /\s*/,
224
229
  ];
225
- const tokens = token_1.TokenCollection.fromPatterns(value, patterns, { repeat: true });
230
+ const tokens = TokenCollection.fromPatterns(value, patterns, { repeat: true });
226
231
  const components = tokens.chunk(patterns.length);
227
232
  const specified = new Set();
228
233
  for (const component of components) {
229
- (0, debug_1.log)('Duration Component: "%s" => %O', component.value, component);
234
+ log('Duration Component: "%s" => %O', component.value, component);
230
235
  const [, , dpfp, , unit] = component;
231
236
  const res = component.eachCheck(ws => { }, num => {
232
237
  if (!num || !num.value) {
233
- const reason = (dpfp === null || dpfp === void 0 ? void 0 : dpfp.value) || (unit === null || unit === void 0 ? void 0 : unit.value) ? 'unexpected-token' : 'missing-token';
234
- return (0, match_result_1.unmatched)('', reason, {
238
+ const reason = dpfp?.value || unit?.value ? 'unexpected-token' : 'missing-token';
239
+ return unmatched('', reason, {
235
240
  expects: [{ type: 'common', value: 'time' }],
236
241
  });
237
242
  }
@@ -253,9 +258,9 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
253
258
  partName: 'unit',
254
259
  });
255
260
  }
256
- const [, fp] = token_1.TokenCollection.fromPatterns(dpfp, [/\./, /[0-9]+/]);
261
+ const [, fp] = TokenCollection.fromPatterns(dpfp, [/\./, /[0-9]+/]);
257
262
  if (!fp || !fp.value) {
258
- return (0, match_result_1.unmatched)('', 'missing-token', {
263
+ return unmatched('', 'missing-token', {
259
264
  expects: [{ type: 'common', value: 'fractional part' }],
260
265
  partName: 'fractional part',
261
266
  });
@@ -283,7 +288,7 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
283
288
  { type: 'const', value: 's' },
284
289
  ].filter(e => !specified.has(e.value));
285
290
  if (!unit || !unit.value) {
286
- return (0, match_result_1.unmatched)('', 'missing-token', {
291
+ return unmatched('', 'missing-token', {
287
292
  expects,
288
293
  partName: 'unit',
289
294
  });
@@ -313,10 +318,9 @@ const checkDurationComponentListString = () => function checkDurationComponentLi
313
318
  specified.add(unitVal);
314
319
  }, ws => { });
315
320
  if (!res.matched) {
316
- (0, debug_1.log)('Failed: %O', res);
321
+ log('Failed: %O', res);
317
322
  return res;
318
323
  }
319
324
  }
320
- return (0, match_result_1.matched)();
325
+ return matched();
321
326
  };
322
- exports.checkDurationComponentListString = checkDurationComponentListString;
@@ -1,4 +1,4 @@
1
- import type { CustomSyntaxChecker } from '../../types';
1
+ import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
3
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#global-dates-and-times
4
4
  */
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkGlobalDateAndTimeString = 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
- const time_zone_offset_string_1 = require("./time-zone-offset-string");
1
+ import { log } from '../../debug.js';
2
+ import { unmatched } from '../../match-result.js';
3
+ import { TokenCollection } from '../../token/index.js';
4
+ import { datetimeTokenCheck } from './datetime-tokens.js';
5
+ import { parseTimeZone } from './time-zone-offset-string.js';
9
6
  /**
10
7
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#global-dates-and-times
11
8
  */
12
- const checkGlobalDateAndTimeString = () => function checkGlobalDateAndTimeString(value) {
13
- (0, debug_1.log)('CHECK: global-date-and-time-string');
14
- const tokens = token_1.TokenCollection.fromPatterns(value, [
9
+ export const checkGlobalDateAndTimeString = () => function checkGlobalDateAndTimeString(value) {
10
+ log('CHECK: global-date-and-time-string');
11
+ const tokens = TokenCollection.fromPatterns(value, [
15
12
  // YYYY
16
13
  /[^-]*/,
17
14
  // -
@@ -35,32 +32,31 @@ const checkGlobalDateAndTimeString = () => function checkGlobalDateAndTimeString
35
32
  // time-zone
36
33
  /.*/,
37
34
  ]);
38
- (0, debug_1.log)('Global Date and Time "%s" => %O', tokens.value, tokens);
39
- 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.colon, datetime_tokens_1.datetimeTokenCheck.minute, second => {
35
+ log('Global Date and Time "%s" => %O', tokens.value, tokens);
36
+ const res = tokens.eachCheck(datetimeTokenCheck.year, datetimeTokenCheck.hyphen, datetimeTokenCheck.month, datetimeTokenCheck.hyphen, datetimeTokenCheck.date, datetimeTokenCheck.localDateTimeSeparator, datetimeTokenCheck.hour, datetimeTokenCheck.colon, datetimeTokenCheck.minute, second => {
40
37
  if (!second || !second.value) {
41
38
  return;
42
39
  }
43
- const secondTokens = token_1.TokenCollection.fromPatterns(second, [/:?/, /[0-9]*/, /\.?/, /[0-9]*/]);
44
- (0, debug_1.log)('Second Part: "%s" => %O', secondTokens.value, secondTokens);
45
- const res = secondTokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.colon, datetime_tokens_1.datetimeTokenCheck.second, datetime_tokens_1.datetimeTokenCheck.decimalPointOrEnd, datetime_tokens_1.datetimeTokenCheck.secondFractionalPart);
40
+ const secondTokens = TokenCollection.fromPatterns(second, [/:?/, /[0-9]*/, /\.?/, /[0-9]*/]);
41
+ log('Second Part: "%s" => %O', secondTokens.value, secondTokens);
42
+ const res = secondTokens.eachCheck(datetimeTokenCheck.colon, datetimeTokenCheck.second, datetimeTokenCheck.decimalPointOrEnd, datetimeTokenCheck.secondFractionalPart);
46
43
  if (!res.matched) {
47
44
  return res;
48
45
  }
49
46
  }, zone => {
50
47
  if (!zone || !zone.value) {
51
- return (0, match_result_1.unmatched)(value, 'missing-token', {
48
+ return unmatched(value, 'missing-token', {
52
49
  expects: [{ type: 'common', value: 'time-zone' }],
53
50
  partName: 'time-zone',
54
51
  });
55
52
  }
56
- const res = (0, time_zone_offset_string_1.parseTimeZone)(zone);
53
+ const res = parseTimeZone(zone);
57
54
  if (!res.matched) {
58
55
  return res;
59
56
  }
60
- }, datetime_tokens_1.datetimeTokenCheck.extra);
57
+ }, datetimeTokenCheck.extra);
61
58
  if (!res.matched) {
62
- (0, debug_1.log)('Failed: %O', res);
59
+ log('Failed: %O', res);
63
60
  }
64
61
  return res;
65
62
  };
66
- exports.checkGlobalDateAndTimeString = checkGlobalDateAndTimeString;
@@ -1,4 +1,4 @@
1
- import type { CustomSyntaxChecker } from '../../types';
1
+ import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
3
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates-and-times
4
4
  */
@@ -1,35 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkDateTime = void 0;
4
- const check_multi_types_1 = require("../../check-multi-types");
5
- const date_string_1 = require("./date-string");
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");
1
+ import { checkMultiTypes } from '../../check-multi-types.js';
2
+ import { checkDateString } from './date-string.js';
3
+ import { checkDurationComponentListString, checkDurationISO8601LikeString } from './duration-string.js';
4
+ import { checkGlobalDateAndTimeString } from './global-date-and-time-string.js';
5
+ import { checkLocalDateAndTimeString, checkNormalizedLocalDateAndTimeString } from './local-date-and-time-string.js';
6
+ import { checkMonthString } from './month-string.js';
7
+ import { checkTimeString } from './time-string.js';
8
+ import { checkTimeZoneOffsetString } from './time-zone-offset-string.js';
9
+ import { checkWeekString } from './week-string.js';
10
+ import { checkYearString } from './year-string.js';
11
+ import { checkYearlessDateString } from './yearless-date-string.js';
15
12
  const checks = [
16
- (0, date_string_1.checkDateString)(),
17
- (0, time_string_1.checkTimeString)(),
18
- (0, month_string_1.checkMonthString)(),
19
- (0, yearless_date_string_1.checkYearlessDateString)(),
20
- (0, local_date_and_time_string_1.checkLocalDateAndTimeString)(),
21
- (0, local_date_and_time_string_1.checkNormalizedLocalDateAndTimeString)(),
22
- (0, time_zone_offset_string_1.checkTimeZoneOffsetString)(),
23
- (0, global_date_and_time_string_1.checkGlobalDateAndTimeString)(),
24
- (0, week_string_1.checkWeekString)(),
25
- (0, year_string_1.checkYearString)(),
26
- (0, duration_string_1.checkDurationISO8601LikeString)(),
27
- (0, duration_string_1.checkDurationComponentListString)(),
13
+ checkDateString(),
14
+ checkTimeString(),
15
+ checkMonthString(),
16
+ checkYearlessDateString(),
17
+ checkLocalDateAndTimeString(),
18
+ checkNormalizedLocalDateAndTimeString(),
19
+ checkTimeZoneOffsetString(),
20
+ checkGlobalDateAndTimeString(),
21
+ checkWeekString(),
22
+ checkYearString(),
23
+ checkDurationISO8601LikeString(),
24
+ checkDurationComponentListString(),
28
25
  ];
29
26
  /**
30
27
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates-and-times
31
28
  */
32
- const checkDateTime = () => value => {
33
- return (0, check_multi_types_1.checkMultiTypes)(value, checks);
29
+ export const checkDateTime = () => value => {
30
+ return checkMultiTypes(value, checks);
34
31
  };
35
- exports.checkDateTime = checkDateTime;
@@ -1,4 +1,4 @@
1
- import type { CustomSyntaxChecker } from '../../types';
1
+ import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
3
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string
4
4
  */