@markuplint/types 3.12.0 → 4.0.0-alpha.10

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 (101) hide show
  1. package/LICENSE +1 -1
  2. package/lib/check-multi-types.d.ts +2 -5
  3. package/lib/check-multi-types.js +9 -14
  4. package/lib/check.d.ts +1 -1
  5. package/lib/check.js +20 -30
  6. package/lib/css-syntax.d.ts +1 -1
  7. package/lib/css-syntax.js +33 -33
  8. package/lib/debug.js +2 -6
  9. package/lib/defs.d.ts +2 -1
  10. package/lib/defs.js +188 -138
  11. package/lib/enum.d.ts +2 -2
  12. package/lib/enum.js +7 -12
  13. package/lib/get-candidate.d.ts +1 -4
  14. package/lib/get-candidate.js +5 -10
  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 +20 -25
  19. package/lib/list.d.ts +2 -2
  20. package/lib/list.js +9 -14
  21. package/lib/match-result.d.ts +8 -21
  22. package/lib/match-result.js +6 -13
  23. package/lib/number.d.ts +3 -3
  24. package/lib/number.js +13 -17
  25. package/lib/primitive/index.d.ts +7 -7
  26. package/lib/primitive/index.js +7 -17
  27. package/lib/primitive/is-float.js +2 -6
  28. package/lib/primitive/is-int.js +2 -6
  29. package/lib/primitive/is-non-zero-uint.js +2 -6
  30. package/lib/primitive/is-quantity.d.ts +1 -5
  31. package/lib/primitive/is-quantity.js +9 -13
  32. package/lib/primitive/is-uint.d.ts +3 -6
  33. package/lib/primitive/is-uint.js +4 -8
  34. package/lib/primitive/range.js +3 -7
  35. package/lib/primitive/split-unit.d.ts +2 -2
  36. package/lib/primitive/split-unit.js +4 -8
  37. package/lib/rfc/is-bcp-47.d.ts +1 -1
  38. package/lib/rfc/is-bcp-47.js +3 -7
  39. package/lib/token/index.d.ts +2 -2
  40. package/lib/token/index.js +2 -7
  41. package/lib/token/token-collection.d.ts +58 -70
  42. package/lib/token/token-collection.js +47 -56
  43. package/lib/token/token.d.ts +54 -59
  44. package/lib/token/token.js +14 -20
  45. package/lib/token/types.js +1 -2
  46. package/lib/types.d.ts +58 -82
  47. package/lib/types.js +1 -2
  48. package/lib/types.schema.d.ts +31 -1087
  49. package/lib/types.schema.js +1 -2
  50. package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
  51. package/lib/w3c/check-serialized-permissions-policy.js +21 -25
  52. package/lib/whatwg/check-autocomplete.d.ts +1 -1
  53. package/lib/whatwg/check-autocomplete.js +34 -41
  54. package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
  55. package/lib/whatwg/check-datetime/date-string.js +12 -16
  56. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +2 -22
  57. package/lib/whatwg/check-datetime/datetime-tokens.js +58 -64
  58. package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
  59. package/lib/whatwg/check-datetime/duration-string.js +64 -69
  60. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
  61. package/lib/whatwg/check-datetime/global-date-and-time-string.js +24 -28
  62. package/lib/whatwg/check-datetime/index.d.ts +1 -1
  63. package/lib/whatwg/check-datetime/index.js +25 -29
  64. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
  65. package/lib/whatwg/check-datetime/local-date-and-time-string.js +37 -41
  66. package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
  67. package/lib/whatwg/check-datetime/month-string.js +9 -13
  68. package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
  69. package/lib/whatwg/check-datetime/time-string.js +13 -17
  70. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
  71. package/lib/whatwg/check-datetime/time-zone-offset-string.js +22 -28
  72. package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
  73. package/lib/whatwg/check-datetime/week-string.js +11 -15
  74. package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
  75. package/lib/whatwg/check-datetime/year-string.js +9 -13
  76. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
  77. package/lib/whatwg/check-datetime/yearless-date-string.js +11 -15
  78. package/lib/whatwg/check-mime-type.d.ts +5 -5
  79. package/lib/whatwg/check-mime-type.js +11 -17
  80. package/lib/whatwg/is-abs-url.d.ts +1 -1
  81. package/lib/whatwg/is-abs-url.js +8 -12
  82. package/lib/whatwg/is-browser-context-name.d.ts +1 -1
  83. package/lib/whatwg/is-browser-context-name.js +1 -5
  84. package/lib/whatwg/is-custom-element-name.d.ts +10 -5
  85. package/lib/whatwg/is-custom-element-name.js +22 -38
  86. package/lib/whatwg/is-itemprop-name.d.ts +1 -1
  87. package/lib/whatwg/is-itemprop-name.js +1 -5
  88. package/lib/whatwg/is-navigable-target-name.d.ts +1 -1
  89. package/lib/whatwg/is-navigable-target-name.js +1 -5
  90. package/package.json +17 -9
  91. package/test/check.spec.js +0 -89
  92. package/test/css-syntax.spec.js +0 -170
  93. package/test/list.spec.js +0 -133
  94. package/test/primitive/index.spec.js +0 -65
  95. package/test/rfc/is-bcp-47.spec.js +0 -23
  96. package/test/token/token-collection.spec.js +0 -146
  97. package/test/w3c/check-serialized-permissions-policy.spec.js +0 -36
  98. package/test/whatwg/check-autocomplete.spec.js +0 -387
  99. package/test/whatwg/check-datetime/index.spec.js +0 -336
  100. package/test/whatwg/check-mime-type.spec.js +0 -59
  101. package/test/whatwg/is-abs-url.spec.js +0 -8
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2019 Yusuke Hirao
3
+ Copyright (c) 2017-2024 Yusuke Hirao
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,2 @@
1
- import type { CustomSyntaxCheck, UnmatchedResult } from './types';
2
- export declare function checkMultiTypes(
3
- value: string,
4
- checks: readonly CustomSyntaxCheck[],
5
- ): UnmatchedResult | import('./types').MatchedResult;
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, overrides } 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,16 +21,16 @@ 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
- Object.keys(types).forEach(key => {
33
+ for (const key of Object.keys(types)) {
38
34
  const valueOrChecker = types[key];
39
35
  if (typeof valueOrChecker === 'string') {
40
36
  typesExtended[key] = valueOrChecker;
@@ -42,47 +38,52 @@ function cssSyntaxMatch(value, type) {
42
38
  else if (valueOrChecker) {
43
39
  typesCheckers[key] = valueOrChecker;
44
40
  }
45
- });
41
+ }
46
42
  propsExtended = { ...type.syntax.properties };
47
43
  if (type.caseSensitive) {
48
44
  caseSensitive = true;
49
- Object.keys(typesExtended).forEach(key => eachMimicCases(key, typesExtended));
50
- Object.keys(propsExtended).forEach(key => eachMimicCases(key, propsExtended));
45
+ for (const key of Object.keys(typesExtended))
46
+ eachMimicCases(key, typesExtended);
47
+ for (const key of Object.keys(propsExtended))
48
+ eachMimicCases(key, propsExtended);
51
49
  value = mimicCases(value);
52
50
  }
53
51
  ref = type.ref;
54
52
  }
55
53
  // @ts-ignore
56
- const lexer = (0, css_tree_1.fork)({
57
- types: typesExtended,
54
+ const lexer = fork({
55
+ types: {
56
+ ...overrides,
57
+ ...typesExtended,
58
+ },
58
59
  properties: propsExtended,
59
60
  }).lexer;
60
- Object.keys(typesCheckers).forEach(key => {
61
+ for (const key of Object.keys(typesCheckers)) {
61
62
  const checker = typesCheckers[key];
62
63
  // @ts-ignore
63
- lexer.addType_(key, (token, getNextToken) => checker === null || checker === void 0 ? void 0 : checker(token, getNextToken, cssSyntaxMatch));
64
- });
64
+ lexer.addType_(key, (token, getNextToken) => checker?.(token, getNextToken, cssSyntaxMatch));
65
+ }
65
66
  const { isProp, name } = detectName(defName);
66
67
  // @ts-ignore
67
68
  const matcher = isProp ? lexer.properties[name] : lexer.types[name];
68
69
  if (!matcher) {
69
- (0, debug_1.log)('"%s" CSS syntax not found', defName);
70
+ log('"%s" CSS syntax not found', defName);
70
71
  throw new Error('MARKUPLINT_TYPE_NO_EXIST');
71
72
  }
72
73
  const refParam = isProp ? 'Property' : 'Type';
73
- ref = ref !== null && ref !== void 0 ? ref : `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
74
+ ref = ref ?? `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
74
75
  // eslint-disable-next-line no-console
75
76
  const _w = console.warn;
76
- if (debug_1.log.enabled) {
77
+ if (log.enabled) {
77
78
  // eslint-disable-next-line no-console
78
- console.warn = warn => (0, debug_1.log)('WARNING: %s (by %s => %s)', warn, value, type);
79
+ console.warn = warn => log('WARNING: %s (by %s => %s)', warn, value, type);
79
80
  }
80
81
  const result = lexer.match(defName, value);
81
- (0, debug_1.log)('css-tree/result: %O', result);
82
+ log('css-tree/result: %O', result);
82
83
  // eslint-disable-next-line no-console
83
84
  console.warn = _w;
84
85
  if (!result.error) {
85
- return (0, match_result_1.matched)();
86
+ return matched();
86
87
  }
87
88
  if (!('css' in result.error)) {
88
89
  throw result.error;
@@ -99,7 +100,7 @@ function cssSyntaxMatch(value, type) {
99
100
  const mismatchLength = error.mismatchLength - MIMIC_LENGTH;
100
101
  error.mismatchLength = mismatchLength < 0 ? error.mismatchLength : mismatchLength;
101
102
  }
102
- (0, debug_1.log)('css-tree/SyntaxMatchError: %O', error);
103
+ log('css-tree/SyntaxMatchError: %O', error);
103
104
  return {
104
105
  matched: false,
105
106
  ref,
@@ -118,10 +119,9 @@ function cssSyntaxMatch(value, type) {
118
119
  reason: 'syntax-error',
119
120
  };
120
121
  }
121
- exports.cssSyntaxMatch = cssSyntaxMatch;
122
122
  function detectName(def) {
123
123
  const isProp = def.search("<'") === 0;
124
- const name = def.replace(/^<'?|'?>$/g, '');
124
+ const name = def.replaceAll(/^<'?|'?>$/g, '');
125
125
  return {
126
126
  isProp,
127
127
  name,
@@ -145,8 +145,8 @@ obj) {
145
145
  obj[key] = mimicCases(value);
146
146
  }
147
147
  function mimicCases(value) {
148
- return value.replace(/[A-Z]/g, $0 => `${MIMIC_TAG_L}${$0}${MIMIC_TAG_R}`);
148
+ return value.replaceAll(/[A-Z]/g, $0 => `${MIMIC_TAG_L}${$0}${MIMIC_TAG_R}`);
149
149
  }
150
150
  function deMimicCases(value) {
151
- return value.replace(new RegExp(`${MIMIC_TAG_L}([A-Z])${MIMIC_TAG_R}`, 'g'), (_, $1) => $1);
151
+ return value.replaceAll(new RegExp(`${MIMIC_TAG_L}([A-Z])${MIMIC_TAG_R}`, 'g'), (_, $1) => $1);
152
152
  }
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,4 @@
1
- import type { Defs, CssSyntaxTokenizer } from './types';
1
+ import type { Defs, CssSyntaxTokenizer } from './types.js';
2
2
  export declare const types: Defs;
3
+ export declare const overrides: Record<string, string>;
3
4
  export declare const tokenizers: Record<string, CssSyntaxTokenizer>;