@markuplint/types 3.0.0-dev.25 → 3.0.0-dev.38

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 (61) hide show
  1. package/package.json +2 -2
  2. package/gen/specific-schema.json +0 -98
  3. package/gen/types.ts +0 -66
  4. package/src/check-multi-types.ts +0 -35
  5. package/src/check.spec.ts +0 -83
  6. package/src/check.ts +0 -48
  7. package/src/css-syntax.spec.ts +0 -167
  8. package/src/css-syntax.ts +0 -188
  9. package/src/debug.ts +0 -3
  10. package/src/defs.ts +0 -811
  11. package/src/enum.ts +0 -25
  12. package/src/get-candidate.ts +0 -24
  13. package/src/index.ts +0 -3
  14. package/src/keyword-type.ts +0 -64
  15. package/src/list.spec.ts +0 -133
  16. package/src/list.ts +0 -34
  17. package/src/match-result.ts +0 -49
  18. package/src/number.ts +0 -46
  19. package/src/primitive/index.spec.ts +0 -65
  20. package/src/primitive/index.ts +0 -7
  21. package/src/primitive/is-float.ts +0 -8
  22. package/src/primitive/is-int.ts +0 -8
  23. package/src/primitive/is-non-zero-uint.ts +0 -8
  24. package/src/primitive/is-quantity.ts +0 -38
  25. package/src/primitive/is-uint.ts +0 -15
  26. package/src/primitive/range.ts +0 -14
  27. package/src/primitive/split-unit.ts +0 -20
  28. package/src/rfc/is-bcp-47.spec.ts +0 -23
  29. package/src/rfc/is-bcp-47.ts +0 -13
  30. package/src/token/index.ts +0 -2
  31. package/src/token/token-collection.spec.ts +0 -147
  32. package/src/token/token-collection.ts +0 -444
  33. package/src/token/token.ts +0 -144
  34. package/src/types.schema.ts +0 -1113
  35. package/src/types.ts +0 -118
  36. package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
  37. package/src/w3c/check-serialized-permissions-policy.ts +0 -303
  38. package/src/whatwg/check-autocomplete.spec.ts +0 -387
  39. package/src/whatwg/check-autocomplete.ts +0 -380
  40. package/src/whatwg/check-datetime/date-string.ts +0 -44
  41. package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
  42. package/src/whatwg/check-datetime/duration-string.ts +0 -399
  43. package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
  44. package/src/whatwg/check-datetime/index.spec.ts +0 -333
  45. package/src/whatwg/check-datetime/index.ts +0 -36
  46. package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
  47. package/src/whatwg/check-datetime/month-string.ts +0 -31
  48. package/src/whatwg/check-datetime/time-string.ts +0 -49
  49. package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
  50. package/src/whatwg/check-datetime/week-string.ts +0 -41
  51. package/src/whatwg/check-datetime/year-string.ts +0 -26
  52. package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
  53. package/src/whatwg/check-mime-type.spec.ts +0 -59
  54. package/src/whatwg/check-mime-type.ts +0 -46
  55. package/src/whatwg/is-abs-url.spec.ts +0 -8
  56. package/src/whatwg/is-abs-url.ts +0 -31
  57. package/src/whatwg/is-browser-context-name.ts +0 -16
  58. package/src/whatwg/is-custom-element-name.ts +0 -76
  59. package/src/whatwg/is-itemprop-name.ts +0 -17
  60. package/tsconfig.test.json +0 -3
  61. package/tsconfig.tsbuildinfo +0 -1
@@ -1,380 +0,0 @@
1
- import type { Expect } from '..';
2
- import type { CustomSyntaxChecker } from '../types';
3
-
4
- import { log } from '../debug';
5
- import { getCandidate } from '../get-candidate';
6
- import { matched } from '../match-result';
7
- import { TokenCollection } from '../token';
8
-
9
- const acLog = log.extend('autocomplete');
10
-
11
- /**
12
- * https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-section
13
- */
14
- const namedGroup = /^section-/i;
15
-
16
- /**
17
- * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-shipping
18
- */
19
- const partOfAddress = ['shipping', 'billing'];
20
-
21
- /**
22
- * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field
23
- */
24
- const autofillFieldNames = [
25
- 'name',
26
- 'honorific-prefix',
27
- 'given-name',
28
- 'additional-name',
29
- 'family-name',
30
- 'honorific-suffix',
31
- 'nickname',
32
- 'username',
33
- 'new-password',
34
- 'current-password',
35
- 'one-time-code',
36
- 'organization-title',
37
- 'organization',
38
- 'street-address',
39
- 'address-line1',
40
- 'address-line2',
41
- 'address-line3',
42
- 'address-level4',
43
- 'address-level3',
44
- 'address-level2',
45
- 'address-level1',
46
- 'country',
47
- 'country-name',
48
- 'postal-code',
49
- 'cc-name',
50
- 'cc-given-name',
51
- 'cc-additional-name',
52
- 'cc-family-name',
53
- 'cc-number',
54
- 'cc-exp',
55
- 'cc-exp-month',
56
- 'cc-exp-year',
57
- 'cc-csc',
58
- 'cc-type',
59
- 'transaction-currency',
60
- 'transaction-amount',
61
- 'language',
62
- 'bday',
63
- 'bday-day',
64
- 'bday-month',
65
- 'bday-year',
66
- 'sex',
67
- 'url',
68
- 'photo',
69
- ];
70
-
71
- /**
72
- * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-home
73
- */
74
- const contactingTokens = ['home', 'work', 'mobile', 'fax', 'pager'];
75
-
76
- /**
77
- * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:ascii-case-insensitive-7
78
- */
79
- const contactableFieldNames = [
80
- 'tel',
81
- 'tel-country-code',
82
- 'tel-national',
83
- 'tel-area-code',
84
- 'tel-local',
85
- 'tel-local-prefix',
86
- 'tel-local-suffix',
87
- 'tel-extension',
88
- 'email',
89
- 'impp',
90
- ];
91
-
92
- /**
93
- * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-webauthn
94
- */
95
- const webauthnFieldNames = ['webauthn'];
96
-
97
- const URL_AUTOCOMPLETE = 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete';
98
- const URL_ON_OFF =
99
- 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-on-2';
100
- const URL_NAMED_GROUP =
101
- 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-section';
102
- const URL_PART_OF_ADDRESS =
103
- 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-shipping';
104
- const URL_AUTOFILL_FIELD = 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field';
105
- const URL_CONTACTABLE_FIELD =
106
- 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-tel';
107
-
108
- /**
109
- * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete
110
- */
111
- export const checkAutoComplete: CustomSyntaxChecker = () => value => {
112
- let hasNamedGroup = false;
113
- let hasPartOfAddress = false;
114
- let hasContactingToken = false;
115
-
116
- const tokens = new TokenCollection(value, {
117
- disallowToSurroundBySpaces: false,
118
- allowEmpty: false,
119
- ordered: true,
120
- unique: true,
121
- caseInsensitive: true,
122
- });
123
-
124
- const listingChecked = tokens.check({
125
- expects: [
126
- {
127
- type: 'format',
128
- value: 'autocomplete',
129
- },
130
- ],
131
- ref: URL_AUTOCOMPLETE,
132
- });
133
- if (!listingChecked.matched) {
134
- acLog('Unmatch: %s', listingChecked.reason);
135
- return listingChecked;
136
- }
137
-
138
- const identTokens = tokens.getIdentTokens();
139
- const headAndTail1 = identTokens.headAndTail();
140
- let { head, tail } = headAndTail1;
141
- if (!head) {
142
- // Never
143
- throw new Error('TokenCollection is empty');
144
- }
145
-
146
- // > When wearing the autofill anchor mantle, the autocomplete attribute,
147
- // > if specified, must have a value that is
148
- // > an ordered set of space-separated tokens consisting of
149
- // > just autofill detail tokens
150
- // > (i.e. the "on" and "off" keywords are not allowed).
151
- if (head.match(['on', 'off'], true)) {
152
- if (tail.length) {
153
- acLog('[Unmatched ("%s")] Unexpected pair with "on" or "off": "%s"', value, tail.value);
154
- return tail[0].unmatched({
155
- reason: 'extra-token',
156
- expects: [
157
- {
158
- type: 'format',
159
- value: 'autocomplete',
160
- },
161
- ],
162
- ref: URL_ON_OFF,
163
- });
164
- }
165
-
166
- return matched();
167
- }
168
-
169
- // > Optionally, a token whose first eight characters are
170
- // > an ASCII case-insensitive match for the string "section-",
171
- // > meaning that the field belongs to the named group.
172
- if (head.match(namedGroup, true)) {
173
- hasNamedGroup = true;
174
- const sectionToken = tail.search(namedGroup);
175
- if (sectionToken) {
176
- acLog('[Unmatched ("%s")] Deprecated in autofill named group: "%s"', value, sectionToken.value);
177
- return sectionToken.unmatched({
178
- partName: 'autofill named group',
179
- reason: 'duplicated',
180
- ref: URL_NAMED_GROUP,
181
- });
182
- }
183
-
184
- const headAndTail2 = tail.headAndTail();
185
- head = headAndTail2.head;
186
- tail = headAndTail2.tail;
187
-
188
- if (!head) {
189
- // Missing autofill field name but it is valid
190
- return matched();
191
- }
192
- }
193
-
194
- // > Optionally, a token that is an ASCII case-insensitive match for
195
- // > one of the following strings:
196
- // > - "shipping", meaning the field is part of the shipping address or contact information
197
- // > - "billing", meaning the field is part of the billing address or contact information
198
- if (head.match(partOfAddress, true)) {
199
- hasPartOfAddress = true;
200
- const partToken = tail.search(partOfAddress);
201
- if (partToken) {
202
- acLog('[Unmatched ("%s")] Duplicated values: "%s"', value, partToken.value);
203
- return partToken.unmatched({
204
- reason: 'duplicated',
205
- expects: [
206
- {
207
- type: 'format',
208
- value: 'autocomplete',
209
- },
210
- ],
211
- ref: URL_PART_OF_ADDRESS,
212
- });
213
- }
214
-
215
- const headAndTail3 = tail.headAndTail();
216
- head = headAndTail3.head;
217
- tail = headAndTail3.tail;
218
-
219
- if (!head) {
220
- // Missing autofill field name but it is valid
221
- return matched();
222
- }
223
- }
224
-
225
- if (head.match(contactingTokens, true)) {
226
- hasContactingToken = true;
227
- const contactableFiledToken = tail[0];
228
- if (!contactableFiledToken) {
229
- // Missing autofill field name but it is valid
230
- return matched();
231
- }
232
-
233
- if (!contactableFiledToken.match(contactableFieldNames, true)) {
234
- const candidate = getCandidate(contactableFiledToken.value, contactableFieldNames);
235
- acLog('[Unmatched ("%s")] Unexpected token: "%s"', value, contactableFiledToken.value);
236
- return contactableFiledToken.unmatched({
237
- reason: 'unexpected-token',
238
- expects: contactableFieldNames.slice().map(token => ({
239
- type: 'const' as const,
240
- value: token,
241
- })),
242
- candidate,
243
- ref: URL_CONTACTABLE_FIELD,
244
- });
245
- }
246
-
247
- if (tail[1]) {
248
- if (tail[1].match(webauthnFieldNames)) {
249
- return matched();
250
- }
251
-
252
- const candidate = getCandidate(tail[1].value, webauthnFieldNames);
253
-
254
- if (candidate) {
255
- acLog(
256
- '[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ',
257
- value,
258
- tail[1].value,
259
- candidate,
260
- );
261
- } else {
262
- acLog('[Unmatched ("%s")] Unnecessarily token: "%s"', value, tail[1].value);
263
- }
264
-
265
- return tail[1].unmatched({
266
- reason: 'extra-token',
267
- expects: [
268
- {
269
- type: 'format',
270
- value: 'autocomplete',
271
- },
272
- ],
273
- ref: URL_AUTOFILL_FIELD,
274
- });
275
- }
276
-
277
- return matched();
278
- }
279
-
280
- if (head.match([...autofillFieldNames, ...contactableFieldNames], true)) {
281
- if (tail.length) {
282
- if (tail[0].match(webauthnFieldNames)) {
283
- return matched();
284
- }
285
-
286
- const candidate = getCandidate(tail[0].value, webauthnFieldNames);
287
-
288
- if (candidate) {
289
- acLog(
290
- '[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ',
291
- value,
292
- tail[0].value,
293
- candidate,
294
- );
295
- } else {
296
- acLog('[Unmatched ("%s")] Unnecessarily token: "%s"', value, tail[0].value);
297
- }
298
-
299
- return tail[0].unmatched({
300
- reason: 'extra-token',
301
- expects: [
302
- {
303
- type: 'format',
304
- value: 'autocomplete',
305
- },
306
- ],
307
- ref: URL_AUTOFILL_FIELD,
308
- });
309
- }
310
-
311
- return matched();
312
- }
313
-
314
- if (head.match(webauthnFieldNames)) {
315
- return matched();
316
- }
317
-
318
- const expects: Expect[] = [
319
- {
320
- type: 'common',
321
- value: 'autofill field name',
322
- },
323
- ];
324
- let candidate: string | undefined;
325
-
326
- if (!hasNamedGroup) {
327
- expects.unshift({
328
- type: 'common',
329
- value: 'autofill named group',
330
- });
331
-
332
- // Potentially typo a named group
333
- const [prefix, namedGroupStr] = head.value.split('-');
334
- const candidatePrefix = getCandidate(prefix, 'section');
335
- if (candidatePrefix) {
336
- candidate = `${candidatePrefix}-${namedGroupStr || ''}`;
337
- }
338
- } else if (!hasPartOfAddress) {
339
- expects.unshift(
340
- ...partOfAddress
341
- .slice()
342
- .reverse()
343
- .map(token => ({
344
- type: 'const' as const,
345
- value: token,
346
- })),
347
- );
348
-
349
- candidate = getCandidate(
350
- head.value,
351
- partOfAddress,
352
- autofillFieldNames,
353
- contactingTokens,
354
- contactableFieldNames,
355
- );
356
- } else if (!hasContactingToken) {
357
- expects.push(
358
- ...contactingTokens.slice().map(token => ({
359
- type: 'const' as const,
360
- value: token,
361
- })),
362
- );
363
-
364
- candidate = getCandidate(head.value, autofillFieldNames, contactingTokens, contactableFieldNames);
365
- }
366
-
367
- candidate = candidate || getCandidate(head.value, autofillFieldNames);
368
-
369
- if (candidate) {
370
- acLog('[Unmatched ("%s")] Unexpected token: "%s", Do you mean "%s"? ', value, head.value, candidate);
371
- } else {
372
- acLog('[Unmatched ("%s")] Unexpected token: "%s"', value, head.value);
373
- }
374
- return head.unmatched({
375
- reason: 'unexpected-token',
376
- expects,
377
- candidate,
378
- ref: URL_AUTOFILL_FIELD,
379
- });
380
- };
@@ -1,44 +0,0 @@
1
- import type { CustomSyntaxChecker } from '../../types';
2
-
3
- import { log } from '../../debug';
4
- import { TokenCollection } from '../../token';
5
-
6
- import { datetimeTokenCheck } from './datetime-tokens';
7
-
8
- /**
9
- * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates
10
- */
11
- export const checkDateString: CustomSyntaxChecker = () =>
12
- function checkDateString(value) {
13
- log('CHECK: date-string');
14
-
15
- const tokens = TokenCollection.fromPatterns(value, [
16
- // YYYY
17
- /[^-]*/,
18
- // -
19
- /[^0-9]?/,
20
- // MM
21
- /[^-]*/,
22
- // -
23
- /[^0-9]/,
24
- // DD
25
- /.[0-9]*/,
26
- ]);
27
-
28
- log('Date: "%s" => %O', tokens.value, tokens);
29
-
30
- const res = tokens.eachCheck(
31
- datetimeTokenCheck.year,
32
- datetimeTokenCheck.hyphen,
33
- datetimeTokenCheck.month,
34
- datetimeTokenCheck.hyphen,
35
- datetimeTokenCheck.date,
36
- datetimeTokenCheck.extra,
37
- );
38
-
39
- if (!res.matched) {
40
- log('Failed: %O', res);
41
- }
42
-
43
- return res;
44
- };