@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.
Files changed (177) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +117 -0
  3. package/extends.json +12 -0
  4. package/gen/specific-schema.json +98 -0
  5. package/gen/types.ts +66 -0
  6. package/lib/check-multi-types.d.ts +2 -0
  7. package/lib/check-multi-types.js +29 -0
  8. package/lib/check.d.ts +8 -0
  9. package/lib/check.js +49 -0
  10. package/lib/check.spec.d.ts +1 -0
  11. package/lib/check.spec.js +57 -0
  12. package/lib/css-syntax.d.ts +2 -0
  13. package/lib/css-syntax.js +141 -0
  14. package/lib/css-syntax.spec.d.ts +1 -0
  15. package/lib/css-syntax.spec.js +157 -0
  16. package/lib/debug.d.ts +2 -0
  17. package/lib/debug.js +6 -0
  18. package/lib/defs.d.ts +3 -0
  19. package/lib/defs.js +752 -0
  20. package/lib/enum.d.ts +3 -0
  21. package/lib/enum.js +26 -0
  22. package/lib/get-candicate.d.ts +3 -0
  23. package/lib/get-candicate.js +26 -0
  24. package/lib/index.d.ts +3 -0
  25. package/lib/index.js +6 -0
  26. package/lib/keyword-type.d.ts +3 -0
  27. package/lib/keyword-type.js +46 -0
  28. package/lib/list.d.ts +3 -0
  29. package/lib/list.js +29 -0
  30. package/lib/list.spec.d.ts +1 -0
  31. package/lib/list.spec.js +129 -0
  32. package/lib/match-result.d.ts +9 -0
  33. package/lib/match-result.js +33 -0
  34. package/lib/number.d.ts +3 -0
  35. package/lib/number.js +41 -0
  36. package/lib/primitive/index.d.ts +7 -0
  37. package/lib/primitive/index.js +17 -0
  38. package/lib/primitive/index.spec.d.ts +1 -0
  39. package/lib/primitive/index.spec.js +62 -0
  40. package/lib/primitive/is-float.d.ts +6 -0
  41. package/lib/primitive/is-float.js +12 -0
  42. package/lib/primitive/is-int.d.ts +6 -0
  43. package/lib/primitive/is-int.js +12 -0
  44. package/lib/primitive/is-non-zero-uint.d.ts +6 -0
  45. package/lib/primitive/is-non-zero-uint.js +12 -0
  46. package/lib/primitive/is-quantity.d.ts +7 -0
  47. package/lib/primitive/is-quantity.js +41 -0
  48. package/lib/primitive/is-uint.d.ts +8 -0
  49. package/lib/primitive/is-uint.js +19 -0
  50. package/lib/primitive/range.d.ts +8 -0
  51. package/lib/primitive/range.js +18 -0
  52. package/lib/primitive/split-unit.d.ts +9 -0
  53. package/lib/primitive/split-unit.js +24 -0
  54. package/lib/rfc/is-bcp-47.d.ts +5 -0
  55. package/lib/rfc/is-bcp-47.js +14 -0
  56. package/lib/rfc/is-bcp-47.spec.d.ts +1 -0
  57. package/lib/rfc/is-bcp-47.spec.js +19 -0
  58. package/lib/token/index.d.ts +2 -0
  59. package/lib/token/index.js +7 -0
  60. package/lib/token/token-collection.d.ts +62 -0
  61. package/lib/token/token-collection.js +383 -0
  62. package/lib/token/token-collection.spec.d.ts +1 -0
  63. package/lib/token/token-collection.spec.js +144 -0
  64. package/lib/token/token.d.ts +55 -0
  65. package/lib/token/token.js +128 -0
  66. package/lib/types.d.ts +78 -0
  67. package/lib/types.js +2 -0
  68. package/lib/types.schema.d.ts +54 -0
  69. package/lib/types.schema.js +8 -0
  70. package/lib/w3c/check-serialized-permissions-policy.d.ts +15 -0
  71. package/lib/w3c/check-serialized-permissions-policy.js +251 -0
  72. package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +1 -0
  73. package/lib/w3c/check-serialized-permissions-policy.spec.js +26 -0
  74. package/lib/whatwg/check-autocomplete.d.ts +5 -0
  75. package/lib/whatwg/check-autocomplete.js +282 -0
  76. package/lib/whatwg/check-autocomplete.spec.d.ts +1 -0
  77. package/lib/whatwg/check-autocomplete.spec.js +370 -0
  78. package/lib/whatwg/check-datetime/date-string.d.ts +5 -0
  79. package/lib/whatwg/check-datetime/date-string.js +31 -0
  80. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +3 -0
  81. package/lib/whatwg/check-datetime/datetime-tokens.js +509 -0
  82. package/lib/whatwg/check-datetime/duration-string.d.ts +6 -0
  83. package/lib/whatwg/check-datetime/duration-string.js +322 -0
  84. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +5 -0
  85. package/lib/whatwg/check-datetime/global-date-and-time-string.js +66 -0
  86. package/lib/whatwg/check-datetime/index.d.ts +5 -0
  87. package/lib/whatwg/check-datetime/index.js +35 -0
  88. package/lib/whatwg/check-datetime/index.spec.d.ts +1 -0
  89. package/lib/whatwg/check-datetime/index.spec.js +318 -0
  90. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +9 -0
  91. package/lib/whatwg/check-datetime/local-date-and-time-string.js +116 -0
  92. package/lib/whatwg/check-datetime/month-string.d.ts +5 -0
  93. package/lib/whatwg/check-datetime/month-string.js +20 -0
  94. package/lib/whatwg/check-datetime/time-string.d.ts +5 -0
  95. package/lib/whatwg/check-datetime/time-string.js +35 -0
  96. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +7 -0
  97. package/lib/whatwg/check-datetime/time-zone-offset-string.js +75 -0
  98. package/lib/whatwg/check-datetime/week-string.d.ts +5 -0
  99. package/lib/whatwg/check-datetime/week-string.js +29 -0
  100. package/lib/whatwg/check-datetime/year-string.d.ts +5 -0
  101. package/lib/whatwg/check-datetime/year-string.js +20 -0
  102. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +5 -0
  103. package/lib/whatwg/check-datetime/yearless-date-string.js +27 -0
  104. package/lib/whatwg/check-mime-type.d.ts +11 -0
  105. package/lib/whatwg/check-mime-type.js +42 -0
  106. package/lib/whatwg/check-mime-type.spec.d.ts +1 -0
  107. package/lib/whatwg/check-mime-type.spec.js +58 -0
  108. package/lib/whatwg/is-abs-url.d.ts +15 -0
  109. package/lib/whatwg/is-abs-url.js +34 -0
  110. package/lib/whatwg/is-abs-url.spec.d.ts +1 -0
  111. package/lib/whatwg/is-abs-url.spec.js +8 -0
  112. package/lib/whatwg/is-browser-context-name.d.ts +11 -0
  113. package/lib/whatwg/is-browser-context-name.js +18 -0
  114. package/lib/whatwg/is-custom-element-name.d.ts +22 -0
  115. package/lib/whatwg/is-custom-element-name.js +77 -0
  116. package/lib/whatwg/is-itemprop-name.d.ts +12 -0
  117. package/lib/whatwg/is-itemprop-name.js +19 -0
  118. package/package.json +33 -0
  119. package/src/check-multi-types.ts +35 -0
  120. package/src/check.spec.ts +62 -0
  121. package/src/check.ts +48 -0
  122. package/src/css-syntax.spec.ts +167 -0
  123. package/src/css-syntax.ts +177 -0
  124. package/src/debug.ts +3 -0
  125. package/src/defs.ts +810 -0
  126. package/src/enum.ts +25 -0
  127. package/src/get-candicate.ts +24 -0
  128. package/src/index.ts +3 -0
  129. package/src/keyword-type.ts +52 -0
  130. package/src/list.spec.ts +133 -0
  131. package/src/list.ts +34 -0
  132. package/src/match-result.ts +49 -0
  133. package/src/number.ts +46 -0
  134. package/src/primitive/index.spec.ts +65 -0
  135. package/src/primitive/index.ts +7 -0
  136. package/src/primitive/is-float.ts +8 -0
  137. package/src/primitive/is-int.ts +8 -0
  138. package/src/primitive/is-non-zero-uint.ts +8 -0
  139. package/src/primitive/is-quantity.ts +38 -0
  140. package/src/primitive/is-uint.ts +15 -0
  141. package/src/primitive/range.ts +14 -0
  142. package/src/primitive/split-unit.ts +20 -0
  143. package/src/rfc/is-bcp-47.spec.ts +23 -0
  144. package/src/rfc/is-bcp-47.ts +13 -0
  145. package/src/token/index.ts +2 -0
  146. package/src/token/token-collection.spec.ts +147 -0
  147. package/src/token/token-collection.ts +444 -0
  148. package/src/token/token.ts +144 -0
  149. package/src/types.schema.ts +1059 -0
  150. package/src/types.ts +118 -0
  151. package/src/w3c/check-serialized-permissions-policy.spec.ts +27 -0
  152. package/src/w3c/check-serialized-permissions-policy.ts +287 -0
  153. package/src/whatwg/check-autocomplete.spec.ts +378 -0
  154. package/src/whatwg/check-autocomplete.ts +324 -0
  155. package/src/whatwg/check-datetime/date-string.ts +44 -0
  156. package/src/whatwg/check-datetime/datetime-tokens.ts +600 -0
  157. package/src/whatwg/check-datetime/duration-string.ts +399 -0
  158. package/src/whatwg/check-datetime/global-date-and-time-string.ts +96 -0
  159. package/src/whatwg/check-datetime/index.spec.ts +333 -0
  160. package/src/whatwg/check-datetime/index.ts +36 -0
  161. package/src/whatwg/check-datetime/local-date-and-time-string.ts +163 -0
  162. package/src/whatwg/check-datetime/month-string.ts +31 -0
  163. package/src/whatwg/check-datetime/time-string.ts +49 -0
  164. package/src/whatwg/check-datetime/time-zone-offset-string.ts +93 -0
  165. package/src/whatwg/check-datetime/week-string.ts +41 -0
  166. package/src/whatwg/check-datetime/year-string.ts +26 -0
  167. package/src/whatwg/check-datetime/yearless-date-string.ts +38 -0
  168. package/src/whatwg/check-mime-type.spec.ts +59 -0
  169. package/src/whatwg/check-mime-type.ts +46 -0
  170. package/src/whatwg/is-abs-url.spec.ts +8 -0
  171. package/src/whatwg/is-abs-url.ts +31 -0
  172. package/src/whatwg/is-browser-context-name.ts +16 -0
  173. package/src/whatwg/is-custom-element-name.ts +76 -0
  174. package/src/whatwg/is-itemprop-name.ts +17 -0
  175. package/tsconfig.test.json +3 -0
  176. package/tsconfig.tsbuildinfo +1 -0
  177. package/types.schema.json +1092 -0
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkYearString = void 0;
4
+ const debug_1 = require("../../debug");
5
+ const token_1 = require("../../token");
6
+ const datetime_tokens_1 = require("./datetime-tokens");
7
+ /**
8
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html
9
+ */
10
+ const checkYearString = () => function checkYearString(value) {
11
+ (0, debug_1.log)('CHECK: year-string');
12
+ const tokens = token_1.TokenCollection.fromPatterns(value, [/.*/]);
13
+ (0, debug_1.log)('Year: "%s" => %O', tokens.value, tokens);
14
+ const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.extra);
15
+ if (!res.matched) {
16
+ (0, debug_1.log)('Failed: %O', res);
17
+ }
18
+ return res;
19
+ };
20
+ exports.checkYearString = checkYearString;
@@ -0,0 +1,5 @@
1
+ import type { CustomSyntaxChecker } from '../../types';
2
+ /**
3
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#yearless-dates
4
+ */
5
+ export declare const checkYearlessDateString: CustomSyntaxChecker;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkYearlessDateString = void 0;
4
+ const debug_1 = require("../../debug");
5
+ const token_1 = require("../../token");
6
+ const datetime_tokens_1 = require("./datetime-tokens");
7
+ /**
8
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#yearless-dates
9
+ */
10
+ const checkYearlessDateString = () => function checkYearlessDateString(value) {
11
+ (0, debug_1.log)('CHECK: yearless-date-string');
12
+ const tokens = token_1.TokenCollection.fromPatterns(value, [
13
+ // MM
14
+ /[^-]*/,
15
+ // -
16
+ /[^0-9]?/,
17
+ // DD
18
+ /.[0-9]*/,
19
+ ]);
20
+ (0, debug_1.log)('Yearless Date: "%s" => %O', tokens.value, tokens);
21
+ const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.month, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.date, datetime_tokens_1.datetimeTokenCheck.extra);
22
+ if (!res.matched) {
23
+ (0, debug_1.log)('Failed: %O', res);
24
+ }
25
+ return res;
26
+ };
27
+ exports.checkYearlessDateString = checkYearlessDateString;
@@ -0,0 +1,11 @@
1
+ import type { CustomSyntaxChecker } from '../types';
2
+ /**
3
+ * MIME Type
4
+ * @see https://mimesniff.spec.whatwg.org/#valid-mime-type
5
+ */
6
+ export declare const checkMIMEType: CustomSyntaxChecker<{
7
+ /**
8
+ * @see https://mimesniff.spec.whatwg.org/#valid-mime-type-with-no-parameters
9
+ */
10
+ withoutParameters?: boolean;
11
+ }>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkMIMEType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // @ts-ignore
6
+ const whatwg_mimetype_1 = (0, tslib_1.__importDefault)(require("whatwg-mimetype"));
7
+ const match_result_1 = require("../match-result");
8
+ const token_1 = require("../token");
9
+ const expects = (withoutParameters) => [
10
+ {
11
+ type: 'format',
12
+ value: withoutParameters ? 'MIME Type with no parameters' : 'MIME Type',
13
+ },
14
+ ];
15
+ /**
16
+ * MIME Type
17
+ * @see https://mimesniff.spec.whatwg.org/#valid-mime-type
18
+ */
19
+ const checkMIMEType = options => value => {
20
+ var _a;
21
+ const withoutParameters = (_a = options === null || options === void 0 ? void 0 : options.withoutParameters) !== null && _a !== void 0 ? _a : false;
22
+ if (!value) {
23
+ return (0, match_result_1.unmatched)(value, 'empty-token', { expects: expects(withoutParameters) });
24
+ }
25
+ const mimeType = whatwg_mimetype_1.default.parse(value);
26
+ if (mimeType) {
27
+ if (value.toLowerCase() === mimeType.essence) {
28
+ return (0, match_result_1.matched)();
29
+ }
30
+ if (!withoutParameters && mimeType.parameters.size) {
31
+ return (0, match_result_1.matched)();
32
+ }
33
+ const extraToken = value.slice(mimeType.essence.length);
34
+ return new token_1.Token(extraToken, mimeType.essence.length, value).unmatched({
35
+ reason: 'extra-token',
36
+ expects: expects(withoutParameters),
37
+ candicate: mimeType.essence,
38
+ });
39
+ }
40
+ return (0, match_result_1.unmatched)(value, 'syntax-error', { expects: expects(withoutParameters) });
41
+ };
42
+ exports.checkMIMEType = checkMIMEType;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const check_mime_type_1 = require("./check-mime-type");
4
+ const check = (0, check_mime_type_1.checkMIMEType)();
5
+ const checkNoParam = (0, check_mime_type_1.checkMIMEType)({ withoutParameters: true });
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
+ test('excrescence-token', () => {
11
+ expect(check('xy;')).toStrictEqual({
12
+ column: 1,
13
+ expects: [{ type: 'format', value: 'MIME Type' }],
14
+ length: 3,
15
+ line: 1,
16
+ matched: false,
17
+ offset: 0,
18
+ raw: 'xy;',
19
+ reason: 'syntax-error',
20
+ ref: null,
21
+ });
22
+ expect(check('x/y;')).toStrictEqual({
23
+ candicate: 'x/y',
24
+ column: 4,
25
+ expects: [{ type: 'format', value: 'MIME Type' }],
26
+ length: 1,
27
+ line: 1,
28
+ matched: false,
29
+ offset: 3,
30
+ raw: ';',
31
+ reason: 'extra-token',
32
+ ref: null,
33
+ });
34
+ expect(checkNoParam('x/y;')).toStrictEqual({
35
+ candicate: 'x/y',
36
+ column: 4,
37
+ expects: [{ type: 'format', value: 'MIME Type with no parameters' }],
38
+ length: 1,
39
+ line: 1,
40
+ matched: false,
41
+ offset: 3,
42
+ raw: ';',
43
+ reason: 'extra-token',
44
+ ref: null,
45
+ });
46
+ expect(checkNoParam('x/y;a=b;c=D;E="F"')).toStrictEqual({
47
+ candicate: 'x/y',
48
+ column: 4,
49
+ expects: [{ type: 'format', value: 'MIME Type with no parameters' }],
50
+ length: 14,
51
+ line: 1,
52
+ matched: false,
53
+ offset: 3,
54
+ raw: ';a=b;c=D;E="F"',
55
+ reason: 'extra-token',
56
+ ref: null,
57
+ });
58
+ });
@@ -0,0 +1,15 @@
1
+ import type { FormattedPrimitiveTypeCreator } from '../types';
2
+ /**
3
+ * @see https://url.spec.whatwg.org/#syntax-url-absolute
4
+ *
5
+ * > An absolute-URL string must be one of the following:
6
+ * > - a URL-scheme string that is an ASCII case-insensitive match
7
+ * > for a special scheme and not an ASCII case-insensitive match for "file",
8
+ * > followed by U+003A (:) and a scheme-relative-special-URL string
9
+ * > - a URL-scheme string that is not an ASCII case-insensitive match
10
+ * > for a special scheme, followed by U+003A (:) and a relative-URL string
11
+ * > - a URL-scheme string that is an ASCII case-insensitive match for "file",
12
+ * > followed by U+003A (:) and a scheme-relative-file-URL string
13
+ *
14
+ */
15
+ export declare const isAbsURL: FormattedPrimitiveTypeCreator;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAbsURL = void 0;
4
+ /**
5
+ * @see https://url.spec.whatwg.org/#syntax-url-absolute
6
+ *
7
+ * > An absolute-URL string must be one of the following:
8
+ * > - a URL-scheme string that is an ASCII case-insensitive match
9
+ * > for a special scheme and not an ASCII case-insensitive match for "file",
10
+ * > followed by U+003A (:) and a scheme-relative-special-URL string
11
+ * > - a URL-scheme string that is not an ASCII case-insensitive match
12
+ * > for a special scheme, followed by U+003A (:) and a relative-URL string
13
+ * > - a URL-scheme string that is an ASCII case-insensitive match for "file",
14
+ * > followed by U+003A (:) and a scheme-relative-file-URL string
15
+ *
16
+ */
17
+ const isAbsURL = () => {
18
+ return value => {
19
+ try {
20
+ new URL(value);
21
+ }
22
+ catch (e) {
23
+ if (e && typeof e === 'object' && 'code' in e) {
24
+ // @ts-ignore
25
+ if (e.code === 'ERR_INVALID_URL') {
26
+ return false;
27
+ }
28
+ }
29
+ throw e;
30
+ }
31
+ return true;
32
+ };
33
+ };
34
+ exports.isAbsURL = isAbsURL;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_abs_url_1 = require("./is-abs-url");
4
+ const is = (0, is_abs_url_1.isAbsURL)();
5
+ test('valid', () => {
6
+ expect(is('https://markuplint.dev')).toBe(true);
7
+ expect(is('markuplint.dev')).toBe(false);
8
+ });
@@ -0,0 +1,11 @@
1
+ import type { FormattedPrimitiveTypeCreator } from '../types';
2
+ /**
3
+ *
4
+ * @see https://html.spec.whatwg.org/multipage/browsers.html#valid-browsing-context-name
5
+ *
6
+ * > A valid browsing context name is any string with at least one character
7
+ * > that does not start with a U+005F LOW LINE character.
8
+ * > (Names starting with an underscore are reserved for special keywords.)
9
+ *
10
+ */
11
+ export declare const isBrowserContextName: FormattedPrimitiveTypeCreator;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBrowserContextName = void 0;
4
+ /**
5
+ *
6
+ * @see https://html.spec.whatwg.org/multipage/browsers.html#valid-browsing-context-name
7
+ *
8
+ * > A valid browsing context name is any string with at least one character
9
+ * > that does not start with a U+005F LOW LINE character.
10
+ * > (Names starting with an underscore are reserved for special keywords.)
11
+ *
12
+ */
13
+ const isBrowserContextName = () => {
14
+ return value => {
15
+ return !!value && value[0] !== '_';
16
+ };
17
+ };
18
+ exports.isBrowserContextName = isBrowserContextName;
@@ -0,0 +1,22 @@
1
+ import type { FormattedPrimitiveTypeCreator } from '../types';
2
+ /**
3
+ * valid name of custom element
4
+ *
5
+ * @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
6
+ *
7
+ * > - name must match the [PotentialCustomElementName](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname) production
8
+ * > - name must not be any of the following:
9
+ * > - `<annotation-xml>`
10
+ * > - `<color-profile>`
11
+ * > - `<font-face>`
12
+ * > - `<font-face-src>`
13
+ * > - `<font-face-uri>`
14
+ * > - `<font-face-format>`
15
+ * > - `<font-face-name>`
16
+ * > - `<missing-glyph>`
17
+ *
18
+ * ASCII-case-insensitively.
19
+ * 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.
20
+ *
21
+ */
22
+ export declare const isCustomElementName: FormattedPrimitiveTypeCreator;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCustomElementName = void 0;
4
+ /**
5
+ * PotentialCustomElementName
6
+ *
7
+ * @see https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname
8
+ *
9
+ * > PotentialCustomElementName ::=
10
+ * > [a-z] (PCENChar)* '-' (PCENChar)*
11
+ * > PCENChar ::=
12
+ * > "-" | "." | [0-9] | "_" | [a-z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] |
13
+ * > [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
14
+ * > This uses the EBNF notation from the XML specification. [XML]
15
+ *
16
+ * ASCII-case-insensitively.
17
+ * 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.
18
+ */
19
+ const rePCENChar = [
20
+ '\\-',
21
+ '\\.',
22
+ '[0-9]',
23
+ '_',
24
+ '[a-z]',
25
+ '\u00B7',
26
+ '[\u00C0-\u00D6]',
27
+ '[\u00D8-\u00F6]',
28
+ '[\u00F8-\u037D]',
29
+ '[\u037F-\u1FFF]',
30
+ '[\u200C-\u200D]',
31
+ '[\u203F-\u2040]',
32
+ '[\u2070-\u218F]',
33
+ '[\u2C00-\u2FEF]',
34
+ '[\u3001-\uD7FF]',
35
+ '[\uF900-\uFDCF]',
36
+ '[\uFDF0-\uFFFD]',
37
+ '[\uD800-\uDBFF][\uDC00-\uDFFF]',
38
+ ].join('|');
39
+ const rePCEN = new RegExp(`^[a-z](?:${rePCENChar})*\\-(?:${rePCENChar})*$`, 'i');
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
+ const isCustomElementName = () => {
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
+ };
77
+ exports.isCustomElementName = isCustomElementName;
@@ -0,0 +1,12 @@
1
+ import type { FormattedPrimitiveTypeCreator } from '../types';
2
+ /**
3
+ *
4
+ * @see https://html.spec.whatwg.org/multipage/microdata.html#defined-property-name
5
+ *
6
+ * > The rules above disallow U+003A COLON characters (:) in non-URL values
7
+ * > because otherwise they could not be distinguished from URLs.
8
+ * > Values with U+002E FULL STOP characters (.) are reserved for future extensions.
9
+ * > ASCII whitespace are disallowed because otherwise the values would be parsed as multiple tokens.
10
+ *
11
+ */
12
+ export declare const isItempropName: FormattedPrimitiveTypeCreator;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isItempropName = void 0;
4
+ /**
5
+ *
6
+ * @see https://html.spec.whatwg.org/multipage/microdata.html#defined-property-name
7
+ *
8
+ * > The rules above disallow U+003A COLON characters (:) in non-URL values
9
+ * > because otherwise they could not be distinguished from URLs.
10
+ * > Values with U+002E FULL STOP characters (.) are reserved for future extensions.
11
+ * > ASCII whitespace are disallowed because otherwise the values would be parsed as multiple tokens.
12
+ *
13
+ */
14
+ const isItempropName = () => {
15
+ return value => {
16
+ return value.indexOf(':') === -1 && value.indexOf('.') === -1 && value.indexOf(' ') === -1;
17
+ };
18
+ };
19
+ exports.isItempropName = isItempropName;
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@markuplint/types",
3
+ "version": "1.0.0-dev.20211213.0",
4
+ "description": "Types of attributes and properties and more",
5
+ "repository": "git@github.com:markuplint/markuplint.git",
6
+ "author": "Yusuke Hirao <yusukehirao@me.com>",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "main": "lib/index.js",
10
+ "types": "lib/index.d.ts",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "clean": "tsc --build --clean",
17
+ "schema": "ts-node './gen/types.ts'; json2ts './types.schema.json' > './src/types.schema.ts'; prettier './src/types.schema.ts' './types.schema.json' --write; eslint './src/types.schema.ts' --fix; tsc;"
18
+ },
19
+ "dependencies": {
20
+ "bcp-47": "1",
21
+ "css-tree": "^1.1.3",
22
+ "debug": "^4.3.2",
23
+ "leven": "3",
24
+ "whatwg-mimetype": "2"
25
+ },
26
+ "devDependencies": {
27
+ "@types/bcp-47": "1",
28
+ "@types/css-tree": "^1.0.7",
29
+ "@types/debug": "^4.1.7",
30
+ "@types/whatwg-mimetype": "^2.1.1"
31
+ },
32
+ "gitHead": "8f4682ca3e0937082af8c39b999443afa4a1aef3"
33
+ }
@@ -0,0 +1,35 @@
1
+ import type { CustomSyntaxCheck, UnmatchedResult } from './types';
2
+
3
+ import { log } from './debug';
4
+ import { matched } from './match-result';
5
+
6
+ export function checkMultiTypes(value: string, checks: CustomSyntaxCheck[]) {
7
+ let unmatched: UnmatchedResult | undefined;
8
+
9
+ for (const check of checks) {
10
+ const res = check(value);
11
+ if (res.matched) {
12
+ return res;
13
+ }
14
+
15
+ // @ts-ignore
16
+ res._fn = check.name;
17
+
18
+ // @ts-ignore
19
+ log('%s(%d) vs %s(%d)', unmatched?._fn, unmatched?.passCount, res._fn, res.passCount);
20
+ const passedA = unmatched?.passCount || 0;
21
+ const passedB = res.passCount || 0;
22
+ const offsetA = unmatched?.offset || 0;
23
+ const offsetB = res.offset;
24
+
25
+ if (passedA < passedB || (passedA === passedB && offsetA <= offsetB)) {
26
+ unmatched = res;
27
+ }
28
+ }
29
+
30
+ const result = unmatched || matched();
31
+
32
+ log('%d checks result: %O', checks.length, result);
33
+
34
+ return result;
35
+ }
@@ -0,0 +1,62 @@
1
+ import { check } from './check';
2
+
3
+ test('Any', () => {
4
+ expect(check('', 'Any').matched).toBe(true);
5
+ expect(check(' ', 'Any').matched).toBe(true);
6
+ expect(check('a', 'Any').matched).toBe(true);
7
+ });
8
+
9
+ test('NoEmptyAny', () => {
10
+ expect(check('', 'NoEmptyAny').matched).toBe(false);
11
+ expect(check(' ', 'NoEmptyAny').matched).toBe(true);
12
+ expect(check('a', 'NoEmptyAny').matched).toBe(true);
13
+ });
14
+
15
+ test('OneLineAny', () => {
16
+ expect(check('', 'OneLineAny').matched).toBe(true);
17
+ expect(check(' ', 'OneLineAny').matched).toBe(true);
18
+ expect(check('a', 'OneLineAny').matched).toBe(true);
19
+ expect(check('a ', 'OneLineAny').matched).toBe(true);
20
+ expect(check('a b', 'OneLineAny').matched).toBe(true);
21
+ expect(check('a\n', 'OneLineAny').matched).toBe(false);
22
+ expect(check('a\nb', 'OneLineAny').matched).toBe(false);
23
+ expect(check('a\r\nb', 'OneLineAny').matched).toBe(false);
24
+ expect(check('a\rb', 'OneLineAny').matched).toBe(false);
25
+ });
26
+
27
+ test('Pattern', () => {
28
+ expect(check('.*', 'Pattern').matched).toBe(true);
29
+ expect(check('[a-z]+', 'Pattern').matched).toBe(true);
30
+ expect(check(']//[()?!+*', 'Pattern').matched).toBe(false);
31
+ });
32
+
33
+ test('BCP47', () => {
34
+ expect(check('en', 'BCP47').matched).toBe(true);
35
+ expect(check('en-US', 'BCP47').matched).toBe(true);
36
+ expect(check('ja', 'BCP47').matched).toBe(true);
37
+ expect(check(' ja ', 'BCP47').matched).toBe(false);
38
+ expect(check('', 'BCP47').matched).toBe(false);
39
+ expect(check('zh/cn', 'BCP47').matched).toBe(false);
40
+ });
41
+
42
+ test('Srcset', () => {
43
+ expect(check('a/bb/ccc/dddd', 'Srcset').matched).toBe(true);
44
+ expect(check('a/bb/ccc/dddd 200w', 'Srcset').matched).toBe(true);
45
+ expect(check('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5x', 'Srcset').matched).toBe(true);
46
+ expect(check('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5a', 'Srcset').matched).toBe(false);
47
+ });
48
+
49
+ test('Srcset', () => {
50
+ expect(check('any', 'IconSize').matched).toBe(true);
51
+ expect(check('Any', 'IconSize').matched).toBe(true);
52
+ expect(check('10x10', 'IconSize').matched).toBe(true);
53
+ expect(check('1x1', 'IconSize').matched).toBe(true);
54
+ expect(check('1x0', 'IconSize').matched).toBe(false);
55
+ expect(check('0x1', 'IconSize').matched).toBe(false);
56
+ expect(check('0x0', 'IconSize').matched).toBe(false);
57
+ expect(check('', 'IconSize').matched).toBe(false);
58
+ expect(check(' ', 'IconSize').matched).toBe(false);
59
+ expect(check('1', 'IconSize').matched).toBe(false);
60
+ expect(check('1x', 'IconSize').matched).toBe(false);
61
+ expect(check('x1', 'IconSize').matched).toBe(false);
62
+ });
package/src/check.ts ADDED
@@ -0,0 +1,48 @@
1
+ import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types';
2
+
3
+ import { log } from './debug';
4
+ import { checkEnum } from './enum';
5
+ import { checkKeywordType } from './keyword-type';
6
+ import { checkList } from './list';
7
+ import { checkNumber } from './number';
8
+
9
+ export function check(value: string, type: Type, ref?: string, cache = true): Result {
10
+ if (isKeyword(type)) {
11
+ log('Check keyword: %s', type);
12
+ return checkKeywordType(value, type, cache);
13
+ }
14
+ if (isList(type)) {
15
+ log('Check list: %O', type);
16
+ return checkList(value, type, ref, cache);
17
+ }
18
+ if (isEnum(type)) {
19
+ log('Check enum: %O', type);
20
+ return checkEnum(value, type, ref);
21
+ }
22
+ log('Check number: %O', type);
23
+ return checkNumber(value, type, ref);
24
+ }
25
+
26
+ export function isKeyword(type: Type): type is KeywordDefinedType {
27
+ return typeof type === 'string';
28
+ }
29
+
30
+ export function isList(type: Type): type is List {
31
+ return typeof type !== 'string' && 'token' in type;
32
+ }
33
+
34
+ export function isEnum(type: Type): type is Enum {
35
+ return typeof type !== 'string' && 'enum' in type;
36
+ }
37
+
38
+ export function isNumber(type: Type): type is Number {
39
+ return typeof type !== 'string' && 'enum' in type;
40
+ }
41
+
42
+ export function isCSSSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomCssSyntax {
43
+ return typeof type === 'string' || 'syntax' in type;
44
+ }
45
+
46
+ export function isCustomSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomSyntax {
47
+ return !isCSSSyntax(type);
48
+ }