@markuplint/types 3.8.0 → 4.0.0-alpha.1

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 (93) hide show
  1. package/lib/check-multi-types.d.ts +2 -2
  2. package/lib/check-multi-types.js +9 -14
  3. package/lib/check.d.ts +1 -1
  4. package/lib/check.js +20 -30
  5. package/lib/css-syntax.d.ts +1 -1
  6. package/lib/css-syntax.js +18 -23
  7. package/lib/debug.js +2 -6
  8. package/lib/defs.d.ts +1 -1
  9. package/lib/defs.js +82 -85
  10. package/lib/enum.d.ts +2 -2
  11. package/lib/enum.js +6 -11
  12. package/lib/get-candidate.js +3 -8
  13. package/lib/index.d.ts +3 -3
  14. package/lib/index.js +3 -6
  15. package/lib/keyword-type.d.ts +2 -2
  16. package/lib/keyword-type.js +17 -22
  17. package/lib/list.d.ts +2 -2
  18. package/lib/list.js +9 -14
  19. package/lib/match-result.d.ts +1 -1
  20. package/lib/match-result.js +6 -13
  21. package/lib/number.d.ts +2 -2
  22. package/lib/number.js +11 -15
  23. package/lib/primitive/index.d.ts +7 -7
  24. package/lib/primitive/index.js +7 -17
  25. package/lib/primitive/is-float.js +1 -5
  26. package/lib/primitive/is-int.js +1 -5
  27. package/lib/primitive/is-non-zero-uint.js +1 -5
  28. package/lib/primitive/is-quantity.js +9 -13
  29. package/lib/primitive/is-uint.js +1 -5
  30. package/lib/primitive/range.js +1 -5
  31. package/lib/primitive/split-unit.js +3 -7
  32. package/lib/rfc/is-bcp-47.d.ts +1 -1
  33. package/lib/rfc/is-bcp-47.js +3 -7
  34. package/lib/token/index.d.ts +2 -2
  35. package/lib/token/index.js +2 -7
  36. package/lib/token/token-collection.d.ts +4 -5
  37. package/lib/token/token-collection.js +35 -43
  38. package/lib/token/token.d.ts +2 -2
  39. package/lib/token/token.js +6 -13
  40. package/lib/token/types.js +1 -2
  41. package/lib/types.d.ts +2 -2
  42. package/lib/types.js +1 -2
  43. package/lib/types.schema.js +1 -2
  44. package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
  45. package/lib/w3c/check-serialized-permissions-policy.js +16 -20
  46. package/lib/whatwg/check-autocomplete.d.ts +1 -1
  47. package/lib/whatwg/check-autocomplete.js +24 -28
  48. package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
  49. package/lib/whatwg/check-datetime/date-string.js +9 -13
  50. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -1
  51. package/lib/whatwg/check-datetime/datetime-tokens.js +40 -46
  52. package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
  53. package/lib/whatwg/check-datetime/duration-string.js +38 -44
  54. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
  55. package/lib/whatwg/check-datetime/global-date-and-time-string.js +17 -21
  56. package/lib/whatwg/check-datetime/index.d.ts +1 -1
  57. package/lib/whatwg/check-datetime/index.js +25 -29
  58. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
  59. package/lib/whatwg/check-datetime/local-date-and-time-string.js +20 -25
  60. package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
  61. package/lib/whatwg/check-datetime/month-string.js +9 -13
  62. package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
  63. package/lib/whatwg/check-datetime/time-string.js +9 -13
  64. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
  65. package/lib/whatwg/check-datetime/time-zone-offset-string.js +16 -22
  66. package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
  67. package/lib/whatwg/check-datetime/week-string.js +9 -13
  68. package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
  69. package/lib/whatwg/check-datetime/year-string.js +9 -13
  70. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
  71. package/lib/whatwg/check-datetime/yearless-date-string.js +9 -13
  72. package/lib/whatwg/check-mime-type.d.ts +1 -1
  73. package/lib/whatwg/check-mime-type.js +11 -17
  74. package/lib/whatwg/is-abs-url.d.ts +1 -1
  75. package/lib/whatwg/is-abs-url.js +1 -5
  76. package/lib/whatwg/is-browser-context-name.d.ts +1 -1
  77. package/lib/whatwg/is-browser-context-name.js +1 -5
  78. package/lib/whatwg/is-custom-element-name.d.ts +1 -1
  79. package/lib/whatwg/is-custom-element-name.js +1 -5
  80. package/lib/whatwg/is-itemprop-name.d.ts +1 -1
  81. package/lib/whatwg/is-itemprop-name.js +1 -5
  82. package/package.json +13 -8
  83. package/test/check.spec.js +0 -89
  84. package/test/css-syntax.spec.js +0 -170
  85. package/test/list.spec.js +0 -133
  86. package/test/primitive/index.spec.js +0 -65
  87. package/test/rfc/is-bcp-47.spec.js +0 -23
  88. package/test/token/token-collection.spec.js +0 -146
  89. package/test/w3c/check-serialized-permissions-policy.spec.js +0 -36
  90. package/test/whatwg/check-autocomplete.spec.js +0 -387
  91. package/test/whatwg/check-datetime/index.spec.js +0 -336
  92. package/test/whatwg/check-mime-type.spec.js +0 -59
  93. package/test/whatwg/is-abs-url.spec.js +0 -8
package/lib/list.js CHANGED
@@ -1,30 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkList = void 0;
4
- const check_1 = require("./check");
5
- const match_result_1 = require("./match-result");
6
- const token_1 = require("./token");
7
- function checkList(value, type, ref, cache = true) {
8
- var _a;
9
- const tokens = new token_1.TokenCollection(value, type);
1
+ import { check } from './check.js';
2
+ import { matched } from './match-result.js';
3
+ import { Token, TokenCollection } from './token/index.js';
4
+ export function checkList(value, type, ref, cache = true) {
5
+ const tokens = new TokenCollection(value, type);
10
6
  const matches = tokens.check({ ref });
11
7
  if (!matches.matched) {
12
8
  return matches;
13
9
  }
14
10
  const identTokens = tokens.getIdentTokens();
15
11
  for (const token of identTokens) {
16
- const res = (0, check_1.check)(token.value, type.token, ref, cache);
12
+ const res = check(token.value, type.token, ref, cache);
17
13
  if (!res.matched) {
18
- const { offset, line, column } = token_1.Token.shiftLocation(token, res.offset);
14
+ const { offset, line, column } = Token.shiftLocation(token, res.offset);
19
15
  return {
20
16
  ...res,
21
- partName: (_a = res.partName) !== null && _a !== void 0 ? _a : 'the content of the list',
17
+ partName: res.partName ?? 'the content of the list',
22
18
  offset,
23
19
  line,
24
20
  column,
25
21
  };
26
22
  }
27
23
  }
28
- return (0, match_result_1.matched)();
24
+ return matched();
29
25
  }
30
- exports.checkList = checkList;
@@ -1,4 +1,4 @@
1
- import type { FormattedPrimitiveTypeCheck, MatchedResult, UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from './types';
1
+ import type { FormattedPrimitiveTypeCheck, MatchedResult, UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from './types.js';
2
2
  export declare function matches(checker: FormattedPrimitiveTypeCheck, options?: UnmatchedResultOptions & {
3
3
  readonly ref?: string;
4
4
  readonly reason?: UnmatchedResultReason;
@@ -1,34 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unmatched = exports.matched = exports.matches = void 0;
4
- function matches(checker, options) {
1
+ export function matches(checker, options) {
5
2
  return (value) => {
6
3
  const valid = checker(value);
7
4
  if (!valid && !value) {
8
5
  return unmatched(value, 'empty-token', options);
9
6
  }
10
- return valid ? matched() : unmatched(value, options === null || options === void 0 ? void 0 : options.reason, options);
7
+ return valid ? matched() : unmatched(value, options?.reason, options);
11
8
  };
12
9
  }
13
- exports.matches = matches;
14
- function matched() {
10
+ export function matched() {
15
11
  return {
16
12
  matched: true,
17
13
  };
18
14
  }
19
- exports.matched = matched;
20
- function unmatched(value, reason, options) {
21
- var _a;
15
+ export function unmatched(value, reason, options) {
22
16
  return {
23
17
  ...options,
24
18
  matched: false,
25
- ref: (_a = options === null || options === void 0 ? void 0 : options.ref) !== null && _a !== void 0 ? _a : null,
19
+ ref: options?.ref ?? null,
26
20
  raw: value,
27
21
  offset: 0,
28
22
  length: value.length,
29
23
  line: 1,
30
24
  column: 1,
31
- reason: reason !== null && reason !== void 0 ? reason : 'syntax-error',
25
+ reason: reason ?? 'syntax-error',
32
26
  };
33
27
  }
34
- exports.unmatched = unmatched;
package/lib/number.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Result } from './types';
2
- import type { Number } from './types.schema';
1
+ import type { Result } from './types.js';
2
+ import type { Number } from './types.schema.js';
3
3
  export declare function checkNumber(value: string, type: Readonly<Number>, ref?: string): Result;
package/lib/number.js CHANGED
@@ -1,41 +1,37 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkNumber = void 0;
4
- const match_result_1 = require("./match-result");
5
- const primitive_1 = require("./primitive");
6
- function checkNumber(value, type, ref) {
1
+ import { matched, unmatched } from './match-result.js';
2
+ import { isFloat, isInt } from './primitive/index.js';
3
+ export function checkNumber(value, type, ref) {
7
4
  if (!value) {
8
- return (0, match_result_1.unmatched)(value, 'empty-token');
5
+ return unmatched(value, 'empty-token');
9
6
  }
10
- const syntaxMatched = type.type === 'float' ? (0, primitive_1.isFloat)(value) : (0, primitive_1.isInt)(value);
7
+ const syntaxMatched = type.type === 'float' ? isFloat(value) : isInt(value);
11
8
  if (syntaxMatched) {
12
9
  const n = parseFloat(value);
13
10
  if (!isFinite(n)) {
14
- return (0, match_result_1.unmatched)(value, 'unexpected-token');
11
+ return unmatched(value, 'unexpected-token');
15
12
  }
16
13
  const clampable = type.clampable;
17
14
  const isInt = type.type === 'integer';
18
15
  if (type.gt != null && n <= type.gt) {
19
- return (0, match_result_1.unmatched)(value, 'out-of-range', {
16
+ return unmatched(value, 'out-of-range', {
20
17
  candidate: clampable && isInt ? `${type.gt + 1}` : undefined,
21
18
  });
22
19
  }
23
20
  if (type.gte != null && n < type.gte) {
24
- return (0, match_result_1.unmatched)(value, 'out-of-range', {
21
+ return unmatched(value, 'out-of-range', {
25
22
  candidate: clampable ? `${type.gte}` : undefined,
26
23
  });
27
24
  }
28
25
  if (type.lt != null && type.lt <= n) {
29
- return (0, match_result_1.unmatched)(value, 'out-of-range', {
26
+ return unmatched(value, 'out-of-range', {
30
27
  candidate: clampable && isInt ? `${type.lt - 1}` : undefined,
31
28
  });
32
29
  }
33
30
  if (type.lte != null && type.lte < n) {
34
- return (0, match_result_1.unmatched)(value, 'out-of-range', {
31
+ return unmatched(value, 'out-of-range', {
35
32
  candidate: clampable ? `${type.lte}` : undefined,
36
33
  });
37
34
  }
38
35
  }
39
- return syntaxMatched ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token');
36
+ return syntaxMatched ? matched() : unmatched(value, 'unexpected-token');
40
37
  }
41
- exports.checkNumber = checkNumber;
@@ -1,7 +1,7 @@
1
- export { isInt } from './is-int';
2
- export { isUint } from './is-uint';
3
- export { isFloat } from './is-float';
4
- export { isNonZeroUint } from './is-non-zero-uint';
5
- export { isQuantity } from './is-quantity';
6
- export { splitUnit } from './split-unit';
7
- export { range } from './range';
1
+ export { isInt } from './is-int.js';
2
+ export { isUint } from './is-uint.js';
3
+ export { isFloat } from './is-float.js';
4
+ export { isNonZeroUint } from './is-non-zero-uint.js';
5
+ export { isQuantity } from './is-quantity.js';
6
+ export { splitUnit } from './split-unit.js';
7
+ export { range } from './range.js';
@@ -1,17 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.range = exports.splitUnit = exports.isQuantity = exports.isNonZeroUint = exports.isFloat = exports.isUint = exports.isInt = void 0;
4
- var is_int_1 = require("./is-int");
5
- Object.defineProperty(exports, "isInt", { enumerable: true, get: function () { return is_int_1.isInt; } });
6
- var is_uint_1 = require("./is-uint");
7
- Object.defineProperty(exports, "isUint", { enumerable: true, get: function () { return is_uint_1.isUint; } });
8
- var is_float_1 = require("./is-float");
9
- Object.defineProperty(exports, "isFloat", { enumerable: true, get: function () { return is_float_1.isFloat; } });
10
- var is_non_zero_uint_1 = require("./is-non-zero-uint");
11
- Object.defineProperty(exports, "isNonZeroUint", { enumerable: true, get: function () { return is_non_zero_uint_1.isNonZeroUint; } });
12
- var is_quantity_1 = require("./is-quantity");
13
- Object.defineProperty(exports, "isQuantity", { enumerable: true, get: function () { return is_quantity_1.isQuantity; } });
14
- var split_unit_1 = require("./split-unit");
15
- Object.defineProperty(exports, "splitUnit", { enumerable: true, get: function () { return split_unit_1.splitUnit; } });
16
- var range_1 = require("./range");
17
- Object.defineProperty(exports, "range", { enumerable: true, get: function () { return range_1.range; } });
1
+ export { isInt } from './is-int.js';
2
+ export { isUint } from './is-uint.js';
3
+ export { isFloat } from './is-float.js';
4
+ export { isNonZeroUint } from './is-non-zero-uint.js';
5
+ export { isQuantity } from './is-quantity.js';
6
+ export { splitUnit } from './split-unit.js';
7
+ export { range } from './range.js';
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFloat = void 0;
4
1
  /**
5
2
  * @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#floating-point-numbers
6
3
  *
7
4
  * @param value
8
5
  */
9
- function isFloat(value) {
6
+ export function isFloat(value) {
10
7
  return value === value.trim() && Number.isFinite(parseFloat(value));
11
8
  }
12
- exports.isFloat = isFloat;
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isInt = void 0;
4
1
  /**
5
2
  * @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#signed-integers
6
3
  *
7
4
  * @param value
8
5
  */
9
- function isInt(value) {
6
+ export function isInt(value) {
10
7
  return /^-?[0-9]+$/.test(value);
11
8
  }
12
- exports.isInt = isInt;
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNonZeroUint = void 0;
4
1
  /**
5
2
  * Non-negative integer greater than zero
6
3
  *
7
4
  * @param value
8
5
  */
9
- function isNonZeroUint(value) {
6
+ export function isNonZeroUint(value) {
10
7
  return /^[0-9]+$/.test(value) && !/^0+$/.test(value);
11
8
  }
12
- exports.isNonZeroUint = isNonZeroUint;
@@ -1,36 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isQuantity = void 0;
4
- const is_float_1 = require("./is-float");
5
- const is_int_1 = require("./is-int");
6
- const is_uint_1 = require("./is-uint");
7
- const split_unit_1 = require("./split-unit");
1
+ import { isFloat } from './is-float.js';
2
+ import { isInt } from './is-int.js';
3
+ import { isUint } from './is-uint.js';
4
+ import { splitUnit } from './split-unit.js';
8
5
  /**
9
6
  *
10
7
  * @param value
11
8
  * @param units
12
9
  * @param numberType
13
10
  */
14
- function isQuantity(value, units, numberType = 'float') {
15
- const { num, unit } = (0, split_unit_1.splitUnit)(value);
11
+ export function isQuantity(value, units, numberType = 'float') {
12
+ const { num, unit } = splitUnit(value);
16
13
  if (!units.includes(unit.toLowerCase())) {
17
14
  return false;
18
15
  }
19
16
  switch (numberType) {
20
17
  case 'int': {
21
- if (!(0, is_int_1.isInt)(num)) {
18
+ if (!isInt(num)) {
22
19
  return false;
23
20
  }
24
21
  break;
25
22
  }
26
23
  case 'uint': {
27
- if (!(0, is_uint_1.isUint)(num)) {
24
+ if (!isUint(num)) {
28
25
  return false;
29
26
  }
30
27
  break;
31
28
  }
32
29
  case 'float': {
33
- if (!(0, is_float_1.isFloat)(num)) {
30
+ if (!isFloat(num)) {
34
31
  return false;
35
32
  }
36
33
  break;
@@ -38,4 +35,3 @@ function isQuantity(value, units, numberType = 'float') {
38
35
  }
39
36
  return true;
40
37
  }
41
- exports.isQuantity = isQuantity;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUint = void 0;
4
1
  /**
5
2
  * @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#non-negative-integers
6
3
  *
7
4
  * @param value
8
5
  */
9
- function isUint(value, options) {
6
+ export function isUint(value, options) {
10
7
  const matched = /^[0-9]+$/.test(value);
11
8
  if (matched && options) {
12
9
  const n = parseInt(value, 10);
@@ -16,4 +13,3 @@ function isUint(value, options) {
16
13
  }
17
14
  return matched;
18
15
  }
19
- exports.isUint = isUint;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.range = void 0;
4
1
  /**
5
2
  * It is in the range between `from` and `to`.
6
3
  *
@@ -8,11 +5,10 @@ exports.range = void 0;
8
5
  * @param from
9
6
  * @param to
10
7
  */
11
- function range(value, from, to) {
8
+ export function range(value, from, to) {
12
9
  const num = parseFloat(value);
13
10
  if (isNaN(num)) {
14
11
  return false;
15
12
  }
16
13
  return from <= num && num <= to;
17
14
  }
18
- exports.range = range;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.splitUnit = void 0;
4
1
  /**
5
2
  *
6
3
  * @param value
7
4
  * @returns
8
5
  */
9
- function splitUnit(value) {
6
+ export function splitUnit(value) {
10
7
  value = value.trim().toLowerCase();
11
8
  const matched = value.match(/(^-?\.[0-9]+|^-?[0-9]+(?:\.[0-9]+(?:e[+-][0-9]+)?)?)([a-z]+$)/i);
12
9
  if (!matched) {
@@ -17,8 +14,7 @@ function splitUnit(value) {
17
14
  }
18
15
  const [, num, unit] = matched;
19
16
  return {
20
- num: num !== null && num !== void 0 ? num : value,
21
- unit: unit !== null && unit !== void 0 ? unit : '',
17
+ num: num ?? value,
18
+ unit: unit ?? '',
22
19
  };
23
20
  }
24
- exports.splitUnit = splitUnit;
@@ -1,4 +1,4 @@
1
- import type { FormattedPrimitiveTypeCreator } from '../types';
1
+ import type { FormattedPrimitiveTypeCreator } from '../types.js';
2
2
  /**
3
3
  * @see https://tools.ietf.org/rfc/bcp/bcp47.html
4
4
  */
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBCP47 = void 0;
4
- const bcp_47_1 = require("bcp-47");
1
+ import { parse } from 'bcp-47';
5
2
  /**
6
3
  * @see https://tools.ietf.org/rfc/bcp/bcp47.html
7
4
  */
8
- const isBCP47 = () => {
5
+ export const isBCP47 = () => {
9
6
  return value => {
10
- const { language } = (0, bcp_47_1.parse)(value);
7
+ const { language } = parse(value);
11
8
  return !!language;
12
9
  };
13
10
  };
14
- exports.isBCP47 = isBCP47;
@@ -1,2 +1,2 @@
1
- export { Token } from './token';
2
- export { TokenCollection } from './token-collection';
1
+ export { Token } from './token.js';
2
+ export { TokenCollection } from './token-collection.js';
@@ -1,7 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenCollection = exports.Token = void 0;
4
- var token_1 = require("./token");
5
- Object.defineProperty(exports, "Token", { enumerable: true, get: function () { return token_1.Token; } });
6
- var token_collection_1 = require("./token-collection");
7
- Object.defineProperty(exports, "TokenCollection", { enumerable: true, get: function () { return token_collection_1.TokenCollection; } });
1
+ export { Token } from './token.js';
2
+ export { TokenCollection } from './token-collection.js';
@@ -1,8 +1,7 @@
1
- import type { TokenValue } from './types';
2
- import type { UnmatchedResult } from '..';
3
- import type { Expect, Result, List } from '../types';
1
+ import type { TokenValue } from './types.js';
2
+ import type { Expect, Result, List, UnmatchedResult } from '../types.js';
4
3
  import type { ReadonlyDeep } from 'type-fest';
5
- import { Token } from './token';
4
+ import { Token } from './token.js';
6
5
  type TokenCollectionOptions = Partial<Omit<List, 'token'> & {
7
6
  specificSeparator: string | string[];
8
7
  }>;
@@ -26,7 +25,7 @@ export declare class TokenCollection extends Array<Token> {
26
25
  expects?: Expect[];
27
26
  ref?: string;
28
27
  cache?: boolean;
29
- }): import("..").MatchedResult | UnmatchedResult;
28
+ }): import("../types.js").MatchedResult | UnmatchedResult;
30
29
  chunk(split: number): TokenCollection[];
31
30
  compareTokens(callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void): Readonly<Token> | null | undefined;
32
31
  divide(position: number): readonly [TokenCollection, TokenCollection];