@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,322 @@
|
|
|
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");
|
|
8
|
+
/**
|
|
9
|
+
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#durations
|
|
10
|
+
*/
|
|
11
|
+
const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeString(value) {
|
|
12
|
+
(0, debug_1.log)('CHECK: duration-string (ISO8601 like)');
|
|
13
|
+
// PnDTnHnMnS
|
|
14
|
+
const tokens = token_1.TokenCollection.fromPatterns(value, [
|
|
15
|
+
// Start sign P
|
|
16
|
+
/[^0-9T]?/,
|
|
17
|
+
// date part
|
|
18
|
+
/[^T]*/,
|
|
19
|
+
// Time sign T
|
|
20
|
+
/[^0-9]?/,
|
|
21
|
+
// Time part
|
|
22
|
+
/.*/,
|
|
23
|
+
]);
|
|
24
|
+
(0, debug_1.log)('Duration ISO8601: "%s" => %O', tokens.value, tokens);
|
|
25
|
+
const res = tokens.eachCheck(p => {
|
|
26
|
+
if (!p || !p.value) {
|
|
27
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
28
|
+
expects: [{ type: 'const', value: 'P' }],
|
|
29
|
+
partName: 'duration',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (!p.match('P', false)) {
|
|
33
|
+
return p.unmatched({
|
|
34
|
+
reason: 'unexpected-token',
|
|
35
|
+
expects: [{ type: 'const', value: 'P' }],
|
|
36
|
+
partName: 'duration',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}, d => {
|
|
40
|
+
if (!d || !d.value) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
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 });
|
|
45
|
+
if (!num.match(/^[0-9]+$/)) {
|
|
46
|
+
return num.unmatched({
|
|
47
|
+
reason: 'unexpected-token',
|
|
48
|
+
expects: [],
|
|
49
|
+
partName: 'date',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (!sign || !sign.value) {
|
|
53
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
54
|
+
expects: [{ type: 'const', value: 'D' }],
|
|
55
|
+
partName: 'date',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (!sign.match('D', false)) {
|
|
59
|
+
return sign.unmatched({
|
|
60
|
+
reason: 'unexpected-token',
|
|
61
|
+
expects: [{ type: 'const', value: 'D' }],
|
|
62
|
+
partName: 'date',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (extra && extra.value) {
|
|
66
|
+
return extra.unmatched({
|
|
67
|
+
reason: 'unexpected-token',
|
|
68
|
+
expects: [{ type: 'const', value: 'T' }],
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}, t => {
|
|
72
|
+
if (!t || !t.value) {
|
|
73
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
74
|
+
expects: [{ type: 'const', value: 'T' }],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (!t.match('T', false)) {
|
|
78
|
+
return t.unmatched({
|
|
79
|
+
reason: 'unexpected-token',
|
|
80
|
+
expects: [{ type: 'const', value: 'T' }],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}, time => {
|
|
84
|
+
if (!time) {
|
|
85
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
86
|
+
expects: [
|
|
87
|
+
{ type: 'common', value: 'hour' },
|
|
88
|
+
{ type: 'common', value: 'minute' },
|
|
89
|
+
{ type: 'common', value: 'second' },
|
|
90
|
+
],
|
|
91
|
+
partName: 'time',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const timeTokens = token_1.TokenCollection.fromPatterns(time, [
|
|
95
|
+
// Hour part
|
|
96
|
+
/[0-9]+(\.[0-9]*)?[^0-9]?/,
|
|
97
|
+
// Minute part
|
|
98
|
+
/[0-9]+(\.[0-9]*)?[^0-9]?/,
|
|
99
|
+
// Second part
|
|
100
|
+
/[0-9]+(\.[0-9]*)?[^0-9]?/,
|
|
101
|
+
]);
|
|
102
|
+
(0, debug_1.log)('Time part: "%s" => %O', timeTokens.value, timeTokens);
|
|
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', {
|
|
106
|
+
expects: [
|
|
107
|
+
{ type: 'common', value: 'hour' },
|
|
108
|
+
{ type: 'common', value: 'minute' },
|
|
109
|
+
{ type: 'common', value: 'second' },
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const specified = new Set();
|
|
114
|
+
for (const t of timeTokens) {
|
|
115
|
+
if (!t || !t.value) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (specified.has('S')) {
|
|
119
|
+
return t.unmatched({
|
|
120
|
+
reason: 'extra-token',
|
|
121
|
+
});
|
|
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 });
|
|
125
|
+
if (!num.match(/^[0-9]+$/)) {
|
|
126
|
+
return num.unmatched({
|
|
127
|
+
reason: 'unexpected-token',
|
|
128
|
+
expects: [{ type: 'common', value: 'number' }],
|
|
129
|
+
partName: 'time',
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
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 });
|
|
135
|
+
if (!dp.match('.')) {
|
|
136
|
+
return dp.unmatched({
|
|
137
|
+
reason: 'unexpected-token',
|
|
138
|
+
expects: [],
|
|
139
|
+
partName: 'decimal point',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (!fp || !fp.value) {
|
|
143
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
144
|
+
expects: [{ type: 'common', value: 'fractional part' }],
|
|
145
|
+
partName: 'second',
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (!fp.match(/^[0-9]+$/)) {
|
|
149
|
+
return fp.unmatched({
|
|
150
|
+
reason: 'unexpected-token',
|
|
151
|
+
expects: [],
|
|
152
|
+
partName: 'fractional part',
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (!(1 <= fp.length && fp.length <= 3)) {
|
|
156
|
+
return fp.unmatched({
|
|
157
|
+
reason: { type: 'out-of-range-length-digit', gte: 1, lte: 3 },
|
|
158
|
+
expects: [],
|
|
159
|
+
partName: 'fractional part',
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const expects = [
|
|
164
|
+
{ type: 'const', value: 'H' },
|
|
165
|
+
{ type: 'const', value: 'M' },
|
|
166
|
+
{ type: 'const', value: 'S' },
|
|
167
|
+
];
|
|
168
|
+
if (!sign || !sign.value) {
|
|
169
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
170
|
+
expects: expects.filter(e => !specified.has(e.value)),
|
|
171
|
+
partName: 'time',
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (specified.has('M') && sign.match('H', false)) {
|
|
175
|
+
return sign.unmatched({
|
|
176
|
+
reason: 'unexpected-token',
|
|
177
|
+
expects: [{ type: 'const', value: 'S' }],
|
|
178
|
+
partName: 'time',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (!sign.match(['H', 'M', 'S'], false) ||
|
|
182
|
+
(sign.match('H', false) && specified.has('H')) ||
|
|
183
|
+
(sign.match('M', false) && specified.has('M'))) {
|
|
184
|
+
return sign.unmatched({
|
|
185
|
+
reason: 'unexpected-token',
|
|
186
|
+
expects: expects.filter(e => !specified.has(e.value)),
|
|
187
|
+
partName: 'time',
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
specified.add(sign.value);
|
|
191
|
+
}
|
|
192
|
+
}, datetime_tokens_1.datetimeTokenCheck.extra);
|
|
193
|
+
if (!res.matched) {
|
|
194
|
+
(0, debug_1.log)('Failed: %O', res);
|
|
195
|
+
}
|
|
196
|
+
return res;
|
|
197
|
+
};
|
|
198
|
+
exports.checkDurationISO8601LikeString = checkDurationISO8601LikeString;
|
|
199
|
+
const checkDurationComponentListString = () => function checkDurationComponentListString(value) {
|
|
200
|
+
(0, debug_1.log)('CHECK: duration-string (duration component list)');
|
|
201
|
+
if (!value) {
|
|
202
|
+
return (0, match_result_1.unmatched)('', 'empty-token', {
|
|
203
|
+
expects: [{ type: 'common', value: 'time' }],
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const patterns = [
|
|
207
|
+
// 1. Zero or more ASCII whitespace.
|
|
208
|
+
/\s*/,
|
|
209
|
+
// 2. One or more ASCII digits, representing a number of time units,
|
|
210
|
+
// scaled by the duration time component scale specified (see below)
|
|
211
|
+
// to represent a number of seconds.
|
|
212
|
+
/[0-9]+/,
|
|
213
|
+
// 3. If the duration time component scale specified is 1 (i.e. the units are seconds),
|
|
214
|
+
// then, optionally, a U+002E FULL STOP character (.) followed by
|
|
215
|
+
// one, two, or three ASCII digits, representing a fraction of a second.
|
|
216
|
+
/(\.[0-9]*)?/,
|
|
217
|
+
// 4. Zero or more ASCII whitespace.
|
|
218
|
+
/\s*/,
|
|
219
|
+
// 5. One of the following characters, representing the duration time component scale
|
|
220
|
+
// of the time unit used in the numeric part of the duration time component:
|
|
221
|
+
/[^0-9]/,
|
|
222
|
+
// 6. Zero or more ASCII whitespace.
|
|
223
|
+
/\s*/,
|
|
224
|
+
];
|
|
225
|
+
const tokens = token_1.TokenCollection.fromPatterns(value, patterns, { repeat: true });
|
|
226
|
+
const components = tokens.chunk(patterns.length);
|
|
227
|
+
const specified = new Set();
|
|
228
|
+
for (const component of components) {
|
|
229
|
+
(0, debug_1.log)('Duration Component: "%s" => %O', component.value, component);
|
|
230
|
+
const [, , dpfp, , unit] = component;
|
|
231
|
+
const res = component.eachCheck(ws => { }, num => {
|
|
232
|
+
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, {
|
|
235
|
+
expects: [{ type: 'common', value: 'time' }],
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}, dpfp => {
|
|
239
|
+
if (!dpfp || !dpfp.value) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const unitExpects = [
|
|
243
|
+
{ type: 'const', value: 'w' },
|
|
244
|
+
{ type: 'const', value: 'd' },
|
|
245
|
+
{ type: 'const', value: 'h' },
|
|
246
|
+
{ type: 'const', value: 'm' },
|
|
247
|
+
{ type: 'const', value: 's' },
|
|
248
|
+
].filter(e => !specified.has(e.value));
|
|
249
|
+
if (specified.has('s')) {
|
|
250
|
+
return dpfp.unmatched({
|
|
251
|
+
reason: 'unexpected-token',
|
|
252
|
+
expects: unitExpects,
|
|
253
|
+
partName: 'unit',
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
const [, fp] = token_1.TokenCollection.fromPatterns(dpfp, [/\./, /[0-9]+/]);
|
|
257
|
+
if (!fp || !fp.value) {
|
|
258
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
259
|
+
expects: [{ type: 'common', value: 'fractional part' }],
|
|
260
|
+
partName: 'fractional part',
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (!fp.match(/[0-9]+/)) {
|
|
264
|
+
return fp.unmatched({
|
|
265
|
+
reason: 'unexpected-token',
|
|
266
|
+
expects: [{ type: 'common', value: 'fractional part' }],
|
|
267
|
+
partName: 'fractional part',
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
if (!(1 <= fp.length && fp.length <= 3)) {
|
|
271
|
+
return fp.unmatched({
|
|
272
|
+
reason: { type: 'out-of-range-length-digit', gte: 1, lte: 3 },
|
|
273
|
+
expects: [],
|
|
274
|
+
partName: 'fractional part',
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}, ws => { }, unit => {
|
|
278
|
+
const expects = [
|
|
279
|
+
{ type: 'const', value: 'w' },
|
|
280
|
+
{ type: 'const', value: 'd' },
|
|
281
|
+
{ type: 'const', value: 'h' },
|
|
282
|
+
{ type: 'const', value: 'm' },
|
|
283
|
+
{ type: 'const', value: 's' },
|
|
284
|
+
].filter(e => !specified.has(e.value));
|
|
285
|
+
if (!unit || !unit.value) {
|
|
286
|
+
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
287
|
+
expects,
|
|
288
|
+
partName: 'unit',
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
const unitVal = unit.value.toLowerCase();
|
|
292
|
+
if (specified.has(unitVal)) {
|
|
293
|
+
return unit.unmatched({
|
|
294
|
+
reason: 'duplicated',
|
|
295
|
+
expects,
|
|
296
|
+
partName: 'unit',
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
if (dpfp && dpfp.value && unit.match(['w', 'd', 'h', 'm'])) {
|
|
300
|
+
return unit.unmatched({
|
|
301
|
+
reason: 'unexpected-token',
|
|
302
|
+
expects: [{ type: 'const', value: 's' }],
|
|
303
|
+
partName: 'unit',
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
if (!unit.match(['w', 'd', 'h', 'm', 's'])) {
|
|
307
|
+
return unit.unmatched({
|
|
308
|
+
reason: 'unexpected-token',
|
|
309
|
+
expects,
|
|
310
|
+
partName: 'unit',
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
specified.add(unitVal);
|
|
314
|
+
}, ws => { });
|
|
315
|
+
if (!res.matched) {
|
|
316
|
+
(0, debug_1.log)('Failed: %O', res);
|
|
317
|
+
return res;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return (0, match_result_1.matched)();
|
|
321
|
+
};
|
|
322
|
+
exports.checkDurationComponentListString = checkDurationComponentListString;
|
|
@@ -0,0 +1,66 @@
|
|
|
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");
|
|
9
|
+
/**
|
|
10
|
+
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#global-dates-and-times
|
|
11
|
+
*/
|
|
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, [
|
|
15
|
+
// YYYY
|
|
16
|
+
/[^-]*/,
|
|
17
|
+
// -
|
|
18
|
+
/[^0-9]?/,
|
|
19
|
+
// MM
|
|
20
|
+
/[^-]*/,
|
|
21
|
+
// -
|
|
22
|
+
/[^0-9]?/,
|
|
23
|
+
// DD
|
|
24
|
+
/[^T\s]*/,
|
|
25
|
+
// T \s
|
|
26
|
+
/[^0-9]?/,
|
|
27
|
+
// hh
|
|
28
|
+
/[^:]*/,
|
|
29
|
+
// :
|
|
30
|
+
/[^0-9]?/,
|
|
31
|
+
// mm
|
|
32
|
+
/[^:Z+-]*/,
|
|
33
|
+
// :ss.sss
|
|
34
|
+
/(:[^Z+-]*)?/,
|
|
35
|
+
// time-zone
|
|
36
|
+
/.*/,
|
|
37
|
+
]);
|
|
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.coron, datetime_tokens_1.datetimeTokenCheck.minute, second => {
|
|
40
|
+
if (!second || !second.value) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const secondTokens = token_1.TokenCollection.fromPatterns(second, [/:?/, /[0-9]*/, /\.?/, /[0-9]*/]);
|
|
44
|
+
(0, debug_1.log)('Scond Part: "%s" => %O', secondTokens.value, secondTokens);
|
|
45
|
+
const res = secondTokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.coron, datetime_tokens_1.datetimeTokenCheck.second, datetime_tokens_1.datetimeTokenCheck.decimalPointOrEnd, datetime_tokens_1.datetimeTokenCheck.secondFractionalPart);
|
|
46
|
+
if (!res.matched) {
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
49
|
+
}, zone => {
|
|
50
|
+
if (!zone || !zone.value) {
|
|
51
|
+
return (0, match_result_1.unmatched)(value, 'missing-token', {
|
|
52
|
+
expects: [{ type: 'common', value: 'time-zone' }],
|
|
53
|
+
partName: 'time-zone',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const res = (0, time_zone_offset_string_1.parseTimeZone)(zone);
|
|
57
|
+
if (!res.matched) {
|
|
58
|
+
return res;
|
|
59
|
+
}
|
|
60
|
+
}, datetime_tokens_1.datetimeTokenCheck.extra);
|
|
61
|
+
if (!res.matched) {
|
|
62
|
+
(0, debug_1.log)('Failed: %O', res);
|
|
63
|
+
}
|
|
64
|
+
return res;
|
|
65
|
+
};
|
|
66
|
+
exports.checkGlobalDateAndTimeString = checkGlobalDateAndTimeString;
|
|
@@ -0,0 +1,35 @@
|
|
|
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");
|
|
15
|
+
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)(),
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates-and-times
|
|
31
|
+
*/
|
|
32
|
+
const checkDateTime = () => value => {
|
|
33
|
+
return (0, check_multi_types_1.checkMultiTypes)(value, checks);
|
|
34
|
+
};
|
|
35
|
+
exports.checkDateTime = checkDateTime;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|