@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.
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/extends.json +12 -0
- package/gen/specific-schema.json +98 -0
- package/gen/types.ts +66 -0
- package/lib/check-multi-types.d.ts +2 -0
- package/lib/check-multi-types.js +29 -0
- package/lib/check.d.ts +8 -0
- package/lib/check.js +49 -0
- package/lib/check.spec.d.ts +1 -0
- package/lib/check.spec.js +57 -0
- package/lib/css-syntax.d.ts +2 -0
- package/lib/css-syntax.js +141 -0
- package/lib/css-syntax.spec.d.ts +1 -0
- package/lib/css-syntax.spec.js +157 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.js +6 -0
- package/lib/defs.d.ts +3 -0
- package/lib/defs.js +752 -0
- package/lib/enum.d.ts +3 -0
- package/lib/enum.js +26 -0
- package/lib/get-candicate.d.ts +3 -0
- package/lib/get-candicate.js +26 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +6 -0
- package/lib/keyword-type.d.ts +3 -0
- package/lib/keyword-type.js +46 -0
- package/lib/list.d.ts +3 -0
- package/lib/list.js +29 -0
- package/lib/list.spec.d.ts +1 -0
- package/lib/list.spec.js +129 -0
- package/lib/match-result.d.ts +9 -0
- package/lib/match-result.js +33 -0
- package/lib/number.d.ts +3 -0
- package/lib/number.js +41 -0
- package/lib/primitive/index.d.ts +7 -0
- package/lib/primitive/index.js +17 -0
- package/lib/primitive/index.spec.d.ts +1 -0
- package/lib/primitive/index.spec.js +62 -0
- package/lib/primitive/is-float.d.ts +6 -0
- package/lib/primitive/is-float.js +12 -0
- package/lib/primitive/is-int.d.ts +6 -0
- package/lib/primitive/is-int.js +12 -0
- package/lib/primitive/is-non-zero-uint.d.ts +6 -0
- package/lib/primitive/is-non-zero-uint.js +12 -0
- package/lib/primitive/is-quantity.d.ts +7 -0
- package/lib/primitive/is-quantity.js +41 -0
- package/lib/primitive/is-uint.d.ts +8 -0
- package/lib/primitive/is-uint.js +19 -0
- package/lib/primitive/range.d.ts +8 -0
- package/lib/primitive/range.js +18 -0
- package/lib/primitive/split-unit.d.ts +9 -0
- package/lib/primitive/split-unit.js +24 -0
- package/lib/rfc/is-bcp-47.d.ts +5 -0
- package/lib/rfc/is-bcp-47.js +14 -0
- package/lib/rfc/is-bcp-47.spec.d.ts +1 -0
- package/lib/rfc/is-bcp-47.spec.js +19 -0
- package/lib/token/index.d.ts +2 -0
- package/lib/token/index.js +7 -0
- package/lib/token/token-collection.d.ts +62 -0
- package/lib/token/token-collection.js +383 -0
- package/lib/token/token-collection.spec.d.ts +1 -0
- package/lib/token/token-collection.spec.js +144 -0
- package/lib/token/token.d.ts +55 -0
- package/lib/token/token.js +128 -0
- package/lib/types.d.ts +78 -0
- package/lib/types.js +2 -0
- package/lib/types.schema.d.ts +54 -0
- package/lib/types.schema.js +8 -0
- package/lib/w3c/check-serialized-permissions-policy.d.ts +15 -0
- package/lib/w3c/check-serialized-permissions-policy.js +251 -0
- package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +1 -0
- package/lib/w3c/check-serialized-permissions-policy.spec.js +26 -0
- package/lib/whatwg/check-autocomplete.d.ts +5 -0
- package/lib/whatwg/check-autocomplete.js +282 -0
- package/lib/whatwg/check-autocomplete.spec.d.ts +1 -0
- package/lib/whatwg/check-autocomplete.spec.js +370 -0
- package/lib/whatwg/check-datetime/date-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/date-string.js +31 -0
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +3 -0
- package/lib/whatwg/check-datetime/datetime-tokens.js +509 -0
- package/lib/whatwg/check-datetime/duration-string.d.ts +6 -0
- package/lib/whatwg/check-datetime/duration-string.js +322 -0
- package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/global-date-and-time-string.js +66 -0
- package/lib/whatwg/check-datetime/index.d.ts +5 -0
- package/lib/whatwg/check-datetime/index.js +35 -0
- package/lib/whatwg/check-datetime/index.spec.d.ts +1 -0
- package/lib/whatwg/check-datetime/index.spec.js +318 -0
- package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +9 -0
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +116 -0
- package/lib/whatwg/check-datetime/month-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/month-string.js +20 -0
- package/lib/whatwg/check-datetime/time-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/time-string.js +35 -0
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +7 -0
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +75 -0
- package/lib/whatwg/check-datetime/week-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/week-string.js +29 -0
- package/lib/whatwg/check-datetime/year-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/year-string.js +20 -0
- package/lib/whatwg/check-datetime/yearless-date-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/yearless-date-string.js +27 -0
- package/lib/whatwg/check-mime-type.d.ts +11 -0
- package/lib/whatwg/check-mime-type.js +42 -0
- package/lib/whatwg/check-mime-type.spec.d.ts +1 -0
- package/lib/whatwg/check-mime-type.spec.js +58 -0
- package/lib/whatwg/is-abs-url.d.ts +15 -0
- package/lib/whatwg/is-abs-url.js +34 -0
- package/lib/whatwg/is-abs-url.spec.d.ts +1 -0
- package/lib/whatwg/is-abs-url.spec.js +8 -0
- package/lib/whatwg/is-browser-context-name.d.ts +11 -0
- package/lib/whatwg/is-browser-context-name.js +18 -0
- package/lib/whatwg/is-custom-element-name.d.ts +22 -0
- package/lib/whatwg/is-custom-element-name.js +77 -0
- package/lib/whatwg/is-itemprop-name.d.ts +12 -0
- package/lib/whatwg/is-itemprop-name.js +19 -0
- package/package.json +33 -0
- package/src/check-multi-types.ts +35 -0
- package/src/check.spec.ts +62 -0
- package/src/check.ts +48 -0
- package/src/css-syntax.spec.ts +167 -0
- package/src/css-syntax.ts +177 -0
- package/src/debug.ts +3 -0
- package/src/defs.ts +810 -0
- package/src/enum.ts +25 -0
- package/src/get-candicate.ts +24 -0
- package/src/index.ts +3 -0
- package/src/keyword-type.ts +52 -0
- package/src/list.spec.ts +133 -0
- package/src/list.ts +34 -0
- package/src/match-result.ts +49 -0
- package/src/number.ts +46 -0
- package/src/primitive/index.spec.ts +65 -0
- package/src/primitive/index.ts +7 -0
- package/src/primitive/is-float.ts +8 -0
- package/src/primitive/is-int.ts +8 -0
- package/src/primitive/is-non-zero-uint.ts +8 -0
- package/src/primitive/is-quantity.ts +38 -0
- package/src/primitive/is-uint.ts +15 -0
- package/src/primitive/range.ts +14 -0
- package/src/primitive/split-unit.ts +20 -0
- package/src/rfc/is-bcp-47.spec.ts +23 -0
- package/src/rfc/is-bcp-47.ts +13 -0
- package/src/token/index.ts +2 -0
- package/src/token/token-collection.spec.ts +147 -0
- package/src/token/token-collection.ts +444 -0
- package/src/token/token.ts +144 -0
- package/src/types.schema.ts +1059 -0
- package/src/types.ts +118 -0
- package/src/w3c/check-serialized-permissions-policy.spec.ts +27 -0
- package/src/w3c/check-serialized-permissions-policy.ts +287 -0
- package/src/whatwg/check-autocomplete.spec.ts +378 -0
- package/src/whatwg/check-autocomplete.ts +324 -0
- package/src/whatwg/check-datetime/date-string.ts +44 -0
- package/src/whatwg/check-datetime/datetime-tokens.ts +600 -0
- package/src/whatwg/check-datetime/duration-string.ts +399 -0
- package/src/whatwg/check-datetime/global-date-and-time-string.ts +96 -0
- package/src/whatwg/check-datetime/index.spec.ts +333 -0
- package/src/whatwg/check-datetime/index.ts +36 -0
- package/src/whatwg/check-datetime/local-date-and-time-string.ts +163 -0
- package/src/whatwg/check-datetime/month-string.ts +31 -0
- package/src/whatwg/check-datetime/time-string.ts +49 -0
- package/src/whatwg/check-datetime/time-zone-offset-string.ts +93 -0
- package/src/whatwg/check-datetime/week-string.ts +41 -0
- package/src/whatwg/check-datetime/year-string.ts +26 -0
- package/src/whatwg/check-datetime/yearless-date-string.ts +38 -0
- package/src/whatwg/check-mime-type.spec.ts +59 -0
- package/src/whatwg/check-mime-type.ts +46 -0
- package/src/whatwg/is-abs-url.spec.ts +8 -0
- package/src/whatwg/is-abs-url.ts +31 -0
- package/src/whatwg/is-browser-context-name.ts +16 -0
- package/src/whatwg/is-custom-element-name.ts +76 -0
- package/src/whatwg/is-itemprop-name.ts +17 -0
- package/tsconfig.test.json +3 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/types.schema.json +1092 -0
|
@@ -0,0 +1,509 @@
|
|
|
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 = {
|
|
7
|
+
/**
|
|
8
|
+
* Temporary year state
|
|
9
|
+
*/
|
|
10
|
+
_year: null,
|
|
11
|
+
/**
|
|
12
|
+
* Temporary month state
|
|
13
|
+
*/
|
|
14
|
+
_month: null,
|
|
15
|
+
/**
|
|
16
|
+
* > Four or more ASCII digits, representing year, where year > 0
|
|
17
|
+
*/
|
|
18
|
+
year(year) {
|
|
19
|
+
(0, debug_1.log)('Parsing Datetime Year: "%s"', year === null || year === void 0 ? void 0 : year.value);
|
|
20
|
+
this._year = null;
|
|
21
|
+
if (!year || !year.value) {
|
|
22
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
23
|
+
expects: [{ type: 'common', value: 'year' }],
|
|
24
|
+
partName: 'year',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (!year.match(/^[0-9]+$/)) {
|
|
28
|
+
return year.unmatched({
|
|
29
|
+
reason: 'unexpected-token',
|
|
30
|
+
expects: [],
|
|
31
|
+
partName: 'year',
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (year.length < 4) {
|
|
35
|
+
return year.unmatched({
|
|
36
|
+
reason: { type: 'out-of-range-length-digit', gte: 4 },
|
|
37
|
+
expects: [],
|
|
38
|
+
partName: 'year',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
this._year = year.toNumber();
|
|
42
|
+
if (this._year <= 0) {
|
|
43
|
+
return year.unmatched({
|
|
44
|
+
reason: { type: 'out-of-range', gt: 0 },
|
|
45
|
+
expects: [],
|
|
46
|
+
partName: 'year',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* > Two ASCII digits, representing the month month, in the range 1 ≤ month ≤ 12
|
|
52
|
+
*/
|
|
53
|
+
month(month) {
|
|
54
|
+
(0, debug_1.log)('Parsing Datetime Month: "%s"', month === null || month === void 0 ? void 0 : month.value);
|
|
55
|
+
this._month = null;
|
|
56
|
+
if (!month || !month.value) {
|
|
57
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
58
|
+
expects: [{ type: 'common', value: 'month' }],
|
|
59
|
+
partName: 'month',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (!month.match(/^[0-9]+$/)) {
|
|
63
|
+
return month.unmatched({
|
|
64
|
+
reason: 'unexpected-token',
|
|
65
|
+
expects: [],
|
|
66
|
+
partName: 'month',
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (month.length !== 2) {
|
|
70
|
+
return month.unmatched({
|
|
71
|
+
reason: { type: 'out-of-range-length-digit', gte: 2, lte: 2 },
|
|
72
|
+
expects: [],
|
|
73
|
+
partName: 'month',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
this._month = month.toNumber();
|
|
77
|
+
if (!(1 <= this._month && this._month <= 12)) {
|
|
78
|
+
return month.unmatched({
|
|
79
|
+
reason: { type: 'out-of-range', gte: 1, lte: 12 },
|
|
80
|
+
expects: [],
|
|
81
|
+
partName: 'month',
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* > Two ASCII digits, representing day, in the range 1 ≤ day ≤ maxday where maxday is the number of days in the month month and year year
|
|
87
|
+
*
|
|
88
|
+
* or
|
|
89
|
+
*
|
|
90
|
+
* In Yearless dates,
|
|
91
|
+
* > Two ASCII digits, representing day,
|
|
92
|
+
* > in the range 1 ≤ day ≤ maxday where maxday is the number of days
|
|
93
|
+
* > in the month month and any arbitrary leap year (e.g. 4 or 2000)
|
|
94
|
+
* > In other words, if the month is "02", meaning February,
|
|
95
|
+
* > then the day can be 29, as if the year was a leap year.
|
|
96
|
+
*/
|
|
97
|
+
date(date) {
|
|
98
|
+
(0, debug_1.log)('Parsing Datetime Date: "%s"', date === null || date === void 0 ? void 0 : date.value);
|
|
99
|
+
if (!date || !date.value) {
|
|
100
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
101
|
+
expects: [{ type: 'common', value: 'date' }],
|
|
102
|
+
partName: 'date',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (!date.match(/^[0-9]+$/)) {
|
|
106
|
+
return date.unmatched({
|
|
107
|
+
reason: 'unexpected-token',
|
|
108
|
+
expects: [],
|
|
109
|
+
partName: 'date',
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (date.length !== 2) {
|
|
113
|
+
return date.unmatched({
|
|
114
|
+
reason: { type: 'out-of-range-length-digit', gte: 2, lte: 2 },
|
|
115
|
+
expects: [],
|
|
116
|
+
partName: 'date',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
// Set the leap year if _year is null
|
|
120
|
+
const year = this._year || 2000;
|
|
121
|
+
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);
|
|
124
|
+
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);
|
|
127
|
+
if (!(1 <= _date && _date <= dayOfMonth)) {
|
|
128
|
+
return date.unmatched({
|
|
129
|
+
reason: { type: 'out-of-range', gte: 1, lte: dayOfMonth },
|
|
130
|
+
expects: [],
|
|
131
|
+
partName: 'date',
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
/**
|
|
136
|
+
* > Two ASCII digits, representing hour, in the range 0 ≤ hour ≤ 23
|
|
137
|
+
*/
|
|
138
|
+
hour(hour) {
|
|
139
|
+
(0, debug_1.log)('Parsing Datetime Hour: "%s"', hour === null || hour === void 0 ? void 0 : hour.value);
|
|
140
|
+
if (!hour || !hour.value) {
|
|
141
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
142
|
+
expects: [{ type: 'common', value: 'hour' }],
|
|
143
|
+
partName: 'hour',
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (!hour.match(/^[0-9]+$/)) {
|
|
147
|
+
return hour.unmatched({
|
|
148
|
+
reason: 'unexpected-token',
|
|
149
|
+
expects: [],
|
|
150
|
+
partName: 'hour',
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (hour.length !== 2) {
|
|
154
|
+
return hour.unmatched({
|
|
155
|
+
reason: { type: 'out-of-range-length-digit', gte: 2, lte: 2 },
|
|
156
|
+
expects: [],
|
|
157
|
+
partName: 'hour',
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
const _hour = hour.toNumber();
|
|
161
|
+
if (!(0 <= _hour && _hour <= 23)) {
|
|
162
|
+
return hour.unmatched({
|
|
163
|
+
reason: { type: 'out-of-range', gte: 0, lte: 23 },
|
|
164
|
+
expects: [],
|
|
165
|
+
partName: 'hour',
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
/**
|
|
170
|
+
* > Two ASCII digits, representing minute, in the range 0 ≤ minute ≤ 59
|
|
171
|
+
*/
|
|
172
|
+
minute(minute) {
|
|
173
|
+
(0, debug_1.log)('Parsing Datetime Minute: "%s"', minute === null || minute === void 0 ? void 0 : minute.value);
|
|
174
|
+
if (!minute || !minute.value) {
|
|
175
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
176
|
+
expects: [{ type: 'common', value: 'minute' }],
|
|
177
|
+
partName: 'minute',
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (!minute.match(/^[0-9]+$/)) {
|
|
181
|
+
return minute.unmatched({
|
|
182
|
+
reason: 'unexpected-token',
|
|
183
|
+
expects: [],
|
|
184
|
+
partName: 'minute',
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
if (minute.length !== 2) {
|
|
188
|
+
return minute.unmatched({
|
|
189
|
+
reason: { type: 'out-of-range-length-digit', gte: 2, lte: 2 },
|
|
190
|
+
expects: [],
|
|
191
|
+
partName: 'minute',
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
const _minute = minute.toNumber();
|
|
195
|
+
if (!(0 <= _minute && _minute <= 59)) {
|
|
196
|
+
return minute.unmatched({
|
|
197
|
+
reason: { type: 'out-of-range', gte: 0, lte: 59 },
|
|
198
|
+
expects: [],
|
|
199
|
+
partName: 'minute',
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
/**
|
|
204
|
+
* > Two ASCII digits, representing the integer part of second, in the range 0 ≤ s ≤ 59
|
|
205
|
+
*/
|
|
206
|
+
second(second) {
|
|
207
|
+
(0, debug_1.log)('Parsing Datetime Second: "%s"', second === null || second === void 0 ? void 0 : second.value);
|
|
208
|
+
if (!second || !second.value) {
|
|
209
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
210
|
+
expects: [{ type: 'common', value: 'second' }],
|
|
211
|
+
partName: 'second',
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (!second.match(/^[0-9]+$/)) {
|
|
215
|
+
return second.unmatched({
|
|
216
|
+
reason: 'unexpected-token',
|
|
217
|
+
expects: [],
|
|
218
|
+
partName: 'second',
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (second.length !== 2) {
|
|
222
|
+
return second.unmatched({
|
|
223
|
+
reason: { type: 'out-of-range-length-digit', gte: 2, lte: 2 },
|
|
224
|
+
expects: [],
|
|
225
|
+
partName: 'second',
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
const _second = second.toNumber();
|
|
229
|
+
if (!(0 <= _second && _second <= 59)) {
|
|
230
|
+
return second.unmatched({
|
|
231
|
+
reason: { type: 'out-of-range', gte: 0, lte: 59 },
|
|
232
|
+
expects: [],
|
|
233
|
+
partName: 'second',
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
/**
|
|
238
|
+
* > One, two, or three ASCII digits, representing the fractional part of second
|
|
239
|
+
*/
|
|
240
|
+
secondFractionalPart(secondFP) {
|
|
241
|
+
(0, debug_1.log)('Parsing Datetime Second Fractional Part: "%s"', secondFP === null || secondFP === void 0 ? void 0 : secondFP.value);
|
|
242
|
+
if (!secondFP || !secondFP.value) {
|
|
243
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
244
|
+
expects: [{ type: 'common', value: 'fractional part' }],
|
|
245
|
+
partName: 'fractional part',
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
if (!secondFP.match(/^[0-9]+$/)) {
|
|
249
|
+
return secondFP.unmatched({
|
|
250
|
+
reason: 'unexpected-token',
|
|
251
|
+
expects: [],
|
|
252
|
+
partName: 'fractional part',
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (!(1 <= secondFP.length && secondFP.length <= 3)) {
|
|
256
|
+
return secondFP.unmatched({
|
|
257
|
+
reason: { type: 'out-of-range-length-digit', gte: 1, lte: 3 },
|
|
258
|
+
expects: [],
|
|
259
|
+
partName: 'fractional part',
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
/**
|
|
264
|
+
* > 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
|
+
*/
|
|
266
|
+
week(week) {
|
|
267
|
+
(0, debug_1.log)('Parsing Datetime Week: "%s"', week === null || week === void 0 ? void 0 : week.value);
|
|
268
|
+
if (!week || !week.value) {
|
|
269
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
270
|
+
expects: [{ type: 'common', value: 'week' }],
|
|
271
|
+
partName: 'week',
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
if (!week.match(/^[0-9]+$/)) {
|
|
275
|
+
return week.unmatched({
|
|
276
|
+
reason: 'unexpected-token',
|
|
277
|
+
expects: [],
|
|
278
|
+
partName: 'week',
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
if (week.length !== 2) {
|
|
282
|
+
return week.unmatched({
|
|
283
|
+
reason: { type: 'out-of-range-length-digit', gte: 2, lte: 2 },
|
|
284
|
+
expects: [],
|
|
285
|
+
partName: 'week',
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
const maxweek = getMaxWeekNum(this._year || 0);
|
|
289
|
+
const _week = week.toNumber();
|
|
290
|
+
if (!(1 <= _week && _week <= maxweek)) {
|
|
291
|
+
return week.unmatched({
|
|
292
|
+
reason: { type: 'out-of-range', gte: 1, lte: maxweek },
|
|
293
|
+
expects: [],
|
|
294
|
+
partName: 'date',
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
/**
|
|
299
|
+
* > A U+002D HYPHEN-MINUS character (-)
|
|
300
|
+
*/
|
|
301
|
+
hyphen(hyphen) {
|
|
302
|
+
(0, debug_1.log)('Parsing Datetime hyphen: "%s"', hyphen === null || hyphen === void 0 ? void 0 : hyphen.value);
|
|
303
|
+
if (!hyphen || !hyphen.value) {
|
|
304
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
305
|
+
expects: [{ type: 'common', value: 'hyphen' }],
|
|
306
|
+
partName: 'datetime',
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (!hyphen.match('-')) {
|
|
310
|
+
return hyphen.unmatched({
|
|
311
|
+
reason: 'unexpected-token',
|
|
312
|
+
expects: [{ type: 'common', value: 'hyphen' }],
|
|
313
|
+
partName: 'datetime',
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
/**
|
|
318
|
+
* > A U+003A COLON character (:)
|
|
319
|
+
*/
|
|
320
|
+
coron(coron) {
|
|
321
|
+
(0, debug_1.log)('Parsing Datetime coron: "%s"', coron === null || coron === void 0 ? void 0 : coron.value);
|
|
322
|
+
if (!coron || !coron.value) {
|
|
323
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
324
|
+
expects: [{ type: 'common', value: 'coron' }],
|
|
325
|
+
partName: 'time',
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
if (!coron.match(':')) {
|
|
329
|
+
return coron.unmatched({
|
|
330
|
+
reason: 'unexpected-token',
|
|
331
|
+
expects: [{ type: 'common', value: 'coron' }],
|
|
332
|
+
partName: 'time',
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
/**
|
|
337
|
+
* > A U+003A COLON character (:)
|
|
338
|
+
* or
|
|
339
|
+
* End of token
|
|
340
|
+
*/
|
|
341
|
+
coronOrEnd(coron) {
|
|
342
|
+
if (!coron || !coron.value) {
|
|
343
|
+
return (0, match_result_1.matched)();
|
|
344
|
+
}
|
|
345
|
+
if (!coron.match(':')) {
|
|
346
|
+
return coron.unmatched({
|
|
347
|
+
reason: 'unexpected-token',
|
|
348
|
+
expects: [{ type: 'common', value: 'coron' }],
|
|
349
|
+
partName: 'time',
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
/**
|
|
354
|
+
* > A U+002E FULL STOP character (.)
|
|
355
|
+
* or
|
|
356
|
+
* End of token
|
|
357
|
+
*/
|
|
358
|
+
decimalPointOrEnd(dot) {
|
|
359
|
+
if (!dot || !dot.value) {
|
|
360
|
+
return (0, match_result_1.matched)();
|
|
361
|
+
}
|
|
362
|
+
if (!dot.match('.')) {
|
|
363
|
+
return dot.unmatched({
|
|
364
|
+
reason: 'unexpected-token',
|
|
365
|
+
expects: [{ type: 'common', value: 'decimal point' }],
|
|
366
|
+
partName: 'second',
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
/**
|
|
371
|
+
* > A U+0054 LATIN CAPITAL LETTER T character (T) or a U+0020 SPACE character
|
|
372
|
+
*/
|
|
373
|
+
localDateTimeSeparator(sep) {
|
|
374
|
+
(0, debug_1.log)('Parsing Datetime Local-Date-Time separator: "%s"', sep === null || sep === void 0 ? void 0 : sep.value);
|
|
375
|
+
if (!sep || !sep.value) {
|
|
376
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
377
|
+
expects: [
|
|
378
|
+
{ type: 'const', value: 'T' },
|
|
379
|
+
{ type: 'common', value: 'space' },
|
|
380
|
+
],
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
if (!sep.match(['T', ' '])) {
|
|
384
|
+
return sep.unmatched({
|
|
385
|
+
reason: 'unexpected-token',
|
|
386
|
+
expects: [
|
|
387
|
+
{ type: 'const', value: 'T' },
|
|
388
|
+
{ type: 'common', value: 'space' },
|
|
389
|
+
],
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
/**
|
|
394
|
+
* > A U+0054 LATIN CAPITAL LETTER T character (T)
|
|
395
|
+
*/
|
|
396
|
+
normalizedlocalDateTimeSeparator(sep) {
|
|
397
|
+
(0, debug_1.log)('Parsing Datetime Normalized-Local-Date-Time separator: %s', sep === null || sep === void 0 ? void 0 : sep.value);
|
|
398
|
+
if (!sep || !sep.value) {
|
|
399
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
400
|
+
expects: [{ type: 'const', value: 'T' }],
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
if (!sep.match('T')) {
|
|
404
|
+
return sep.unmatched({
|
|
405
|
+
reason: 'unexpected-token',
|
|
406
|
+
expects: [{ type: 'const', value: 'T' }],
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
/**
|
|
411
|
+
* > Either a U+002B PLUS SIGN character (+) or,
|
|
412
|
+
* > if the time-zone offset is not zero,
|
|
413
|
+
* > a U+002D HYPHEN-MINUS character (-),
|
|
414
|
+
* > representing the sign of the time-zone offset
|
|
415
|
+
*/
|
|
416
|
+
plusOrMinusSign(coron) {
|
|
417
|
+
if (!coron) {
|
|
418
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
419
|
+
expects: [
|
|
420
|
+
{ type: 'const', value: '+' },
|
|
421
|
+
{ type: 'const', value: '-' },
|
|
422
|
+
],
|
|
423
|
+
partName: 'time-zone',
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
if (!coron.match(['+', '-'])) {
|
|
427
|
+
return coron.unmatched({
|
|
428
|
+
reason: 'unexpected-token',
|
|
429
|
+
expects: [
|
|
430
|
+
{ type: 'const', value: '+' },
|
|
431
|
+
{ type: 'const', value: '-' },
|
|
432
|
+
],
|
|
433
|
+
partName: 'time-zone',
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
/**
|
|
438
|
+
* > A U+0057 LATIN CAPITAL LETTER W character (W)
|
|
439
|
+
*/
|
|
440
|
+
weekSign(weekSign) {
|
|
441
|
+
(0, debug_1.log)('Parsing Datetime W sign: "%s"', weekSign === null || weekSign === void 0 ? void 0 : weekSign.value);
|
|
442
|
+
if (!weekSign || !weekSign.value) {
|
|
443
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
444
|
+
expects: [{ type: 'const', value: 'W' }],
|
|
445
|
+
partName: 'time-zone',
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
if (!weekSign.match('W')) {
|
|
449
|
+
return weekSign.unmatched({
|
|
450
|
+
reason: 'unexpected-token',
|
|
451
|
+
expects: [{ type: 'const', value: 'W' }],
|
|
452
|
+
partName: 'time-zone',
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
/**
|
|
457
|
+
* Extra token
|
|
458
|
+
*/
|
|
459
|
+
extra(extra) {
|
|
460
|
+
(0, debug_1.log)('Parsing Datetime EXTRA STRING: "%s"', extra === null || extra === void 0 ? void 0 : extra.value);
|
|
461
|
+
if (extra && extra.value) {
|
|
462
|
+
return extra.unmatched({
|
|
463
|
+
reason: 'extra-token',
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
};
|
|
468
|
+
const daysOfMonth = [
|
|
469
|
+
0,
|
|
470
|
+
// 1
|
|
471
|
+
31,
|
|
472
|
+
// 2
|
|
473
|
+
28,
|
|
474
|
+
// 3
|
|
475
|
+
31,
|
|
476
|
+
// 4
|
|
477
|
+
30,
|
|
478
|
+
// 5
|
|
479
|
+
31,
|
|
480
|
+
// 6
|
|
481
|
+
30,
|
|
482
|
+
// 7
|
|
483
|
+
31,
|
|
484
|
+
// 8
|
|
485
|
+
31,
|
|
486
|
+
// 9
|
|
487
|
+
30,
|
|
488
|
+
// 10
|
|
489
|
+
31,
|
|
490
|
+
// 11
|
|
491
|
+
30,
|
|
492
|
+
// 12
|
|
493
|
+
31,
|
|
494
|
+
];
|
|
495
|
+
function getMaxWeekNum(year) {
|
|
496
|
+
let date = 31;
|
|
497
|
+
while (date) {
|
|
498
|
+
const d = new Date(Date.UTC(year, 11, date, 0, 0, 0, 0));
|
|
499
|
+
d.setDate(d.getDate() + 4 - (d.getDay() || 7));
|
|
500
|
+
const yearStart = new Date(d.getFullYear(), 0, 1);
|
|
501
|
+
const weekNo = Math.ceil(((d.valueOf() - yearStart.valueOf()) / 86400000 + 1) / 7);
|
|
502
|
+
if (weekNo !== 1) {
|
|
503
|
+
return weekNo;
|
|
504
|
+
}
|
|
505
|
+
date--;
|
|
506
|
+
}
|
|
507
|
+
return NaN;
|
|
508
|
+
}
|
|
509
|
+
exports.getMaxWeekNum = getMaxWeekNum;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CustomSyntaxChecker } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#durations
|
|
4
|
+
*/
|
|
5
|
+
export declare const checkDurationISO8601LikeString: CustomSyntaxChecker;
|
|
6
|
+
export declare const checkDurationComponentListString: CustomSyntaxChecker;
|