@markuplint/types 3.9.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
@@ -1,2 +1,2 @@
1
- import type { CustomSyntaxCheck, UnmatchedResult } from './types';
2
- export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): import("./types").MatchedResult | UnmatchedResult;
1
+ import type { CustomSyntaxCheck, UnmatchedResult } from './types.js';
2
+ export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): import("./types.js").MatchedResult | UnmatchedResult;
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkMultiTypes = void 0;
4
- const debug_1 = require("./debug");
5
- const match_result_1 = require("./match-result");
6
- function checkMultiTypes(value, checks) {
7
- var _a, _b, _c;
1
+ import { log } from './debug.js';
2
+ import { matched } from './match-result.js';
3
+ export function checkMultiTypes(value, checks) {
8
4
  let unmatched;
9
5
  for (const check of checks) {
10
6
  const res = check(value);
@@ -14,17 +10,16 @@ function checkMultiTypes(value, checks) {
14
10
  // @ts-ignore
15
11
  res._fn = check.name;
16
12
  // @ts-ignore
17
- (0, debug_1.log)('%s(%d) vs %s(%d)', unmatched === null || unmatched === void 0 ? void 0 : unmatched._fn, unmatched === null || unmatched === void 0 ? void 0 : unmatched.passCount, res._fn, res.passCount);
18
- const passedA = (_a = unmatched === null || unmatched === void 0 ? void 0 : unmatched.passCount) !== null && _a !== void 0 ? _a : 0;
19
- const passedB = (_b = res.passCount) !== null && _b !== void 0 ? _b : 0;
20
- const offsetA = (_c = unmatched === null || unmatched === void 0 ? void 0 : unmatched.offset) !== null && _c !== void 0 ? _c : 0;
13
+ log('%s(%d) vs %s(%d)', unmatched?._fn, unmatched?.passCount, res._fn, res.passCount);
14
+ const passedA = unmatched?.passCount ?? 0;
15
+ const passedB = res.passCount ?? 0;
16
+ const offsetA = unmatched?.offset ?? 0;
21
17
  const offsetB = res.offset;
22
18
  if (passedA < passedB || (passedA === passedB && offsetA <= offsetB)) {
23
19
  unmatched = res;
24
20
  }
25
21
  }
26
- const result = unmatched !== null && unmatched !== void 0 ? unmatched : (0, match_result_1.matched)();
27
- (0, debug_1.log)('%d checks result: %O', checks.length, result);
22
+ const result = unmatched ?? matched();
23
+ log('%d checks result: %O', checks.length, result);
28
24
  return result;
29
25
  }
30
- exports.checkMultiTypes = checkMultiTypes;
package/lib/check.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types';
1
+ import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types.js';
2
2
  import type { ReadonlyDeep } from 'type-fest';
3
3
  export declare function check(value: string, type: ReadonlyDeep<Type>, ref?: string, cache?: boolean): Result;
4
4
  export declare function isKeyword(type: ReadonlyDeep<Type>): type is ReadonlyDeep<KeywordDefinedType>;
package/lib/check.js CHANGED
@@ -1,49 +1,39 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isCustomSyntax = exports.isCSSSyntax = exports.isNumber = exports.isEnum = exports.isList = exports.isKeyword = exports.check = void 0;
4
- const debug_1 = require("./debug");
5
- const enum_1 = require("./enum");
6
- const keyword_type_1 = require("./keyword-type");
7
- const list_1 = require("./list");
8
- const number_1 = require("./number");
9
- function check(value, type, ref, cache = true) {
1
+ import { log } from './debug.js';
2
+ import { checkEnum } from './enum.js';
3
+ import { checkKeywordType } from './keyword-type.js';
4
+ import { checkList } from './list.js';
5
+ import { checkNumber } from './number.js';
6
+ export function check(value, type, ref, cache = true) {
10
7
  if (isKeyword(type)) {
11
- (0, debug_1.log)('Check keyword: %s', type);
12
- return (0, keyword_type_1.checkKeywordType)(value, type, cache);
8
+ log('Check keyword: %s', type);
9
+ return checkKeywordType(value, type, cache);
13
10
  }
14
11
  if (isList(type)) {
15
- (0, debug_1.log)('Check list: %O', type);
16
- return (0, list_1.checkList)(value, type, ref, cache);
12
+ log('Check list: %O', type);
13
+ return checkList(value, type, ref, cache);
17
14
  }
18
15
  if (isEnum(type)) {
19
- (0, debug_1.log)('Check enum: %O', type);
20
- return (0, enum_1.checkEnum)(value, type, ref);
16
+ log('Check enum: %O', type);
17
+ return checkEnum(value, type, ref);
21
18
  }
22
- (0, debug_1.log)('Check number: %O', type);
23
- return (0, number_1.checkNumber)(value, type, ref);
19
+ log('Check number: %O', type);
20
+ return checkNumber(value, type, ref);
24
21
  }
25
- exports.check = check;
26
- function isKeyword(type) {
22
+ export function isKeyword(type) {
27
23
  return typeof type === 'string';
28
24
  }
29
- exports.isKeyword = isKeyword;
30
- function isList(type) {
25
+ export function isList(type) {
31
26
  return typeof type !== 'string' && 'token' in type;
32
27
  }
33
- exports.isList = isList;
34
- function isEnum(type) {
28
+ export function isEnum(type) {
35
29
  return typeof type !== 'string' && 'enum' in type;
36
30
  }
37
- exports.isEnum = isEnum;
38
- function isNumber(type) {
31
+ export function isNumber(type) {
39
32
  return typeof type !== 'string' && 'enum' in type;
40
33
  }
41
- exports.isNumber = isNumber;
42
- function isCSSSyntax(type) {
34
+ export function isCSSSyntax(type) {
43
35
  return typeof type === 'string' || 'syntax' in type;
44
36
  }
45
- exports.isCSSSyntax = isCSSSyntax;
46
- function isCustomSyntax(type) {
37
+ export function isCustomSyntax(type) {
47
38
  return !isCSSSyntax(type);
48
39
  }
49
- exports.isCustomSyntax = isCustomSyntax;
@@ -1,2 +1,2 @@
1
- import type { CustomCssSyntax, Result, CssSyntax } from './types';
1
+ import type { CustomCssSyntax, Result, CssSyntax } from './types.js';
2
2
  export declare function cssSyntaxMatch(value: string, type: CssSyntax | CustomCssSyntax): Result;
package/lib/css-syntax.js CHANGED
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cssSyntaxMatch = void 0;
4
- const css_tree_1 = require("css-tree");
5
- const debug_1 = require("./debug");
6
- const defs_1 = require("./defs");
7
- const match_result_1 = require("./match-result");
1
+ import { fork } from 'css-tree';
2
+ import { log } from './debug.js';
3
+ import { tokenizers } from './defs.js';
4
+ import { matched } from './match-result.js';
8
5
  const MIMIC_TAG_L = 'mimiccases---';
9
6
  const MIMIC_TAG_R = '---mimiccases';
10
7
  const MIMIC_LENGTH = (MIMIC_TAG_L + MIMIC_TAG_R).length;
11
- function cssSyntaxMatch(value, type) {
12
- var _a;
13
- (0, debug_1.log)('Search CSS Syntax: "%s"', type);
8
+ export function cssSyntaxMatch(value, type) {
9
+ log('Search CSS Syntax: "%s"', type);
14
10
  const origin = value;
15
11
  let defName;
16
12
  const typesExtended = {};
@@ -25,13 +21,13 @@ function cssSyntaxMatch(value, type) {
25
21
  }
26
22
  else {
27
23
  defName = type.syntax.apply;
28
- ebnf = (_a = type.syntax.ebnf) !== null && _a !== void 0 ? _a : null;
24
+ ebnf = type.syntax.ebnf ?? null;
29
25
  if (ebnf) {
30
26
  // Work in progress
31
- return (0, match_result_1.matched)();
27
+ return matched();
32
28
  }
33
29
  const types = {
34
- ...defs_1.tokenizers,
30
+ ...tokenizers,
35
31
  ...type.syntax.def,
36
32
  };
37
33
  Object.keys(types).forEach(key => {
@@ -53,36 +49,36 @@ function cssSyntaxMatch(value, type) {
53
49
  ref = type.ref;
54
50
  }
55
51
  // @ts-ignore
56
- const lexer = (0, css_tree_1.fork)({
52
+ const lexer = fork({
57
53
  types: typesExtended,
58
54
  properties: propsExtended,
59
55
  }).lexer;
60
56
  Object.keys(typesCheckers).forEach(key => {
61
57
  const checker = typesCheckers[key];
62
58
  // @ts-ignore
63
- lexer.addType_(key, (token, getNextToken) => checker === null || checker === void 0 ? void 0 : checker(token, getNextToken, cssSyntaxMatch));
59
+ lexer.addType_(key, (token, getNextToken) => checker?.(token, getNextToken, cssSyntaxMatch));
64
60
  });
65
61
  const { isProp, name } = detectName(defName);
66
62
  // @ts-ignore
67
63
  const matcher = isProp ? lexer.properties[name] : lexer.types[name];
68
64
  if (!matcher) {
69
- (0, debug_1.log)('"%s" CSS syntax not found', defName);
65
+ log('"%s" CSS syntax not found', defName);
70
66
  throw new Error('MARKUPLINT_TYPE_NO_EXIST');
71
67
  }
72
68
  const refParam = isProp ? 'Property' : 'Type';
73
- ref = ref !== null && ref !== void 0 ? ref : `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
69
+ ref = ref ?? `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
74
70
  // eslint-disable-next-line no-console
75
71
  const _w = console.warn;
76
- if (debug_1.log.enabled) {
72
+ if (log.enabled) {
77
73
  // eslint-disable-next-line no-console
78
- console.warn = warn => (0, debug_1.log)('WARNING: %s (by %s => %s)', warn, value, type);
74
+ console.warn = warn => log('WARNING: %s (by %s => %s)', warn, value, type);
79
75
  }
80
76
  const result = lexer.match(defName, value);
81
- (0, debug_1.log)('css-tree/result: %O', result);
77
+ log('css-tree/result: %O', result);
82
78
  // eslint-disable-next-line no-console
83
79
  console.warn = _w;
84
80
  if (!result.error) {
85
- return (0, match_result_1.matched)();
81
+ return matched();
86
82
  }
87
83
  if (!('css' in result.error)) {
88
84
  throw result.error;
@@ -99,7 +95,7 @@ function cssSyntaxMatch(value, type) {
99
95
  const mismatchLength = error.mismatchLength - MIMIC_LENGTH;
100
96
  error.mismatchLength = mismatchLength < 0 ? error.mismatchLength : mismatchLength;
101
97
  }
102
- (0, debug_1.log)('css-tree/SyntaxMatchError: %O', error);
98
+ log('css-tree/SyntaxMatchError: %O', error);
103
99
  return {
104
100
  matched: false,
105
101
  ref,
@@ -118,7 +114,6 @@ function cssSyntaxMatch(value, type) {
118
114
  reason: 'syntax-error',
119
115
  };
120
116
  }
121
- exports.cssSyntaxMatch = cssSyntaxMatch;
122
117
  function detectName(def) {
123
118
  const isProp = def.search("<'") === 0;
124
119
  const name = def.replace(/^<'?|'?>$/g, '');
package/lib/debug.js CHANGED
@@ -1,6 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.log = void 0;
4
- const tslib_1 = require("tslib");
5
- const debug_1 = tslib_1.__importDefault(require("debug"));
6
- exports.log = (0, debug_1.default)('@markuplint/types');
1
+ import debug from 'debug';
2
+ export const log = debug('@markuplint/types');
package/lib/defs.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Defs, CssSyntaxTokenizer } from './types';
1
+ import type { Defs, CssSyntaxTokenizer } from './types.js';
2
2
  export declare const types: Defs;
3
3
  export declare const tokenizers: Record<string, CssSyntaxTokenizer>;