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

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 (173) hide show
  1. package/README.md +63 -61
  2. package/lib/check-multi-types.d.ts +2 -2
  3. package/lib/check-multi-types.js +9 -13
  4. package/lib/check.d.ts +7 -6
  5. package/lib/check.js +20 -30
  6. package/lib/css-syntax.d.ts +1 -1
  7. package/lib/css-syntax.js +60 -63
  8. package/lib/debug.js +2 -6
  9. package/lib/defs.d.ts +1 -1
  10. package/lib/defs.js +163 -91
  11. package/lib/enum.d.ts +4 -3
  12. package/lib/enum.js +7 -12
  13. package/lib/get-candidate.d.ts +1 -1
  14. package/lib/get-candidate.js +3 -8
  15. package/lib/index.d.ts +3 -3
  16. package/lib/index.js +3 -6
  17. package/lib/keyword-type.d.ts +2 -2
  18. package/lib/keyword-type.js +17 -21
  19. package/lib/list.d.ts +4 -3
  20. package/lib/list.js +9 -13
  21. package/lib/match-result.d.ts +4 -4
  22. package/lib/match-result.js +6 -12
  23. package/lib/number.d.ts +3 -3
  24. package/lib/number.js +11 -15
  25. package/lib/primitive/index.d.ts +7 -7
  26. package/lib/primitive/index.js +7 -17
  27. package/lib/primitive/is-float.js +1 -5
  28. package/lib/primitive/is-int.js +1 -5
  29. package/lib/primitive/is-non-zero-uint.js +1 -5
  30. package/lib/primitive/is-quantity.d.ts +1 -1
  31. package/lib/primitive/is-quantity.js +9 -13
  32. package/lib/primitive/is-uint.d.ts +1 -1
  33. package/lib/primitive/is-uint.js +1 -5
  34. package/lib/primitive/range.js +1 -5
  35. package/lib/primitive/split-unit.js +3 -7
  36. package/lib/rfc/is-bcp-47.d.ts +1 -1
  37. package/lib/rfc/is-bcp-47.js +3 -7
  38. package/lib/token/index.d.ts +2 -2
  39. package/lib/token/index.js +2 -7
  40. package/lib/token/token-collection.d.ts +13 -13
  41. package/lib/token/token-collection.js +55 -50
  42. package/lib/token/token.d.ts +11 -10
  43. package/lib/token/token.js +16 -24
  44. package/lib/token/types.d.ts +3 -0
  45. package/lib/types.d.ts +47 -46
  46. package/lib/types.js +1 -2
  47. package/lib/types.schema.d.ts +2 -2
  48. package/lib/types.schema.js +1 -3
  49. package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
  50. package/lib/w3c/check-serialized-permissions-policy.js +16 -20
  51. package/lib/whatwg/check-autocomplete.d.ts +1 -1
  52. package/lib/whatwg/check-autocomplete.js +28 -32
  53. package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
  54. package/lib/whatwg/check-datetime/date-string.js +9 -13
  55. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -1
  56. package/lib/whatwg/check-datetime/datetime-tokens.js +43 -46
  57. package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
  58. package/lib/whatwg/check-datetime/duration-string.js +48 -44
  59. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
  60. package/lib/whatwg/check-datetime/global-date-and-time-string.js +17 -21
  61. package/lib/whatwg/check-datetime/index.d.ts +1 -1
  62. package/lib/whatwg/check-datetime/index.js +25 -29
  63. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
  64. package/lib/whatwg/check-datetime/local-date-and-time-string.js +25 -26
  65. package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
  66. package/lib/whatwg/check-datetime/month-string.js +9 -13
  67. package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
  68. package/lib/whatwg/check-datetime/time-string.js +9 -13
  69. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
  70. package/lib/whatwg/check-datetime/time-zone-offset-string.js +16 -21
  71. package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
  72. package/lib/whatwg/check-datetime/week-string.js +9 -13
  73. package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
  74. package/lib/whatwg/check-datetime/year-string.js +9 -13
  75. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
  76. package/lib/whatwg/check-datetime/yearless-date-string.js +9 -13
  77. package/lib/whatwg/check-mime-type.d.ts +1 -1
  78. package/lib/whatwg/check-mime-type.js +12 -18
  79. package/lib/whatwg/is-abs-url.d.ts +1 -1
  80. package/lib/whatwg/is-abs-url.js +1 -5
  81. package/lib/whatwg/is-browser-context-name.d.ts +3 -1
  82. package/lib/whatwg/is-browser-context-name.js +3 -5
  83. package/lib/whatwg/is-custom-element-name.d.ts +1 -1
  84. package/lib/whatwg/is-custom-element-name.js +1 -5
  85. package/lib/whatwg/is-itemprop-name.d.ts +1 -1
  86. package/lib/whatwg/is-itemprop-name.js +2 -6
  87. package/lib/whatwg/is-navigable-target-name.d.ts +11 -0
  88. package/lib/whatwg/is-navigable-target-name.js +20 -0
  89. package/package.json +19 -14
  90. package/types.schema.json +314 -311
  91. package/gen/specific-schema.json +0 -98
  92. package/gen/types.ts +0 -66
  93. package/lib/check.spec.js +0 -76
  94. package/lib/css-syntax.spec.d.ts +0 -1
  95. package/lib/css-syntax.spec.js +0 -157
  96. package/lib/list.spec.d.ts +0 -1
  97. package/lib/list.spec.js +0 -129
  98. package/lib/primitive/index.spec.d.ts +0 -1
  99. package/lib/primitive/index.spec.js +0 -62
  100. package/lib/rfc/is-bcp-47.spec.d.ts +0 -1
  101. package/lib/rfc/is-bcp-47.spec.js +0 -19
  102. package/lib/token/token-collection.spec.d.ts +0 -1
  103. package/lib/token/token-collection.spec.js +0 -144
  104. package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +0 -1
  105. package/lib/w3c/check-serialized-permissions-policy.spec.js +0 -34
  106. package/lib/whatwg/check-autocomplete.spec.d.ts +0 -1
  107. package/lib/whatwg/check-autocomplete.spec.js +0 -379
  108. package/lib/whatwg/check-datetime/index.spec.d.ts +0 -1
  109. package/lib/whatwg/check-datetime/index.spec.js +0 -318
  110. package/lib/whatwg/check-mime-type.spec.d.ts +0 -1
  111. package/lib/whatwg/check-mime-type.spec.js +0 -58
  112. package/lib/whatwg/is-abs-url.spec.d.ts +0 -1
  113. package/lib/whatwg/is-abs-url.spec.js +0 -8
  114. package/patches/css-tree+2.3.1.patch +0 -23
  115. package/src/check-multi-types.ts +0 -35
  116. package/src/check.spec.ts +0 -83
  117. package/src/check.ts +0 -48
  118. package/src/css-syntax.spec.ts +0 -167
  119. package/src/css-syntax.ts +0 -188
  120. package/src/debug.ts +0 -3
  121. package/src/defs.ts +0 -811
  122. package/src/enum.ts +0 -25
  123. package/src/get-candidate.ts +0 -24
  124. package/src/index.ts +0 -3
  125. package/src/keyword-type.ts +0 -64
  126. package/src/list.spec.ts +0 -133
  127. package/src/list.ts +0 -34
  128. package/src/match-result.ts +0 -49
  129. package/src/number.ts +0 -46
  130. package/src/primitive/index.spec.ts +0 -65
  131. package/src/primitive/index.ts +0 -7
  132. package/src/primitive/is-float.ts +0 -8
  133. package/src/primitive/is-int.ts +0 -8
  134. package/src/primitive/is-non-zero-uint.ts +0 -8
  135. package/src/primitive/is-quantity.ts +0 -38
  136. package/src/primitive/is-uint.ts +0 -15
  137. package/src/primitive/range.ts +0 -14
  138. package/src/primitive/split-unit.ts +0 -20
  139. package/src/rfc/is-bcp-47.spec.ts +0 -23
  140. package/src/rfc/is-bcp-47.ts +0 -13
  141. package/src/token/index.ts +0 -2
  142. package/src/token/token-collection.spec.ts +0 -147
  143. package/src/token/token-collection.ts +0 -444
  144. package/src/token/token.ts +0 -144
  145. package/src/types.schema.ts +0 -1113
  146. package/src/types.ts +0 -118
  147. package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
  148. package/src/w3c/check-serialized-permissions-policy.ts +0 -303
  149. package/src/whatwg/check-autocomplete.spec.ts +0 -387
  150. package/src/whatwg/check-autocomplete.ts +0 -380
  151. package/src/whatwg/check-datetime/date-string.ts +0 -44
  152. package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
  153. package/src/whatwg/check-datetime/duration-string.ts +0 -399
  154. package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
  155. package/src/whatwg/check-datetime/index.spec.ts +0 -333
  156. package/src/whatwg/check-datetime/index.ts +0 -36
  157. package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
  158. package/src/whatwg/check-datetime/month-string.ts +0 -31
  159. package/src/whatwg/check-datetime/time-string.ts +0 -49
  160. package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
  161. package/src/whatwg/check-datetime/week-string.ts +0 -41
  162. package/src/whatwg/check-datetime/year-string.ts +0 -26
  163. package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
  164. package/src/whatwg/check-mime-type.spec.ts +0 -59
  165. package/src/whatwg/check-mime-type.ts +0 -46
  166. package/src/whatwg/is-abs-url.spec.ts +0 -8
  167. package/src/whatwg/is-abs-url.ts +0 -31
  168. package/src/whatwg/is-browser-context-name.ts +0 -16
  169. package/src/whatwg/is-custom-element-name.ts +0 -76
  170. package/src/whatwg/is-itemprop-name.ts +0 -17
  171. package/tsconfig.test.json +0 -3
  172. package/tsconfig.tsbuildinfo +0 -1
  173. /package/lib/{check.spec.d.ts → token/types.js} +0 -0
@@ -1,27 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkKeywordType = void 0;
4
- const check_1 = require("./check");
5
- const css_syntax_1 = require("./css-syntax");
6
- const debug_1 = require("./debug");
7
- const defs_1 = require("./defs");
8
- const match_result_1 = require("./match-result");
1
+ import { isCSSSyntax } from './check.js';
2
+ import { cssSyntaxMatch } from './css-syntax.js';
3
+ import { log } from './debug.js';
4
+ import { types } from './defs.js';
5
+ import { matched } from './match-result.js';
9
6
  const resultCache = new Map();
10
7
  const CACHE_KEY_PREFIX = '@markuplint/types/checkKeywordType/cache:::';
11
- function checkKeywordType(value, type, cache = true) {
8
+ export function checkKeywordType(value, type, cache = true) {
12
9
  const key = `${CACHE_KEY_PREFIX}${value}${type}`;
13
10
  if (cache) {
14
11
  const cachedResult = resultCache.get(key);
15
12
  if (cachedResult) {
16
- (0, debug_1.log)('Restore cache: %s / %s', value, type);
13
+ log('Restore cache: %s / %s', value, type);
17
14
  return cachedResult;
18
15
  }
19
16
  }
20
17
  const result = _checkKeywordType(value, type);
21
18
  if (cache) {
22
19
  resultCache.set(key, result);
23
- if (debug_1.log.enabled) {
24
- (0, debug_1.log)('Cache checking: %O', {
20
+ if (log.enabled) {
21
+ log('Cache checking: %O', {
25
22
  input: value,
26
23
  type,
27
24
  key,
@@ -31,28 +28,27 @@ function checkKeywordType(value, type, cache = true) {
31
28
  }
32
29
  return result;
33
30
  }
34
- exports.checkKeywordType = checkKeywordType;
35
31
  function _checkKeywordType(value, type) {
36
- const def = defs_1.types[type];
32
+ const def = types[type];
37
33
  if (!def) {
38
- (0, debug_1.log)('The "%s" type is not defined in custom type identifier markuplint specified', type);
34
+ log('The "%s" type is not defined in custom type identifier markuplint specified', type);
39
35
  try {
40
- return (0, css_syntax_1.cssSyntaxMatch)(value, type);
36
+ return cssSyntaxMatch(value, type);
41
37
  }
42
38
  catch (e) {
43
39
  if (e instanceof Error && e.message === 'MARKUPLINT_TYPE_NO_EXIST') {
44
- (0, debug_1.log)("Allow all of any value because the type doesn't exist");
45
- return (0, match_result_1.matched)();
40
+ log("Allow all of any value because the type doesn't exist");
41
+ return matched();
46
42
  }
47
43
  throw e;
48
44
  }
49
45
  }
50
- const matches = (0, check_1.isCSSSyntax)(def) ? (0, css_syntax_1.cssSyntaxMatch)(value, def) : def.is(value);
46
+ const matches = isCSSSyntax(def) ? cssSyntaxMatch(value, def) : def.is(value);
51
47
  if (!matches.matched) {
52
48
  return {
53
49
  ...matches,
54
- ref: matches.ref || def.ref,
55
- expects: matches.expects || def.expects,
50
+ ref: matches.ref ?? def.ref,
51
+ expects: matches.expects ?? def.expects,
56
52
  };
57
53
  }
58
54
  return matches;
package/lib/list.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import type { Result } from './types';
2
- import type { List } from './types.schema';
3
- export declare function checkList(value: string, type: List, ref?: string, cache?: boolean): Result;
1
+ import type { Result } from './types.js';
2
+ import type { List } from './types.schema.js';
3
+ import type { ReadonlyDeep } from 'type-fest';
4
+ export declare function checkList(value: string, type: ReadonlyDeep<List>, ref?: string, cache?: boolean): Result;
package/lib/list.js CHANGED
@@ -1,29 +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
- 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);
9
6
  const matches = tokens.check({ ref });
10
7
  if (!matches.matched) {
11
8
  return matches;
12
9
  }
13
10
  const identTokens = tokens.getIdentTokens();
14
11
  for (const token of identTokens) {
15
- const res = (0, check_1.check)(token.value, type.token, ref, cache);
12
+ const res = check(token.value, type.token, ref, cache);
16
13
  if (!res.matched) {
17
- const { offset, line, column } = token_1.Token.shiftLocation(token, res.offset);
14
+ const { offset, line, column } = Token.shiftLocation(token, res.offset);
18
15
  return {
19
16
  ...res,
20
- partName: res.partName || 'the content of the list',
17
+ partName: res.partName ?? 'the content of the list',
21
18
  offset,
22
19
  line,
23
20
  column,
24
21
  };
25
22
  }
26
23
  }
27
- return (0, match_result_1.matched)();
24
+ return matched();
28
25
  }
29
- exports.checkList = checkList;
@@ -1,9 +1,9 @@
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
- ref?: string;
4
- reason?: UnmatchedResultReason;
3
+ readonly ref?: string;
4
+ readonly reason?: UnmatchedResultReason;
5
5
  }): (value: string) => MatchedResult | UnmatchedResult;
6
6
  export declare function matched(): MatchedResult;
7
7
  export declare function unmatched(value: string, reason?: UnmatchedResultReason, options?: UnmatchedResultOptions & {
8
- ref?: string;
8
+ readonly ref?: string;
9
9
  }): UnmatchedResult;
@@ -1,33 +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) {
15
+ export function unmatched(value, reason, options) {
21
16
  return {
22
17
  ...options,
23
18
  matched: false,
24
- ref: (options === null || options === void 0 ? void 0 : options.ref) || null,
19
+ ref: options?.ref ?? null,
25
20
  raw: value,
26
21
  offset: 0,
27
22
  length: value.length,
28
23
  line: 1,
29
24
  column: 1,
30
- reason: reason !== null && reason !== void 0 ? reason : 'syntax-error',
25
+ reason: reason ?? 'syntax-error',
31
26
  };
32
27
  }
33
- 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';
3
- export declare function checkNumber(value: string, type: Number, ref?: string): Result;
1
+ import type { Result } from './types.js';
2
+ import type { Number } from './types.schema.js';
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;
@@ -4,4 +4,4 @@
4
4
  * @param units
5
5
  * @param numberType
6
6
  */
7
- export declare function isQuantity(value: string, units: string[], numberType?: 'int' | 'uint' | 'float'): boolean;
7
+ export declare function isQuantity(value: string, units: readonly string[], numberType?: 'int' | 'uint' | 'float'): boolean;
@@ -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;
@@ -4,5 +4,5 @@
4
4
  * @param value
5
5
  */
6
6
  export declare function isUint(value: string, options?: {
7
- gt?: number;
7
+ readonly gt?: number;
8
8
  }): boolean;
@@ -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,
21
- 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,12 +1,12 @@
1
- import type { UnmatchedResult } from '..';
2
- import type { Expect, Result, List } from '../types';
3
- import { Token } from './token';
1
+ import type { TokenValue } from './types.js';
2
+ import type { Expect, Result, List, UnmatchedResult } from '../types.js';
3
+ import { Token } from './token.js';
4
4
  type TokenCollectionOptions = Partial<Omit<List, 'token'> & {
5
5
  specificSeparator: string | string[];
6
6
  }>;
7
- export type TokenEachCheck = (head: Token | null, tail: TokenCollection) => Result | void;
7
+ export type TokenEachCheck = (head: Readonly<Token> | null, tail: TokenCollection) => Result | void;
8
8
  export declare class TokenCollection extends Array<Token> {
9
- static fromPatterns(value: Token | string, patterns: RegExp[], typeOptions?: Omit<TokenCollectionOptions, 'specificSeparator'> & {
9
+ static fromPatterns(value: Readonly<Token> | string, patterns: readonly Readonly<RegExp>[], typeOptions?: Omit<TokenCollectionOptions, 'specificSeparator'> & {
10
10
  repeat?: boolean;
11
11
  }): TokenCollection;
12
12
  static get [Symbol.species](): ArrayConstructor;
@@ -24,20 +24,20 @@ export declare class TokenCollection extends Array<Token> {
24
24
  expects?: Expect[];
25
25
  ref?: string;
26
26
  cache?: boolean;
27
- }): import("..").MatchedResult | UnmatchedResult;
27
+ }): import("../types.js").MatchedResult | UnmatchedResult;
28
28
  chunk(split: number): TokenCollection[];
29
- compareTokens(callback: (prev: Token, current: Token) => Token | null | void): Token | null | undefined;
29
+ compareTokens(callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void): Readonly<Token> | null | undefined;
30
30
  divide(position: number): readonly [TokenCollection, TokenCollection];
31
- eachCheck(...callbacks: TokenEachCheck[]): Result;
32
- filter(callback: (value: Token, index: number, array: Token[]) => boolean): TokenCollection;
33
- getConsecutiveToken(tokenType: number): Token | null;
31
+ eachCheck(...callbacks: readonly TokenEachCheck[]): Result;
32
+ filter(callback: Parameters<Array<Token>['filter']>[0]): TokenCollection;
33
+ getConsecutiveToken(tokenType: number): Readonly<Token> | null;
34
34
  getDuplicated(): Token | null;
35
35
  getIdentTokens(): TokenCollection;
36
36
  /**
37
37
  *
38
38
  * @param value The token value or the token type or its list
39
39
  */
40
- has(value: string | RegExp | number | (string | RegExp | number)[]): boolean;
40
+ has(value: TokenValue): boolean;
41
41
  headAndTail(): {
42
42
  head: Token | null;
43
43
  tail: TokenCollection;
@@ -46,10 +46,10 @@ export declare class TokenCollection extends Array<Token> {
46
46
  *
47
47
  * @param value The token value or the token type or its list
48
48
  */
49
- search(value: string | RegExp | number | (string | RegExp | number)[]): Token | null;
49
+ search(value: TokenValue): Token | null;
50
50
  takeTurns(tokenNumbers: ReadonlyArray<number>, lastTokenNumber?: number): {
51
51
  unexpectedLastToken: boolean;
52
- expectedTokenNumber: number;
52
+ expectedTokenNumber: number | undefined;
53
53
  token: Token;
54
54
  } | null;
55
55
  toJSON(): {