@markuplint/types 3.0.0-alpha.2 → 3.0.0-alpha.27

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 (72) hide show
  1. package/README.md +12 -8
  2. package/lib/css-syntax.js +6 -6
  3. package/lib/defs.js +1 -0
  4. package/lib/get-candidate.d.ts +1 -1
  5. package/lib/token/token-collection.d.ts +2 -2
  6. package/lib/token/token-collection.js +47 -47
  7. package/lib/token/token.js +7 -7
  8. package/lib/types.d.ts +16 -16
  9. package/lib/types.schema.d.ts +5 -5
  10. package/package.json +7 -5
  11. package/patches/css-tree+2.3.1.patch +23 -0
  12. package/types.schema.json +67 -16
  13. package/gen/specific-schema.json +0 -98
  14. package/gen/types.ts +0 -66
  15. package/src/check-multi-types.ts +0 -35
  16. package/src/check.spec.ts +0 -83
  17. package/src/check.ts +0 -48
  18. package/src/css-syntax.spec.ts +0 -167
  19. package/src/css-syntax.ts +0 -188
  20. package/src/debug.ts +0 -3
  21. package/src/defs.ts +0 -810
  22. package/src/enum.ts +0 -25
  23. package/src/get-candidate.ts +0 -24
  24. package/src/index.ts +0 -3
  25. package/src/keyword-type.ts +0 -64
  26. package/src/list.spec.ts +0 -133
  27. package/src/list.ts +0 -34
  28. package/src/match-result.ts +0 -49
  29. package/src/number.ts +0 -46
  30. package/src/primitive/index.spec.ts +0 -65
  31. package/src/primitive/index.ts +0 -7
  32. package/src/primitive/is-float.ts +0 -8
  33. package/src/primitive/is-int.ts +0 -8
  34. package/src/primitive/is-non-zero-uint.ts +0 -8
  35. package/src/primitive/is-quantity.ts +0 -38
  36. package/src/primitive/is-uint.ts +0 -15
  37. package/src/primitive/range.ts +0 -14
  38. package/src/primitive/split-unit.ts +0 -20
  39. package/src/rfc/is-bcp-47.spec.ts +0 -23
  40. package/src/rfc/is-bcp-47.ts +0 -13
  41. package/src/token/index.ts +0 -2
  42. package/src/token/token-collection.spec.ts +0 -147
  43. package/src/token/token-collection.ts +0 -444
  44. package/src/token/token.ts +0 -144
  45. package/src/types.schema.ts +0 -1062
  46. package/src/types.ts +0 -118
  47. package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
  48. package/src/w3c/check-serialized-permissions-policy.ts +0 -303
  49. package/src/whatwg/check-autocomplete.spec.ts +0 -387
  50. package/src/whatwg/check-autocomplete.ts +0 -380
  51. package/src/whatwg/check-datetime/date-string.ts +0 -44
  52. package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
  53. package/src/whatwg/check-datetime/duration-string.ts +0 -399
  54. package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
  55. package/src/whatwg/check-datetime/index.spec.ts +0 -333
  56. package/src/whatwg/check-datetime/index.ts +0 -36
  57. package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
  58. package/src/whatwg/check-datetime/month-string.ts +0 -31
  59. package/src/whatwg/check-datetime/time-string.ts +0 -49
  60. package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
  61. package/src/whatwg/check-datetime/week-string.ts +0 -41
  62. package/src/whatwg/check-datetime/year-string.ts +0 -26
  63. package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
  64. package/src/whatwg/check-mime-type.spec.ts +0 -59
  65. package/src/whatwg/check-mime-type.ts +0 -46
  66. package/src/whatwg/is-abs-url.spec.ts +0 -8
  67. package/src/whatwg/is-abs-url.ts +0 -31
  68. package/src/whatwg/is-browser-context-name.ts +0 -16
  69. package/src/whatwg/is-custom-element-name.ts +0 -76
  70. package/src/whatwg/is-itemprop-name.ts +0 -17
  71. package/tsconfig.test.json +0 -3
  72. package/tsconfig.tsbuildinfo +0 -1
@@ -1,93 +0,0 @@
1
- import type { Token } from '../../token';
2
- import type { CustomSyntaxChecker } from '../../types';
3
-
4
- import { log } from '../../debug';
5
- import { matched, unmatched } from '../../match-result';
6
- import { TokenCollection } from '../../token';
7
-
8
- import { datetimeTokenCheck } from './datetime-tokens';
9
-
10
- /**
11
- * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#time-zones
12
- */
13
- export const checkTimeZoneOffsetString: CustomSyntaxChecker = () =>
14
- function checkTimeZoneOffsetString(value) {
15
- log('CHECK: time-zone-offset-string');
16
-
17
- return parseTimeZone(value);
18
- };
19
-
20
- export function parseTimeZone(zone: string | Token) {
21
- const value = typeof zone === 'string' ? zone : zone.value;
22
-
23
- const zoneTokens = TokenCollection.fromPatterns(zone, [
24
- // Z + -
25
- /[^0-9]?/,
26
- // hh
27
- /[^:]{0,2}/,
28
- // :
29
- /[^0-9]?/,
30
- // mm
31
- /.[0-9]*/,
32
- ]);
33
-
34
- log('Time-zone Part: "%s" => %O', value, zoneTokens);
35
-
36
- const res = zoneTokens.eachCheck(
37
- (sign, tail) => {
38
- if (!sign || !sign.value) {
39
- return unmatched(value, 'missing-token', {
40
- expects: [
41
- { type: 'const', value: 'Z' },
42
- { type: 'const', value: '+' },
43
- { type: 'const', value: '-' },
44
- ],
45
- partName: 'time-zone',
46
- });
47
- }
48
-
49
- if (sign.match('Z')) {
50
- if (tail.value) {
51
- return tail[0].unmatched({
52
- reason: 'extra-token',
53
- });
54
- }
55
-
56
- return matched();
57
- }
58
-
59
- if (!sign.match(['+', '-'])) {
60
- return sign.unmatched({
61
- reason: 'unexpected-token',
62
- expects: [
63
- { type: 'const', value: '+' },
64
- { type: 'const', value: '-' },
65
- ],
66
- partName: 'time-zone',
67
- });
68
- }
69
- },
70
- datetimeTokenCheck.hour,
71
- colon => {
72
- if (!colon || !colon.value) {
73
- return;
74
- }
75
-
76
- if (!colon.match(':')) {
77
- return colon.unmatched({
78
- reason: 'unexpected-token',
79
- expects: [{ type: 'const', value: ':' }],
80
- partName: 'time-zone',
81
- });
82
- }
83
- },
84
- datetimeTokenCheck.minute,
85
- datetimeTokenCheck.extra,
86
- );
87
-
88
- if (!res.matched) {
89
- log('Failed: %O', res);
90
- }
91
-
92
- return res;
93
- }
@@ -1,41 +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#weeks
10
- */
11
- export const checkWeekString: CustomSyntaxChecker = () =>
12
- function checkWeekString(value) {
13
- log('CHECK: week-string');
14
-
15
- const tokens = TokenCollection.fromPatterns(value, [
16
- // YYYY
17
- /[^-]+/,
18
- // -
19
- /[^W]?/,
20
- // W
21
- /[^0-9]?/,
22
- // ww
23
- /.[0-9]*/,
24
- ]);
25
-
26
- log('Week: "%s" => %O', tokens.value, tokens);
27
-
28
- const res = tokens.eachCheck(
29
- datetimeTokenCheck.year,
30
- datetimeTokenCheck.hyphen,
31
- datetimeTokenCheck.weekSign,
32
- datetimeTokenCheck.week,
33
- datetimeTokenCheck.extra,
34
- );
35
-
36
- if (!res.matched) {
37
- log('Failed: %O', res);
38
- }
39
-
40
- return res;
41
- };
@@ -1,26 +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
10
- */
11
- export const checkYearString: CustomSyntaxChecker = () =>
12
- function checkYearString(value) {
13
- log('CHECK: year-string');
14
-
15
- const tokens = TokenCollection.fromPatterns(value, [/.*/]);
16
-
17
- log('Year: "%s" => %O', tokens.value, tokens);
18
-
19
- const res = tokens.eachCheck(datetimeTokenCheck.year, datetimeTokenCheck.extra);
20
-
21
- if (!res.matched) {
22
- log('Failed: %O', res);
23
- }
24
-
25
- return res;
26
- };
@@ -1,38 +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#yearless-dates
10
- */
11
- export const checkYearlessDateString: CustomSyntaxChecker = () =>
12
- function checkYearlessDateString(value) {
13
- log('CHECK: yearless-date-string');
14
-
15
- const tokens = TokenCollection.fromPatterns(value, [
16
- // MM
17
- /[^-]*/,
18
- // -
19
- /[^0-9]?/,
20
- // DD
21
- /.[0-9]*/,
22
- ]);
23
-
24
- log('Yearless Date: "%s" => %O', tokens.value, tokens);
25
-
26
- const res = tokens.eachCheck(
27
- datetimeTokenCheck.month,
28
- datetimeTokenCheck.hyphen,
29
- datetimeTokenCheck.date,
30
- datetimeTokenCheck.extra,
31
- );
32
-
33
- if (!res.matched) {
34
- log('Failed: %O', res);
35
- }
36
-
37
- return res;
38
- };
@@ -1,59 +0,0 @@
1
- import { checkMIMEType } from './check-mime-type';
2
-
3
- const check = checkMIMEType();
4
- const checkNoParam = checkMIMEType({ withoutParameters: true });
5
-
6
- test('valid', () => {
7
- expect(check('x/y').matched).toBe(true);
8
- expect(check('x/y;a=b;c=D;E="F"').matched).toBe(true);
9
- });
10
-
11
- test('excrescence-token', () => {
12
- expect(check('xy;')).toStrictEqual({
13
- column: 1,
14
- expects: [{ type: 'format', value: 'MIME Type' }],
15
- length: 3,
16
- line: 1,
17
- matched: false,
18
- offset: 0,
19
- raw: 'xy;',
20
- reason: 'syntax-error',
21
- ref: null,
22
- });
23
- expect(check('x/y;')).toStrictEqual({
24
- candidate: 'x/y',
25
- column: 4,
26
- expects: [{ type: 'format', value: 'MIME Type' }],
27
- length: 1,
28
- line: 1,
29
- matched: false,
30
- offset: 3,
31
- raw: ';',
32
- reason: 'extra-token',
33
- ref: null,
34
- });
35
- expect(checkNoParam('x/y;')).toStrictEqual({
36
- candidate: 'x/y',
37
- column: 4,
38
- expects: [{ type: 'format', value: 'MIME Type with no parameters' }],
39
- length: 1,
40
- line: 1,
41
- matched: false,
42
- offset: 3,
43
- raw: ';',
44
- reason: 'extra-token',
45
- ref: null,
46
- });
47
- expect(checkNoParam('x/y;a=b;c=D;E="F"')).toStrictEqual({
48
- candidate: 'x/y',
49
- column: 4,
50
- expects: [{ type: 'format', value: 'MIME Type with no parameters' }],
51
- length: 14,
52
- line: 1,
53
- matched: false,
54
- offset: 3,
55
- raw: ';a=b;c=D;E="F"',
56
- reason: 'extra-token',
57
- ref: null,
58
- });
59
- });
@@ -1,46 +0,0 @@
1
- import type { CustomSyntaxChecker } from '../types';
2
-
3
- // @ts-ignore
4
- import MIMEType from 'whatwg-mimetype';
5
-
6
- import { matched, unmatched } from '../match-result';
7
- import { Token } from '../token';
8
-
9
- const expects = (withoutParameters: boolean) => [
10
- {
11
- type: 'format' as const,
12
- value: withoutParameters ? 'MIME Type with no parameters' : 'MIME Type',
13
- },
14
- ];
15
-
16
- /**
17
- * MIME Type
18
- * @see https://mimesniff.spec.whatwg.org/#valid-mime-type
19
- */
20
- export const checkMIMEType: CustomSyntaxChecker<{
21
- /**
22
- * @see https://mimesniff.spec.whatwg.org/#valid-mime-type-with-no-parameters
23
- */
24
- withoutParameters?: boolean;
25
- }> = options => value => {
26
- const withoutParameters = options?.withoutParameters ?? false;
27
- if (!value) {
28
- return unmatched(value, 'empty-token', { expects: expects(withoutParameters) });
29
- }
30
- const mimeType = MIMEType.parse(value);
31
- if (mimeType) {
32
- if (value.toLowerCase() === mimeType.essence) {
33
- return matched();
34
- }
35
- if (!withoutParameters && mimeType.parameters.size) {
36
- return matched();
37
- }
38
- const extraToken = value.slice(mimeType.essence.length);
39
- return new Token(extraToken, mimeType.essence.length, value).unmatched({
40
- reason: 'extra-token',
41
- expects: expects(withoutParameters),
42
- candidate: mimeType.essence,
43
- });
44
- }
45
- return unmatched(value, 'syntax-error', { expects: expects(withoutParameters) });
46
- };
@@ -1,8 +0,0 @@
1
- import { isAbsURL } from './is-abs-url';
2
-
3
- const is = isAbsURL();
4
-
5
- test('valid', () => {
6
- expect(is('https://markuplint.dev')).toBe(true);
7
- expect(is('markuplint.dev')).toBe(false);
8
- });
@@ -1,31 +0,0 @@
1
- import type { FormattedPrimitiveTypeCreator } from '../types';
2
-
3
- /**
4
- * @see https://url.spec.whatwg.org/#syntax-url-absolute
5
- *
6
- * > An absolute-URL string must be one of the following:
7
- * > - a URL-scheme string that is an ASCII case-insensitive match
8
- * > for a special scheme and not an ASCII case-insensitive match for "file",
9
- * > followed by U+003A (:) and a scheme-relative-special-URL string
10
- * > - a URL-scheme string that is not an ASCII case-insensitive match
11
- * > for a special scheme, followed by U+003A (:) and a relative-URL string
12
- * > - a URL-scheme string that is an ASCII case-insensitive match for "file",
13
- * > followed by U+003A (:) and a scheme-relative-file-URL string
14
- *
15
- */
16
- export const isAbsURL: FormattedPrimitiveTypeCreator = () => {
17
- return value => {
18
- try {
19
- new URL(value);
20
- } catch (e: unknown) {
21
- if (e && typeof e === 'object' && 'code' in e) {
22
- // @ts-ignore
23
- if (e.code === 'ERR_INVALID_URL') {
24
- return false;
25
- }
26
- }
27
- throw e;
28
- }
29
- return true;
30
- };
31
- };
@@ -1,16 +0,0 @@
1
- import type { FormattedPrimitiveTypeCreator } from '../types';
2
-
3
- /**
4
- *
5
- * @see https://html.spec.whatwg.org/multipage/browsers.html#valid-browsing-context-name
6
- *
7
- * > A valid browsing context name is any string with at least one character
8
- * > that does not start with a U+005F LOW LINE character.
9
- * > (Names starting with an underscore are reserved for special keywords.)
10
- *
11
- */
12
- export const isBrowserContextName: FormattedPrimitiveTypeCreator = () => {
13
- return value => {
14
- return !!value && value[0] !== '_';
15
- };
16
- };
@@ -1,76 +0,0 @@
1
- import type { FormattedPrimitiveTypeCreator } from '../types';
2
-
3
- /**
4
- * PotentialCustomElementName
5
- *
6
- * @see https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname
7
- *
8
- * > PotentialCustomElementName ::=
9
- * > [a-z] (PCENChar)* '-' (PCENChar)*
10
- * > PCENChar ::=
11
- * > "-" | "." | [0-9] | "_" | [a-z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] |
12
- * > [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
13
- * > This uses the EBNF notation from the XML specification. [XML]
14
- *
15
- * ASCII-case-insensitively.
16
- * Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
17
- */
18
- const rePCENChar = [
19
- '\\-',
20
- '\\.',
21
- '[0-9]',
22
- '_',
23
- '[a-z]',
24
- '\u00B7',
25
- '[\u00C0-\u00D6]',
26
- '[\u00D8-\u00F6]',
27
- '[\u00F8-\u037D]',
28
- '[\u037F-\u1FFF]',
29
- '[\u200C-\u200D]',
30
- '[\u203F-\u2040]',
31
- '[\u2070-\u218F]',
32
- '[\u2C00-\u2FEF]',
33
- '[\u3001-\uD7FF]',
34
- '[\uF900-\uFDCF]',
35
- '[\uFDF0-\uFFFD]',
36
- '[\uD800-\uDBFF][\uDC00-\uDFFF]',
37
- ].join('|');
38
- const rePCEN = new RegExp(`^[a-z](?:${rePCENChar})*\\-(?:${rePCENChar})*$`, 'i');
39
-
40
- /**
41
- * valid name of custom element
42
- *
43
- * @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
44
- *
45
- * > - name must match the [PotentialCustomElementName](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname) production
46
- * > - name must not be any of the following:
47
- * > - `<annotation-xml>`
48
- * > - `<color-profile>`
49
- * > - `<font-face>`
50
- * > - `<font-face-src>`
51
- * > - `<font-face-uri>`
52
- * > - `<font-face-format>`
53
- * > - `<font-face-name>`
54
- * > - `<missing-glyph>`
55
- *
56
- * ASCII-case-insensitively.
57
- * Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
58
- *
59
- */
60
- export const isCustomElementName: FormattedPrimitiveTypeCreator = () => {
61
- return tagName => {
62
- switch (tagName) {
63
- case 'annotation-xml':
64
- case 'color-profile':
65
- case 'font-face':
66
- case 'font-face-src':
67
- case 'font-face-uri':
68
- case 'font-face-format':
69
- case 'font-face-name':
70
- case 'missing-glyph': {
71
- return false;
72
- }
73
- }
74
- return rePCEN.test(tagName);
75
- };
76
- };
@@ -1,17 +0,0 @@
1
- import type { FormattedPrimitiveTypeCreator } from '../types';
2
-
3
- /**
4
- *
5
- * @see https://html.spec.whatwg.org/multipage/microdata.html#defined-property-name
6
- *
7
- * > The rules above disallow U+003A COLON characters (:) in non-URL values
8
- * > because otherwise they could not be distinguished from URLs.
9
- * > Values with U+002E FULL STOP characters (.) are reserved for future extensions.
10
- * > ASCII whitespace are disallowed because otherwise the values would be parsed as multiple tokens.
11
- *
12
- */
13
- export const isItempropName: FormattedPrimitiveTypeCreator = () => {
14
- return value => {
15
- return value.indexOf(':') === -1 && value.indexOf('.') === -1 && value.indexOf(' ') === -1;
16
- };
17
- };
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.json"
3
- }