@markuplint/types 3.12.0 → 4.0.0-alpha.10
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 +1 -1
- package/lib/check-multi-types.d.ts +2 -5
- package/lib/check-multi-types.js +9 -14
- package/lib/check.d.ts +1 -1
- package/lib/check.js +20 -30
- package/lib/css-syntax.d.ts +1 -1
- package/lib/css-syntax.js +33 -33
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +2 -1
- package/lib/defs.js +188 -138
- package/lib/enum.d.ts +2 -2
- package/lib/enum.js +7 -12
- package/lib/get-candidate.d.ts +1 -4
- package/lib/get-candidate.js +5 -10
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -6
- package/lib/keyword-type.d.ts +2 -2
- package/lib/keyword-type.js +20 -25
- package/lib/list.d.ts +2 -2
- package/lib/list.js +9 -14
- package/lib/match-result.d.ts +8 -21
- package/lib/match-result.js +6 -13
- package/lib/number.d.ts +3 -3
- package/lib/number.js +13 -17
- package/lib/primitive/index.d.ts +7 -7
- package/lib/primitive/index.js +7 -17
- package/lib/primitive/is-float.js +2 -6
- package/lib/primitive/is-int.js +2 -6
- package/lib/primitive/is-non-zero-uint.js +2 -6
- package/lib/primitive/is-quantity.d.ts +1 -5
- package/lib/primitive/is-quantity.js +9 -13
- package/lib/primitive/is-uint.d.ts +3 -6
- package/lib/primitive/is-uint.js +4 -8
- package/lib/primitive/range.js +3 -7
- package/lib/primitive/split-unit.d.ts +2 -2
- package/lib/primitive/split-unit.js +4 -8
- package/lib/rfc/is-bcp-47.d.ts +1 -1
- package/lib/rfc/is-bcp-47.js +3 -7
- package/lib/token/index.d.ts +2 -2
- package/lib/token/index.js +2 -7
- package/lib/token/token-collection.d.ts +58 -70
- package/lib/token/token-collection.js +47 -56
- package/lib/token/token.d.ts +54 -59
- package/lib/token/token.js +14 -20
- package/lib/token/types.js +1 -2
- package/lib/types.d.ts +58 -82
- package/lib/types.js +1 -2
- package/lib/types.schema.d.ts +31 -1087
- package/lib/types.schema.js +1 -2
- package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
- package/lib/w3c/check-serialized-permissions-policy.js +21 -25
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +34 -41
- package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/date-string.js +12 -16
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +2 -22
- package/lib/whatwg/check-datetime/datetime-tokens.js +58 -64
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +64 -69
- package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/global-date-and-time-string.js +24 -28
- package/lib/whatwg/check-datetime/index.d.ts +1 -1
- package/lib/whatwg/check-datetime/index.js +25 -29
- package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +37 -41
- package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/month-string.js +9 -13
- package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/time-string.js +13 -17
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +22 -28
- package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/week-string.js +11 -15
- package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/year-string.js +9 -13
- package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/yearless-date-string.js +11 -15
- package/lib/whatwg/check-mime-type.d.ts +5 -5
- package/lib/whatwg/check-mime-type.js +11 -17
- package/lib/whatwg/is-abs-url.d.ts +1 -1
- package/lib/whatwg/is-abs-url.js +8 -12
- package/lib/whatwg/is-browser-context-name.d.ts +1 -1
- package/lib/whatwg/is-browser-context-name.js +1 -5
- package/lib/whatwg/is-custom-element-name.d.ts +10 -5
- package/lib/whatwg/is-custom-element-name.js +22 -38
- package/lib/whatwg/is-itemprop-name.d.ts +1 -1
- package/lib/whatwg/is-itemprop-name.js +1 -5
- package/lib/whatwg/is-navigable-target-name.d.ts +1 -1
- package/lib/whatwg/is-navigable-target-name.js +1 -5
- package/package.json +17 -9
- package/test/check.spec.js +0 -89
- package/test/css-syntax.spec.js +0 -170
- package/test/list.spec.js +0 -133
- package/test/primitive/index.spec.js +0 -65
- package/test/rfc/is-bcp-47.spec.js +0 -23
- package/test/token/token-collection.spec.js +0 -146
- package/test/w3c/check-serialized-permissions-policy.spec.js +0 -36
- package/test/whatwg/check-autocomplete.spec.js +0 -387
- package/test/whatwg/check-datetime/index.spec.js +0 -336
- package/test/whatwg/check-mime-type.spec.js +0 -59
- package/test/whatwg/is-abs-url.spec.js +0 -8
|
@@ -1,87 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../../debug");
|
|
5
|
-
const token_1 = require("../../token");
|
|
6
|
-
const datetime_tokens_1 = require("./datetime-tokens");
|
|
1
|
+
import { log } from '../../debug.js';
|
|
2
|
+
import { TokenCollection } from '../../token/index.js';
|
|
3
|
+
import { datetimeTokenCheck } from './datetime-tokens.js';
|
|
7
4
|
/**
|
|
8
5
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string
|
|
9
6
|
*/
|
|
10
|
-
const checkLocalDateAndTimeString = () => function checkLocalDateAndTimeString(value) {
|
|
11
|
-
|
|
12
|
-
const tokens =
|
|
7
|
+
export const checkLocalDateAndTimeString = () => function checkLocalDateAndTimeString(value) {
|
|
8
|
+
log('CHECK: local-date-and-time-string');
|
|
9
|
+
const tokens = TokenCollection.fromPatterns(value, [
|
|
13
10
|
// YYYY
|
|
14
11
|
/[^-]*/,
|
|
15
12
|
// -
|
|
16
|
-
|
|
13
|
+
/\D?/,
|
|
17
14
|
// MM
|
|
18
15
|
/[^-]*/,
|
|
19
16
|
// -
|
|
20
|
-
|
|
17
|
+
/\D?/,
|
|
21
18
|
// DD
|
|
22
|
-
/[
|
|
19
|
+
/[^\sT]*/,
|
|
23
20
|
// T
|
|
24
|
-
|
|
21
|
+
/\D?/,
|
|
25
22
|
// hh
|
|
26
23
|
/[^:]*/,
|
|
27
24
|
// :
|
|
28
|
-
|
|
25
|
+
/\D?/,
|
|
29
26
|
// mm
|
|
30
27
|
/[^:]*/,
|
|
31
28
|
// :
|
|
32
|
-
|
|
29
|
+
/\D?/,
|
|
33
30
|
// ss
|
|
34
31
|
/[^.]*/,
|
|
35
32
|
// .
|
|
36
|
-
|
|
33
|
+
/\D?/,
|
|
37
34
|
// sss
|
|
38
|
-
|
|
35
|
+
/.\d*/,
|
|
39
36
|
]);
|
|
40
|
-
|
|
41
|
-
const res = tokens.eachCheck(
|
|
37
|
+
log('Local Date and Time: "%s" => %O', tokens.value, tokens);
|
|
38
|
+
const res = tokens.eachCheck(datetimeTokenCheck.year, datetimeTokenCheck.hyphen, datetimeTokenCheck.month, datetimeTokenCheck.hyphen, datetimeTokenCheck.date, datetimeTokenCheck.localDateTimeSeparator, datetimeTokenCheck.hour, datetimeTokenCheck.colon, datetimeTokenCheck.minute, datetimeTokenCheck.colonOrEnd, datetimeTokenCheck.second, datetimeTokenCheck.decimalPointOrEnd, datetimeTokenCheck.secondFractionalPart, datetimeTokenCheck.extra);
|
|
42
39
|
if (!res.matched) {
|
|
43
|
-
|
|
40
|
+
log('Failed: %O', res);
|
|
44
41
|
}
|
|
45
42
|
return res;
|
|
46
43
|
};
|
|
47
|
-
exports.checkLocalDateAndTimeString = checkLocalDateAndTimeString;
|
|
48
44
|
/**
|
|
49
45
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-normalised-local-date-and-time-string
|
|
50
46
|
*/
|
|
51
|
-
const checkNormalizedLocalDateAndTimeString = () => function checkNormalizedLocalDateAndTimeString(value) {
|
|
52
|
-
|
|
53
|
-
const tokens =
|
|
47
|
+
export const checkNormalizedLocalDateAndTimeString = () => function checkNormalizedLocalDateAndTimeString(value) {
|
|
48
|
+
log('CHECK: normalized-local-date-and-time-string');
|
|
49
|
+
const tokens = TokenCollection.fromPatterns(value, [
|
|
54
50
|
// YYYY
|
|
55
51
|
/[^-]*/,
|
|
56
52
|
// -
|
|
57
|
-
|
|
53
|
+
/\D?/,
|
|
58
54
|
// MM
|
|
59
55
|
/[^-]*/,
|
|
60
56
|
// -
|
|
61
|
-
|
|
57
|
+
/\D?/,
|
|
62
58
|
// DD
|
|
63
59
|
/[^T]*/,
|
|
64
60
|
// T
|
|
65
|
-
|
|
61
|
+
/\D?/,
|
|
66
62
|
// hh
|
|
67
63
|
/[^:]*/,
|
|
68
64
|
// :
|
|
69
|
-
|
|
65
|
+
/\D?/,
|
|
70
66
|
// mm
|
|
71
67
|
/[^:]*/,
|
|
72
68
|
// :
|
|
73
|
-
|
|
69
|
+
/\D?/,
|
|
74
70
|
// ss
|
|
75
71
|
/[^.]*/,
|
|
76
72
|
// .
|
|
77
|
-
|
|
73
|
+
/\D?/,
|
|
78
74
|
// sss
|
|
79
|
-
|
|
75
|
+
/.\d*/,
|
|
80
76
|
]);
|
|
81
|
-
|
|
82
|
-
const res = tokens.eachCheck(
|
|
77
|
+
log('Normalized Local Date and Time: "%s" => %O', tokens.value, tokens);
|
|
78
|
+
const res = tokens.eachCheck(datetimeTokenCheck.year, datetimeTokenCheck.hyphen, datetimeTokenCheck.month, datetimeTokenCheck.hyphen, datetimeTokenCheck.date, datetimeTokenCheck.normalizedlocalDateTimeSeparator, datetimeTokenCheck.hour, datetimeTokenCheck.colon, datetimeTokenCheck.minute, datetimeTokenCheck.colonOrEnd, datetimeTokenCheck.second, datetimeTokenCheck.decimalPointOrEnd, datetimeTokenCheck.secondFractionalPart, datetimeTokenCheck.extra);
|
|
83
79
|
if (!res.matched) {
|
|
84
|
-
|
|
80
|
+
log('Failed: %O', res);
|
|
85
81
|
return res;
|
|
86
82
|
}
|
|
87
83
|
/**
|
|
@@ -90,20 +86,21 @@ const checkNormalizedLocalDateAndTimeString = () => function checkNormalizedLoca
|
|
|
90
86
|
* > (e.g. omitting the seconds component entirely
|
|
91
87
|
* > if the given time is zero seconds past the minute)
|
|
92
88
|
*/
|
|
93
|
-
const
|
|
89
|
+
const second = tokens[10];
|
|
90
|
+
const fp = tokens[12];
|
|
94
91
|
if (!second || !fp) {
|
|
95
|
-
|
|
92
|
+
log('Failed: %O', res);
|
|
96
93
|
return res;
|
|
97
94
|
}
|
|
98
95
|
const _second = second.toNumber();
|
|
99
96
|
const _fp = fp.toNumber();
|
|
100
|
-
|
|
97
|
+
log('Omitting the seconds component: "%s.%s" => %d, %d', second?.value, fp?.value, _second, _fp);
|
|
101
98
|
if (second.value && _second === 0 && (!fp.value || (fp.value && _fp === 0))) {
|
|
102
99
|
const res = second.unmatched({
|
|
103
100
|
partName: 'second',
|
|
104
101
|
reason: 'extra-token',
|
|
105
102
|
});
|
|
106
|
-
|
|
103
|
+
log('Failed: %O', res);
|
|
107
104
|
return res;
|
|
108
105
|
}
|
|
109
106
|
if (fp.value && _fp === 0) {
|
|
@@ -111,10 +108,9 @@ const checkNormalizedLocalDateAndTimeString = () => function checkNormalizedLoca
|
|
|
111
108
|
partName: 'fractional part',
|
|
112
109
|
reason: 'extra-token',
|
|
113
110
|
});
|
|
114
|
-
|
|
111
|
+
log('Failed: %O', res);
|
|
115
112
|
return res;
|
|
116
113
|
}
|
|
117
|
-
|
|
114
|
+
log('Failed: %O', res);
|
|
118
115
|
return res;
|
|
119
116
|
};
|
|
120
|
-
exports.checkNormalizedLocalDateAndTimeString = checkNormalizedLocalDateAndTimeString;
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../../debug");
|
|
5
|
-
const token_1 = require("../../token");
|
|
6
|
-
const datetime_tokens_1 = require("./datetime-tokens");
|
|
1
|
+
import { log } from '../../debug.js';
|
|
2
|
+
import { TokenCollection } from '../../token/index.js';
|
|
3
|
+
import { datetimeTokenCheck } from './datetime-tokens.js';
|
|
7
4
|
/**
|
|
8
5
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-month-string
|
|
9
6
|
*/
|
|
10
|
-
const checkMonthString = () => function checkMonthString(value) {
|
|
11
|
-
|
|
12
|
-
const tokens =
|
|
13
|
-
|
|
14
|
-
const res = tokens.eachCheck(
|
|
7
|
+
export const checkMonthString = () => function checkMonthString(value) {
|
|
8
|
+
log('CHECK: month-string');
|
|
9
|
+
const tokens = TokenCollection.fromPatterns(value, [/[^-]*/, /\D?/, /.\d*/]);
|
|
10
|
+
log('Month: "%s" => %O', tokens.value, tokens);
|
|
11
|
+
const res = tokens.eachCheck(datetimeTokenCheck.year, datetimeTokenCheck.hyphen, datetimeTokenCheck.month, datetimeTokenCheck.extra);
|
|
15
12
|
if (!res.matched) {
|
|
16
|
-
|
|
13
|
+
log('Failed: %O', res);
|
|
17
14
|
}
|
|
18
15
|
return res;
|
|
19
16
|
};
|
|
20
|
-
exports.checkMonthString = checkMonthString;
|
|
@@ -1,35 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../../debug");
|
|
5
|
-
const token_1 = require("../../token");
|
|
6
|
-
const datetime_tokens_1 = require("./datetime-tokens");
|
|
1
|
+
import { log } from '../../debug.js';
|
|
2
|
+
import { TokenCollection } from '../../token/index.js';
|
|
3
|
+
import { datetimeTokenCheck } from './datetime-tokens.js';
|
|
7
4
|
/**
|
|
8
5
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#times
|
|
9
6
|
*/
|
|
10
|
-
const checkTimeString = () => function checkTimeString(value) {
|
|
11
|
-
|
|
12
|
-
const tokens =
|
|
7
|
+
export const checkTimeString = () => function checkTimeString(value) {
|
|
8
|
+
log('CHECK: time-string');
|
|
9
|
+
const tokens = TokenCollection.fromPatterns(value, [
|
|
13
10
|
// hh
|
|
14
11
|
/[^:]*/,
|
|
15
12
|
// :
|
|
16
|
-
|
|
13
|
+
/\D?/,
|
|
17
14
|
// mm
|
|
18
15
|
/[^:]*/,
|
|
19
16
|
// :
|
|
20
|
-
|
|
17
|
+
/\D?/,
|
|
21
18
|
// ss
|
|
22
19
|
/[^.]*/,
|
|
23
20
|
// .
|
|
24
|
-
|
|
21
|
+
/\D?/,
|
|
25
22
|
// sss
|
|
26
|
-
|
|
23
|
+
/.\d*/,
|
|
27
24
|
]);
|
|
28
|
-
|
|
29
|
-
const res = tokens.eachCheck(
|
|
25
|
+
log('Time: "%s" => %O', tokens.value, tokens);
|
|
26
|
+
const res = tokens.eachCheck(datetimeTokenCheck.hour, datetimeTokenCheck.colon, datetimeTokenCheck.minute, datetimeTokenCheck.colonOrEnd, datetimeTokenCheck.second, datetimeTokenCheck.decimalPointOrEnd, datetimeTokenCheck.secondFractionalPart);
|
|
30
27
|
if (!res.matched) {
|
|
31
|
-
|
|
28
|
+
log('Failed: %O', res);
|
|
32
29
|
}
|
|
33
30
|
return res;
|
|
34
31
|
};
|
|
35
|
-
exports.checkTimeString = checkTimeString;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Token } from '../../token';
|
|
2
|
-
import type { CustomSyntaxChecker } from '../../types';
|
|
1
|
+
import type { Token } from '../../token/index.js';
|
|
2
|
+
import type { CustomSyntaxChecker } from '../../types.js';
|
|
3
3
|
/**
|
|
4
4
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#time-zones
|
|
5
5
|
*/
|
|
6
6
|
export declare const checkTimeZoneOffsetString: CustomSyntaxChecker;
|
|
7
|
-
export declare function parseTimeZone(zone: string | Readonly<Token>): import(
|
|
7
|
+
export declare function parseTimeZone(zone: string | Readonly<Token>): import("../../types.js").Result;
|
|
@@ -1,35 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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#time-zones
|
|
10
7
|
*/
|
|
11
|
-
const checkTimeZoneOffsetString = () => function checkTimeZoneOffsetString(value) {
|
|
12
|
-
|
|
8
|
+
export const checkTimeZoneOffsetString = () => function checkTimeZoneOffsetString(value) {
|
|
9
|
+
log('CHECK: time-zone-offset-string');
|
|
13
10
|
return parseTimeZone(value);
|
|
14
11
|
};
|
|
15
|
-
|
|
16
|
-
function parseTimeZone(zone) {
|
|
12
|
+
export function parseTimeZone(zone) {
|
|
17
13
|
const value = typeof zone === 'string' ? zone : zone.value;
|
|
18
|
-
const zoneTokens =
|
|
14
|
+
const zoneTokens = TokenCollection.fromPatterns(zone, [
|
|
19
15
|
// Z + -
|
|
20
|
-
|
|
16
|
+
/\D?/,
|
|
21
17
|
// hh
|
|
22
18
|
/[^:]{0,2}/,
|
|
23
19
|
// :
|
|
24
|
-
|
|
20
|
+
/\D?/,
|
|
25
21
|
// mm
|
|
26
|
-
|
|
22
|
+
/.\d*/,
|
|
27
23
|
]);
|
|
28
|
-
|
|
24
|
+
log('Time-zone Part: "%s" => %O', value, zoneTokens);
|
|
29
25
|
const res = zoneTokens.eachCheck((sign, tail) => {
|
|
30
|
-
var _a, _b;
|
|
31
26
|
if (!sign || !sign.value) {
|
|
32
|
-
return
|
|
27
|
+
return unmatched(value, 'missing-token', {
|
|
33
28
|
expects: [
|
|
34
29
|
{ type: 'const', value: 'Z' },
|
|
35
30
|
{ type: 'const', value: '+' },
|
|
@@ -38,15 +33,15 @@ function parseTimeZone(zone) {
|
|
|
38
33
|
partName: 'time-zone',
|
|
39
34
|
});
|
|
40
35
|
}
|
|
41
|
-
if (sign.
|
|
36
|
+
if (sign.matches('Z')) {
|
|
42
37
|
if (tail.value) {
|
|
43
|
-
return (
|
|
38
|
+
return (tail[0]?.unmatched({
|
|
44
39
|
reason: 'extra-token',
|
|
45
|
-
})
|
|
40
|
+
}) ?? unmatched(tail.value, 'extra-token'));
|
|
46
41
|
}
|
|
47
|
-
return
|
|
42
|
+
return matched();
|
|
48
43
|
}
|
|
49
|
-
if (!sign.
|
|
44
|
+
if (!sign.matches(['+', '-'])) {
|
|
50
45
|
return sign.unmatched({
|
|
51
46
|
reason: 'unexpected-token',
|
|
52
47
|
expects: [
|
|
@@ -56,21 +51,20 @@ function parseTimeZone(zone) {
|
|
|
56
51
|
partName: 'time-zone',
|
|
57
52
|
});
|
|
58
53
|
}
|
|
59
|
-
},
|
|
54
|
+
}, datetimeTokenCheck.hour, colon => {
|
|
60
55
|
if (!colon || !colon.value) {
|
|
61
56
|
return;
|
|
62
57
|
}
|
|
63
|
-
if (!colon.
|
|
58
|
+
if (!colon.matches(':')) {
|
|
64
59
|
return colon.unmatched({
|
|
65
60
|
reason: 'unexpected-token',
|
|
66
61
|
expects: [{ type: 'const', value: ':' }],
|
|
67
62
|
partName: 'time-zone',
|
|
68
63
|
});
|
|
69
64
|
}
|
|
70
|
-
},
|
|
65
|
+
}, datetimeTokenCheck.minute, datetimeTokenCheck.extra);
|
|
71
66
|
if (!res.matched) {
|
|
72
|
-
|
|
67
|
+
log('Failed: %O', res);
|
|
73
68
|
}
|
|
74
69
|
return res;
|
|
75
70
|
}
|
|
76
|
-
exports.parseTimeZone = parseTimeZone;
|
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../../debug");
|
|
5
|
-
const token_1 = require("../../token");
|
|
6
|
-
const datetime_tokens_1 = require("./datetime-tokens");
|
|
1
|
+
import { log } from '../../debug.js';
|
|
2
|
+
import { TokenCollection } from '../../token/index.js';
|
|
3
|
+
import { datetimeTokenCheck } from './datetime-tokens.js';
|
|
7
4
|
/**
|
|
8
5
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#weeks
|
|
9
6
|
*/
|
|
10
|
-
const checkWeekString = () => function checkWeekString(value) {
|
|
11
|
-
|
|
12
|
-
const tokens =
|
|
7
|
+
export const checkWeekString = () => function checkWeekString(value) {
|
|
8
|
+
log('CHECK: week-string');
|
|
9
|
+
const tokens = TokenCollection.fromPatterns(value, [
|
|
13
10
|
// YYYY
|
|
14
11
|
/[^-]+/,
|
|
15
12
|
// -
|
|
16
13
|
/[^W]?/,
|
|
17
14
|
// W
|
|
18
|
-
|
|
15
|
+
/\D?/,
|
|
19
16
|
// ww
|
|
20
|
-
|
|
17
|
+
/.\d*/,
|
|
21
18
|
]);
|
|
22
|
-
|
|
23
|
-
const res = tokens.eachCheck(
|
|
19
|
+
log('Week: "%s" => %O', tokens.value, tokens);
|
|
20
|
+
const res = tokens.eachCheck(datetimeTokenCheck.year, datetimeTokenCheck.hyphen, datetimeTokenCheck.weekSign, datetimeTokenCheck.week, datetimeTokenCheck.extra);
|
|
24
21
|
if (!res.matched) {
|
|
25
|
-
|
|
22
|
+
log('Failed: %O', res);
|
|
26
23
|
}
|
|
27
24
|
return res;
|
|
28
25
|
};
|
|
29
|
-
exports.checkWeekString = checkWeekString;
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../../debug");
|
|
5
|
-
const token_1 = require("../../token");
|
|
6
|
-
const datetime_tokens_1 = require("./datetime-tokens");
|
|
1
|
+
import { log } from '../../debug.js';
|
|
2
|
+
import { TokenCollection } from '../../token/index.js';
|
|
3
|
+
import { datetimeTokenCheck } from './datetime-tokens.js';
|
|
7
4
|
/**
|
|
8
5
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html
|
|
9
6
|
*/
|
|
10
|
-
const checkYearString = () => function checkYearString(value) {
|
|
11
|
-
|
|
12
|
-
const tokens =
|
|
13
|
-
|
|
14
|
-
const res = tokens.eachCheck(
|
|
7
|
+
export const checkYearString = () => function checkYearString(value) {
|
|
8
|
+
log('CHECK: year-string');
|
|
9
|
+
const tokens = TokenCollection.fromPatterns(value, [/.*/]);
|
|
10
|
+
log('Year: "%s" => %O', tokens.value, tokens);
|
|
11
|
+
const res = tokens.eachCheck(datetimeTokenCheck.year, datetimeTokenCheck.extra);
|
|
15
12
|
if (!res.matched) {
|
|
16
|
-
|
|
13
|
+
log('Failed: %O', res);
|
|
17
14
|
}
|
|
18
15
|
return res;
|
|
19
16
|
};
|
|
20
|
-
exports.checkYearString = checkYearString;
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../../debug");
|
|
5
|
-
const token_1 = require("../../token");
|
|
6
|
-
const datetime_tokens_1 = require("./datetime-tokens");
|
|
1
|
+
import { log } from '../../debug.js';
|
|
2
|
+
import { TokenCollection } from '../../token/index.js';
|
|
3
|
+
import { datetimeTokenCheck } from './datetime-tokens.js';
|
|
7
4
|
/**
|
|
8
5
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#yearless-dates
|
|
9
6
|
*/
|
|
10
|
-
const checkYearlessDateString = () => function checkYearlessDateString(value) {
|
|
11
|
-
|
|
12
|
-
const tokens =
|
|
7
|
+
export const checkYearlessDateString = () => function checkYearlessDateString(value) {
|
|
8
|
+
log('CHECK: yearless-date-string');
|
|
9
|
+
const tokens = TokenCollection.fromPatterns(value, [
|
|
13
10
|
// MM
|
|
14
11
|
/[^-]*/,
|
|
15
12
|
// -
|
|
16
|
-
|
|
13
|
+
/\D?/,
|
|
17
14
|
// DD
|
|
18
|
-
|
|
15
|
+
/.\d*/,
|
|
19
16
|
]);
|
|
20
|
-
|
|
21
|
-
const res = tokens.eachCheck(
|
|
17
|
+
log('Yearless Date: "%s" => %O', tokens.value, tokens);
|
|
18
|
+
const res = tokens.eachCheck(datetimeTokenCheck.month, datetimeTokenCheck.hyphen, datetimeTokenCheck.date, datetimeTokenCheck.extra);
|
|
22
19
|
if (!res.matched) {
|
|
23
|
-
|
|
20
|
+
log('Failed: %O', res);
|
|
24
21
|
}
|
|
25
22
|
return res;
|
|
26
23
|
};
|
|
27
|
-
exports.checkYearlessDateString = checkYearlessDateString;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { CustomSyntaxChecker } from '../types';
|
|
1
|
+
import type { CustomSyntaxChecker } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* MIME Type
|
|
4
4
|
* @see https://mimesniff.spec.whatwg.org/#valid-mime-type
|
|
5
5
|
*/
|
|
6
6
|
export declare const checkMIMEType: CustomSyntaxChecker<{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @see https://mimesniff.spec.whatwg.org/#valid-mime-type-with-no-parameters
|
|
9
|
+
*/
|
|
10
|
+
withoutParameters?: boolean;
|
|
11
11
|
}>;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkMIMEType = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
1
|
// @ts-ignore
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import MIMEType from 'whatwg-mimetype';
|
|
3
|
+
import { matched, unmatched } from '../match-result.js';
|
|
4
|
+
import { Token } from '../token/index.js';
|
|
9
5
|
const expects = (withoutParameters) => [
|
|
10
6
|
{
|
|
11
7
|
type: 'format',
|
|
@@ -16,27 +12,25 @@ const expects = (withoutParameters) => [
|
|
|
16
12
|
* MIME Type
|
|
17
13
|
* @see https://mimesniff.spec.whatwg.org/#valid-mime-type
|
|
18
14
|
*/
|
|
19
|
-
const checkMIMEType = options => value => {
|
|
20
|
-
|
|
21
|
-
const withoutParameters = (_a = options === null || options === void 0 ? void 0 : options.withoutParameters) !== null && _a !== void 0 ? _a : false;
|
|
15
|
+
export const checkMIMEType = options => value => {
|
|
16
|
+
const withoutParameters = options?.withoutParameters ?? false;
|
|
22
17
|
if (!value) {
|
|
23
|
-
return
|
|
18
|
+
return unmatched(value, 'empty-token', { expects: expects(withoutParameters) });
|
|
24
19
|
}
|
|
25
|
-
const mimeType =
|
|
20
|
+
const mimeType = MIMEType.parse(value);
|
|
26
21
|
if (mimeType) {
|
|
27
22
|
if (value.toLowerCase() === mimeType.essence) {
|
|
28
|
-
return
|
|
23
|
+
return matched();
|
|
29
24
|
}
|
|
30
25
|
if (!withoutParameters && mimeType.parameters.size > 0) {
|
|
31
|
-
return
|
|
26
|
+
return matched();
|
|
32
27
|
}
|
|
33
28
|
const extraToken = value.slice(mimeType.essence.length);
|
|
34
|
-
return new
|
|
29
|
+
return new Token(extraToken, mimeType.essence.length, value).unmatched({
|
|
35
30
|
reason: 'extra-token',
|
|
36
31
|
expects: expects(withoutParameters),
|
|
37
32
|
candidate: mimeType.essence,
|
|
38
33
|
});
|
|
39
34
|
}
|
|
40
|
-
return
|
|
35
|
+
return unmatched(value, 'syntax-error', { expects: expects(withoutParameters) });
|
|
41
36
|
};
|
|
42
|
-
exports.checkMIMEType = checkMIMEType;
|
package/lib/whatwg/is-abs-url.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isAbsURL = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* @see https://url.spec.whatwg.org/#syntax-url-absolute
|
|
6
3
|
*
|
|
@@ -14,21 +11,20 @@ exports.isAbsURL = void 0;
|
|
|
14
11
|
* > followed by U+003A (:) and a scheme-relative-file-URL string
|
|
15
12
|
*
|
|
16
13
|
*/
|
|
17
|
-
const isAbsURL = () => {
|
|
14
|
+
export const isAbsURL = () => {
|
|
18
15
|
return value => {
|
|
19
16
|
try {
|
|
20
17
|
new URL(value);
|
|
21
18
|
}
|
|
22
|
-
catch (
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error &&
|
|
21
|
+
typeof error === 'object' &&
|
|
22
|
+
'code' in error && // @ts-ignore
|
|
23
|
+
error.code === 'ERR_INVALID_URL') {
|
|
24
|
+
return false;
|
|
28
25
|
}
|
|
29
|
-
throw
|
|
26
|
+
throw error;
|
|
30
27
|
}
|
|
31
28
|
return true;
|
|
32
29
|
};
|
|
33
30
|
};
|
|
34
|
-
exports.isAbsURL = isAbsURL;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBrowserContextName = void 0;
|
|
4
1
|
/**
|
|
5
2
|
*
|
|
6
3
|
* @see https://html.spec.whatwg.org/multipage/browsers.html#valid-browsing-context-name
|
|
@@ -12,9 +9,8 @@ exports.isBrowserContextName = void 0;
|
|
|
12
9
|
* @deprecated
|
|
13
10
|
*
|
|
14
11
|
*/
|
|
15
|
-
const isBrowserContextName = () => {
|
|
12
|
+
export const isBrowserContextName = () => {
|
|
16
13
|
return value => {
|
|
17
14
|
return !!value && value[0] !== '_';
|
|
18
15
|
};
|
|
19
16
|
};
|
|
20
|
-
exports.isBrowserContextName = isBrowserContextName;
|