@markuplint/types 4.8.1 → 5.0.0-alpha.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 (116) hide show
  1. package/ARCHITECTURE.ja.md +256 -0
  2. package/ARCHITECTURE.md +256 -0
  3. package/CHANGELOG.md +18 -2
  4. package/README.md +37 -2
  5. package/SKILL.md +100 -0
  6. package/docs/check-pipeline.ja.md +494 -0
  7. package/docs/check-pipeline.md +494 -0
  8. package/docs/token-system.ja.md +584 -0
  9. package/docs/token-system.md +584 -0
  10. package/docs/type-system.ja.md +556 -0
  11. package/docs/type-system.md +556 -0
  12. package/docs/validators.ja.md +524 -0
  13. package/docs/validators.md +524 -0
  14. package/lib/check-base.d.ts +81 -1
  15. package/lib/check-base.js +87 -0
  16. package/lib/check-multi-types.d.ts +12 -1
  17. package/lib/check-multi-types.js +11 -0
  18. package/lib/check.d.ts +13 -0
  19. package/lib/check.js +13 -0
  20. package/lib/css-defs.d.ts +8 -0
  21. package/lib/css-defs.js +8 -0
  22. package/lib/css-overrides.d.ts +7 -0
  23. package/lib/css-overrides.js +7 -0
  24. package/lib/css-syntax.d.ts +11 -0
  25. package/lib/css-syntax.js +12 -1
  26. package/lib/css-tokenizers.d.ts +6 -0
  27. package/lib/css-tokenizers.js +6 -0
  28. package/lib/debug.d.ts +3 -0
  29. package/lib/debug.js +3 -0
  30. package/lib/defs.d.ts +8 -0
  31. package/lib/defs.js +26 -0
  32. package/lib/directive.d.ts +14 -0
  33. package/lib/directive.js +14 -0
  34. package/lib/enum.d.ts +11 -0
  35. package/lib/enum.js +11 -0
  36. package/lib/get-candidate.d.ts +11 -0
  37. package/lib/get-candidate.js +11 -0
  38. package/lib/index.d.ts +10 -1
  39. package/lib/index.js +9 -1
  40. package/lib/keyword-type.d.ts +13 -0
  41. package/lib/keyword-type.js +13 -0
  42. package/lib/list.d.ts +13 -0
  43. package/lib/list.js +13 -0
  44. package/lib/match-result.d.ts +22 -1
  45. package/lib/match-result.js +21 -0
  46. package/lib/number.d.ts +12 -0
  47. package/lib/number.js +12 -0
  48. package/lib/pattern.d.ts +12 -0
  49. package/lib/pattern.js +33 -0
  50. package/lib/primitive/is-float.d.ts +4 -1
  51. package/lib/primitive/is-float.js +4 -1
  52. package/lib/primitive/is-int.d.ts +4 -1
  53. package/lib/primitive/is-int.js +4 -1
  54. package/lib/primitive/is-non-zero-uint.d.ts +3 -2
  55. package/lib/primitive/is-non-zero-uint.js +3 -2
  56. package/lib/primitive/is-quantity.d.ts +5 -3
  57. package/lib/primitive/is-quantity.js +5 -3
  58. package/lib/primitive/is-uint.d.ts +5 -1
  59. package/lib/primitive/is-uint.js +5 -1
  60. package/lib/primitive/range.d.ts +5 -4
  61. package/lib/primitive/range.js +5 -4
  62. package/lib/primitive/split-unit.d.ts +3 -2
  63. package/lib/primitive/split-unit.js +3 -2
  64. package/lib/rfc/is-bcp-47.d.ts +2 -0
  65. package/lib/rfc/is-bcp-47.js +4 -2
  66. package/lib/token/token-collection.d.ts +108 -3
  67. package/lib/token/token-collection.js +110 -3
  68. package/lib/token/token.d.ts +66 -2
  69. package/lib/token/token.js +89 -21
  70. package/lib/token/types.d.ts +9 -0
  71. package/lib/types.d.ts +108 -1
  72. package/lib/types.schema.d.ts +4 -1
  73. package/lib/w3c/check-serialized-permissions-policy.d.ts +2 -0
  74. package/lib/w3c/check-serialized-permissions-policy.js +2 -0
  75. package/lib/whatwg/check-autocomplete.d.ts +10 -0
  76. package/lib/whatwg/check-autocomplete.js +214 -159
  77. package/lib/whatwg/check-datetime/date-string.d.ts +2 -0
  78. package/lib/whatwg/check-datetime/date-string.js +2 -0
  79. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +13 -0
  80. package/lib/whatwg/check-datetime/datetime-tokens.js +14 -1
  81. package/lib/whatwg/check-datetime/duration-string.d.ts +7 -0
  82. package/lib/whatwg/check-datetime/duration-string.js +7 -0
  83. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +2 -0
  84. package/lib/whatwg/check-datetime/global-date-and-time-string.js +2 -0
  85. package/lib/whatwg/check-datetime/index.d.ts +5 -0
  86. package/lib/whatwg/check-datetime/index.js +5 -0
  87. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +4 -0
  88. package/lib/whatwg/check-datetime/local-date-and-time-string.js +4 -0
  89. package/lib/whatwg/check-datetime/month-string.d.ts +2 -0
  90. package/lib/whatwg/check-datetime/month-string.js +2 -0
  91. package/lib/whatwg/check-datetime/time-string.d.ts +2 -0
  92. package/lib/whatwg/check-datetime/time-string.js +2 -0
  93. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +8 -0
  94. package/lib/whatwg/check-datetime/time-zone-offset-string.js +8 -0
  95. package/lib/whatwg/check-datetime/week-string.d.ts +2 -0
  96. package/lib/whatwg/check-datetime/week-string.js +2 -0
  97. package/lib/whatwg/check-datetime/year-string.d.ts +2 -0
  98. package/lib/whatwg/check-datetime/year-string.js +2 -0
  99. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +2 -0
  100. package/lib/whatwg/check-datetime/yearless-date-string.js +2 -0
  101. package/lib/whatwg/check-link-type.d.ts +108 -1
  102. package/lib/whatwg/check-link-type.js +17 -7
  103. package/lib/whatwg/check-mime-type.d.ts +4 -1
  104. package/lib/whatwg/check-mime-type.js +6 -3
  105. package/lib/whatwg/is-abs-url.d.ts +2 -0
  106. package/lib/whatwg/is-abs-url.js +3 -4
  107. package/lib/whatwg/is-browser-context-name.d.ts +2 -2
  108. package/lib/whatwg/is-browser-context-name.js +2 -2
  109. package/lib/whatwg/is-custom-element-name.d.ts +1 -1
  110. package/lib/whatwg/is-custom-element-name.js +1 -1
  111. package/lib/whatwg/is-itemprop-name.d.ts +1 -0
  112. package/lib/whatwg/is-itemprop-name.js +1 -0
  113. package/lib/whatwg/is-navigable-target-name.d.ts +2 -0
  114. package/lib/whatwg/is-navigable-target-name.js +2 -0
  115. package/package.json +8 -6
  116. package/types.schema.json +10 -1
package/lib/check-base.js CHANGED
@@ -4,6 +4,21 @@ import { checkEnum } from './enum.js';
4
4
  import { checkKeywordType } from './keyword-type.js';
5
5
  import { checkList } from './list.js';
6
6
  import { checkNumber } from './number.js';
7
+ import { checkPattern } from './pattern.js';
8
+ /**
9
+ * Validates a string value against a specified type definition using the provided
10
+ * set of custom type definitions. This is the core type-checking dispatcher that
11
+ * routes validation to the appropriate checker based on the type's structure
12
+ * (keyword, list, enum, number, or directive).
13
+ *
14
+ * @param value - The string value to validate
15
+ * @param type - The type definition to validate against
16
+ * @param defs - A map of custom type definitions (both CSS syntax and custom syntax) used for resolving keyword types
17
+ * @param ref - An optional reference identifier used for error reporting context
18
+ * @param cache - Whether to use cached results for repeated checks with the same inputs
19
+ * @returns A result indicating whether the value matches the type, or details about the mismatch
20
+ * @throws Error if the type does not match any known type structure
21
+ */
7
22
  export function checkBase(value, type, defs, ref, cache = true) {
8
23
  if (isKeyword(type)) {
9
24
  log('Check keyword: %s', type);
@@ -25,26 +40,98 @@ export function checkBase(value, type, defs, ref, cache = true) {
25
40
  log('Check directive: %O', type);
26
41
  return checkDirective(value, type, defs, ref, cache);
27
42
  }
43
+ if (isPattern(type)) {
44
+ log('Check pattern: %O', type);
45
+ return checkPattern(value, type);
46
+ }
28
47
  throw new Error('Unknown type');
29
48
  }
49
+ /**
50
+ * Determines whether a type definition is a keyword-based type.
51
+ * Keyword types are represented as plain strings (e.g., CSS syntax names
52
+ * like `"<color>"` or extended types like `"URL"`).
53
+ *
54
+ * @param type - The type definition to test
55
+ * @returns True if the type is a keyword-defined type string
56
+ */
30
57
  export function isKeyword(type) {
31
58
  return typeof type === 'string';
32
59
  }
60
+ /**
61
+ * Determines whether a type definition represents a list type.
62
+ * List types define space-separated or comma-separated token sequences
63
+ * and are identified by having a `separator` property.
64
+ *
65
+ * @param type - The type definition to test
66
+ * @returns True if the type is a list definition
67
+ */
33
68
  export function isList(type) {
34
69
  return typeof type !== 'string' && 'separator' in type;
35
70
  }
71
+ /**
72
+ * Determines whether a type definition represents an enumerated type.
73
+ * Enum types define a fixed set of allowed string values and are
74
+ * identified by having an `enum` property.
75
+ *
76
+ * @param type - The type definition to test
77
+ * @returns True if the type is an enum definition
78
+ */
36
79
  export function isEnum(type) {
37
80
  return typeof type !== 'string' && 'enum' in type;
38
81
  }
82
+ /**
83
+ * Determines whether a type definition represents a numeric type.
84
+ * Number types specify either `float` or `integer` validation with
85
+ * optional range constraints, and are identified by having a `type`
86
+ * property set to one of those values.
87
+ *
88
+ * @param type - The type definition to test
89
+ * @returns True if the type is a number definition
90
+ */
39
91
  export function isNumber(type) {
40
92
  return typeof type !== 'string' && 'type' in type && (type.type === 'float' || type.type === 'integer');
41
93
  }
94
+ /**
95
+ * Determines whether a type definition represents a directive type.
96
+ * Directive types allow separating and individually validating parts of
97
+ * an attribute value, and are identified by having a `directive` property.
98
+ *
99
+ * @param type - The type definition to test
100
+ * @returns True if the type is a directive definition
101
+ */
42
102
  export function isDirective(type) {
43
103
  return typeof type !== 'string' && 'directive' in type;
44
104
  }
105
+ /**
106
+ * Determines whether a type definition represents a pattern type.
107
+ * Pattern types validate attribute values against a regular expression
108
+ * or plain string, and are identified by having a `pattern` property.
109
+ *
110
+ * @param type - The type definition to test
111
+ * @returns True if the type is a pattern definition
112
+ */
113
+ export function isPattern(type) {
114
+ return typeof type !== 'string' && 'pattern' in type;
115
+ }
116
+ /**
117
+ * Determines whether a custom type definition uses CSS syntax matching.
118
+ * CSS syntax definitions are either plain strings or objects with a `syntax`
119
+ * property that specifies CSS value definition syntax for matching.
120
+ *
121
+ * @param type - The custom type definition to test
122
+ * @returns True if the definition uses CSS syntax matching
123
+ */
45
124
  export function isCSSSyntax(type) {
46
125
  return typeof type === 'string' || 'syntax' in type;
47
126
  }
127
+ /**
128
+ * Determines whether a custom type definition uses a programmatic custom
129
+ * syntax checker rather than CSS syntax matching. This is the inverse
130
+ * of {@link isCSSSyntax}.
131
+ *
132
+ * @param type - The custom type definition to test
133
+ * @returns True if the definition uses a custom programmatic checker function
134
+ */
48
135
  export function isCustomSyntax(type) {
49
136
  return !isCSSSyntax(type);
50
137
  }
@@ -1,2 +1,13 @@
1
1
  import type { CustomSyntaxCheck, UnmatchedResult } from './types.js';
2
- export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): UnmatchedResult | import("./types.js").MatchedResult;
2
+ /**
3
+ * Checks a value against multiple type checkers and returns the best result.
4
+ *
5
+ * Iterates through the provided checks and returns the first matched result.
6
+ * If none match, returns the unmatched result with the highest pass count
7
+ * or furthest offset, providing the most informative error.
8
+ *
9
+ * @param value - The string value to check
10
+ * @param checks - The array of type check functions to try
11
+ * @returns The matched result or the best unmatched result
12
+ */
13
+ export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): import("./types.js").MatchedResult | UnmatchedResult;
@@ -1,5 +1,16 @@
1
1
  import { log } from './debug.js';
2
2
  import { matched } from './match-result.js';
3
+ /**
4
+ * Checks a value against multiple type checkers and returns the best result.
5
+ *
6
+ * Iterates through the provided checks and returns the first matched result.
7
+ * If none match, returns the unmatched result with the highest pass count
8
+ * or furthest offset, providing the most informative error.
9
+ *
10
+ * @param value - The string value to check
11
+ * @param checks - The array of type check functions to try
12
+ * @returns The matched result or the best unmatched result
13
+ */
3
14
  export function checkMultiTypes(value, checks) {
4
15
  let unmatched;
5
16
  for (const check of checks) {
package/lib/check.d.ts CHANGED
@@ -1,3 +1,16 @@
1
1
  import type { Type, Result } from './types.js';
2
2
  import type { ReadonlyDeep } from 'type-fest';
3
+ /**
4
+ * Validates a string value against a specified type definition using
5
+ * the built-in HTML and CSS type definitions.
6
+ *
7
+ * This is the primary entry point for type checking in the @markuplint/types package.
8
+ * It delegates to {@link checkBase} with the combined set of HTML and CSS definitions.
9
+ *
10
+ * @param value - The string value to validate
11
+ * @param type - The type definition to validate against
12
+ * @param ref - An optional reference identifier used for error reporting context
13
+ * @param cache - Whether to use cached results for repeated checks with the same inputs
14
+ * @returns A result indicating whether the value matches the type, or details about the mismatch
15
+ */
3
16
  export declare function check(value: string, type: ReadonlyDeep<Type>, ref?: string, cache?: boolean): Result;
package/lib/check.js CHANGED
@@ -1,6 +1,19 @@
1
1
  import { checkBase } from './check-base.js';
2
2
  import { defs } from './defs.js';
3
3
  import { cssDefs } from './css-defs.js';
4
+ /**
5
+ * Validates a string value against a specified type definition using
6
+ * the built-in HTML and CSS type definitions.
7
+ *
8
+ * This is the primary entry point for type checking in the @markuplint/types package.
9
+ * It delegates to {@link checkBase} with the combined set of HTML and CSS definitions.
10
+ *
11
+ * @param value - The string value to validate
12
+ * @param type - The type definition to validate against
13
+ * @param ref - An optional reference identifier used for error reporting context
14
+ * @param cache - Whether to use cached results for repeated checks with the same inputs
15
+ * @returns A result indicating whether the value matches the type, or details about the mismatch
16
+ */
4
17
  export function check(value, type, ref, cache = true) {
5
18
  return checkBase(value, type, { ...defs, ...cssDefs }, ref, cache);
6
19
  }
package/lib/css-defs.d.ts CHANGED
@@ -1,2 +1,10 @@
1
1
  import type { Defs } from './types.js';
2
+ /**
3
+ * CSS and SVG type definitions for attribute value validation.
4
+ *
5
+ * Contains definitions for CSS declaration lists, SVG-specific types
6
+ * (paths, viewBox, preserveAspectRatio, etc.), and animation-related types.
7
+ * Each definition includes a reference URL and either a CSS syntax or
8
+ * a custom validation function.
9
+ */
2
10
  export declare const cssDefs: Defs;
package/lib/css-defs.js CHANGED
@@ -1,4 +1,12 @@
1
1
  import { matched } from './match-result.js';
2
+ /**
3
+ * CSS and SVG type definitions for attribute value validation.
4
+ *
5
+ * Contains definitions for CSS declaration lists, SVG-specific types
6
+ * (paths, viewBox, preserveAspectRatio, etc.), and animation-related types.
7
+ * Each definition includes a reference URL and either a CSS syntax or
8
+ * a custom validation function.
9
+ */
2
10
  export const cssDefs = {
3
11
  '<css-declaration-list>': {
4
12
  ref: 'https://drafts.csswg.org/css-style-attr/#syntax',
@@ -1 +1,8 @@
1
+ /**
2
+ * CSS syntax overrides for css-tree's built-in definitions.
3
+ *
4
+ * Provides alternative syntax definitions for CSS transform functions
5
+ * and legacy value types to support SVG attribute validation where
6
+ * the standard CSS syntax is too strict.
7
+ */
1
8
  export declare const cssOverrides: Record<string, string>;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * CSS syntax overrides for css-tree's built-in definitions.
3
+ *
4
+ * Provides alternative syntax definitions for CSS transform functions
5
+ * and legacy value types to support SVG attribute validation where
6
+ * the standard CSS syntax is too strict.
7
+ */
1
8
  export const cssOverrides = {
2
9
  // Alias
3
10
  'legacy-length-percentage': '<length> | <percentage> | <svg-length>',
@@ -1,2 +1,13 @@
1
1
  import type { CustomCssSyntax, Result, CssSyntax } from './types.js';
2
+ /**
3
+ * Matches a value against a CSS syntax definition using css-tree.
4
+ *
5
+ * Supports both standard CSS syntax types (e.g., `<color>`) and custom syntax
6
+ * definitions with extended types, properties, and case-sensitive matching.
7
+ * Uses css-tree's lexer for syntax validation.
8
+ *
9
+ * @param value - The string value to match
10
+ * @param type - The CSS syntax identifier or custom syntax definition
11
+ * @returns The validation result
12
+ */
2
13
  export declare function cssSyntaxMatch(value: string, type: CssSyntax | CustomCssSyntax): Result;
package/lib/css-syntax.js CHANGED
@@ -6,6 +6,17 @@ import { cssOverrides } from './css-overrides.js';
6
6
  const MIMIC_TAG_L = 'mimiccases---';
7
7
  const MIMIC_TAG_R = '---mimiccases';
8
8
  const MIMIC_LENGTH = (MIMIC_TAG_L + MIMIC_TAG_R).length;
9
+ /**
10
+ * Matches a value against a CSS syntax definition using css-tree.
11
+ *
12
+ * Supports both standard CSS syntax types (e.g., `<color>`) and custom syntax
13
+ * definitions with extended types, properties, and case-sensitive matching.
14
+ * Uses css-tree's lexer for syntax validation.
15
+ *
16
+ * @param value - The string value to match
17
+ * @param type - The CSS syntax identifier or custom syntax definition
18
+ * @returns The validation result
19
+ */
9
20
  export function cssSyntaxMatch(value, type) {
10
21
  log('Search CSS Syntax: "%s"', type);
11
22
  const origin = value;
@@ -15,7 +26,7 @@ export function cssSyntaxMatch(value, type) {
15
26
  let propsExtended;
16
27
  let ref = undefined;
17
28
  let caseSensitive = false;
18
- let ebnf = null;
29
+ let ebnf;
19
30
  if (typeof type === 'string') {
20
31
  defName = type;
21
32
  propsExtended = {};
@@ -1,2 +1,8 @@
1
1
  import type { CssSyntaxTokenizer } from './types.js';
2
+ /**
3
+ * Custom CSS syntax tokenizers for css-tree integration.
4
+ *
5
+ * Provides tokenizer functions for CSS value types that require
6
+ * custom parsing logic beyond what css-tree supports natively.
7
+ */
2
8
  export declare const cssTokenizers: Record<string, CssSyntaxTokenizer>;
@@ -1,4 +1,10 @@
1
1
  import { isBCP47 } from './rfc/is-bcp-47.js';
2
+ /**
3
+ * Custom CSS syntax tokenizers for css-tree integration.
4
+ *
5
+ * Provides tokenizer functions for CSS value types that require
6
+ * custom parsing logic beyond what css-tree supports natively.
7
+ */
2
8
  export const cssTokenizers = {
3
9
  // RFC
4
10
  // https://tools.ietf.org/rfc/bcp/bcp47.html
package/lib/debug.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  import debug from 'debug';
2
+ /**
3
+ * Debug logger for the `@markuplint/types` package.
4
+ */
2
5
  export declare const log: debug.Debugger;
package/lib/debug.js CHANGED
@@ -1,2 +1,5 @@
1
1
  import debug from 'debug';
2
+ /**
3
+ * Debug logger for the `@markuplint/types` package.
4
+ */
2
5
  export const log = debug('@markuplint/types');
package/lib/defs.d.ts CHANGED
@@ -1,2 +1,10 @@
1
1
  import type { Defs } from './types.js';
2
+ /**
3
+ * Built-in type definitions registry for HTML attribute value validation.
4
+ *
5
+ * Maps type identifiers to their validation logic, reference URLs,
6
+ * and expected value descriptions. Includes definitions for common types
7
+ * (Any, Number, URL, etc.), WHATWG-specified types (DateTime, MIMEType,
8
+ * CustomElementName, etc.), and format-specific validators (BCP47, Pattern, etc.).
9
+ */
2
10
  export declare const defs: Defs;
package/lib/defs.js CHANGED
@@ -14,6 +14,14 @@ import { isCustomElementName } from './whatwg/is-custom-element-name.js';
14
14
  import { isItempropName } from './whatwg/is-itemprop-name.js';
15
15
  import { isNavigableTargetName } from './whatwg/is-navigable-target-name.js';
16
16
  import { checkLinkType } from './whatwg/check-link-type.js';
17
+ /**
18
+ * Built-in type definitions registry for HTML attribute value validation.
19
+ *
20
+ * Maps type identifiers to their validation logic, reference URLs,
21
+ * and expected value descriptions. Includes definitions for common types
22
+ * (Any, Number, URL, etc.), WHATWG-specified types (DateTime, MIMEType,
23
+ * CustomElementName, etc.), and format-specific validators (BCP47, Pattern, etc.).
24
+ */
17
25
  export const defs = {
18
26
  Any: {
19
27
  ref: '',
@@ -426,6 +434,8 @@ export const defs = {
426
434
  ref: 'https://html.spec.whatwg.org/multipage/images.html#srcset-attributes',
427
435
  is(value) {
428
436
  const images = value.split(',');
437
+ let hasWidth = false;
438
+ let hasDensity = false;
429
439
  for (const image of images) {
430
440
  // image candidate string
431
441
  const [url, , descriptor, ...tail] = new TokenCollection(image.trim(), {
@@ -456,6 +466,7 @@ export const defs = {
456
466
  ],
457
467
  });
458
468
  }
469
+ hasWidth = true;
459
470
  break;
460
471
  }
461
472
  case 'x': {
@@ -469,6 +480,7 @@ export const defs = {
469
480
  ],
470
481
  });
471
482
  }
483
+ hasDensity = true;
472
484
  break;
473
485
  }
474
486
  default: {
@@ -487,6 +499,10 @@ export const defs = {
487
499
  }
488
500
  }
489
501
  }
502
+ else {
503
+ // No descriptor implies 1x (density descriptor)
504
+ hasDensity = true;
505
+ }
490
506
  if (tail[0]) {
491
507
  return unmatched(value, 'unexpected-token', {
492
508
  expects: [
@@ -498,6 +514,16 @@ export const defs = {
498
514
  });
499
515
  }
500
516
  }
517
+ if (hasWidth && hasDensity) {
518
+ return unmatched(value, 'unexpected-token', {
519
+ expects: [
520
+ {
521
+ type: 'format',
522
+ value: 'consistent descriptors (all width or all density, not mixed)',
523
+ },
524
+ ],
525
+ });
526
+ }
501
527
  return matched();
502
528
  },
503
529
  },
@@ -1,3 +1,17 @@
1
1
  import type { Result, Directive, Defs } from './types.js';
2
2
  import type { ReadonlyDeep } from 'type-fest';
3
+ /**
4
+ * Checks a value against a directive type definition.
5
+ *
6
+ * A directive type consists of a prefix pattern (string or regex) followed by
7
+ * a token value. This function extracts the token portion after the directive
8
+ * prefix and validates it against the token type.
9
+ *
10
+ * @param value - The string value to check
11
+ * @param type - The directive type definition containing directive patterns and token type
12
+ * @param defs - The type definitions registry for resolving nested types
13
+ * @param ref - Optional reference URL for the unmatched result
14
+ * @param cache - Whether to use cached results (defaults to `true`)
15
+ * @returns The validation result
16
+ */
3
17
  export declare function checkDirective(value: string, type: ReadonlyDeep<Directive>, defs: Defs, ref?: string, cache?: boolean): Result;
package/lib/directive.js CHANGED
@@ -1,6 +1,20 @@
1
1
  import { regexParser } from '@markuplint/shared';
2
2
  import { checkBase } from './check-base.js';
3
3
  import { matched, unmatched } from './match-result.js';
4
+ /**
5
+ * Checks a value against a directive type definition.
6
+ *
7
+ * A directive type consists of a prefix pattern (string or regex) followed by
8
+ * a token value. This function extracts the token portion after the directive
9
+ * prefix and validates it against the token type.
10
+ *
11
+ * @param value - The string value to check
12
+ * @param type - The directive type definition containing directive patterns and token type
13
+ * @param defs - The type definitions registry for resolving nested types
14
+ * @param ref - Optional reference URL for the unmatched result
15
+ * @param cache - Whether to use cached results (defaults to `true`)
16
+ * @returns The validation result
17
+ */
4
18
  export function checkDirective(value, type, defs, ref, cache = true) {
5
19
  const unmatches = [];
6
20
  for (const directive of type.directive) {
package/lib/enum.d.ts CHANGED
@@ -1,4 +1,15 @@
1
1
  import type { Result } from './types.js';
2
2
  import type { Enum } from './types.schema.js';
3
3
  import type { ReadonlyDeep } from 'type-fest';
4
+ /**
5
+ * Checks whether a value matches one of the allowed enumeration values.
6
+ *
7
+ * By default, comparison is case-insensitive and surrounding spaces are not allowed.
8
+ * These behaviors can be configured through the type definition.
9
+ *
10
+ * @param value - The string value to check
11
+ * @param type - The enum type definition containing the allowed values and options
12
+ * @param ref - Optional reference URL for the unmatched result
13
+ * @returns The validation result
14
+ */
4
15
  export declare function checkEnum(value: string, type: ReadonlyDeep<Enum>, ref?: string): Result;
package/lib/enum.js CHANGED
@@ -1,4 +1,15 @@
1
1
  import { matched, unmatched } from './match-result.js';
2
+ /**
3
+ * Checks whether a value matches one of the allowed enumeration values.
4
+ *
5
+ * By default, comparison is case-insensitive and surrounding spaces are not allowed.
6
+ * These behaviors can be configured through the type definition.
7
+ *
8
+ * @param value - The string value to check
9
+ * @param type - The enum type definition containing the allowed values and options
10
+ * @param ref - Optional reference URL for the unmatched result
11
+ * @returns The validation result
12
+ */
2
13
  export function checkEnum(value, type, ref) {
3
14
  const disallowToSurroundBySpaces = type.disallowToSurroundBySpaces ?? true;
4
15
  const caseInsensitive = type.caseInsensitive ?? true;
@@ -1,3 +1,14 @@
1
1
  type NullableString = string | null | undefined;
2
+ /**
3
+ * Finds the closest matching candidate string using Levenshtein distance.
4
+ *
5
+ * Compares the input value against a list of candidate strings and returns
6
+ * the one with the highest similarity ratio (at least 50% similar).
7
+ * Returns `undefined` if no close match is found or the value exactly matches a candidate.
8
+ *
9
+ * @param value - The input string to find a candidate for
10
+ * @param candidates - The candidate strings or arrays of strings to compare against
11
+ * @returns The closest matching candidate, or `undefined` if none is close enough
12
+ */
2
13
  export declare function getCandidate(value: NullableString, ...candidates: readonly (NullableString | readonly NullableString[])[]): string | undefined;
3
14
  export {};
@@ -1,5 +1,16 @@
1
1
  import leven from 'leven';
2
2
  const FLAT_DEPTH = 2;
3
+ /**
4
+ * Finds the closest matching candidate string using Levenshtein distance.
5
+ *
6
+ * Compares the input value against a list of candidate strings and returns
7
+ * the one with the highest similarity ratio (at least 50% similar).
8
+ * Returns `undefined` if no close match is found or the value exactly matches a candidate.
9
+ *
10
+ * @param value - The input string to find a candidate for
11
+ * @param candidates - The candidate strings or arrays of strings to compare against
12
+ * @returns The closest matching candidate, or `undefined` if none is close enough
13
+ */
3
14
  export function getCandidate(value, ...candidates) {
4
15
  if (!value) {
5
16
  return;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,13 @@
1
+ /**
2
+ * @module @markuplint/types
3
+ *
4
+ * Provides type checking utilities for HTML attribute values,
5
+ * CSS syntax validation, and custom type definitions used by markuplint rules.
6
+ */
1
7
  export * from './whatwg/is-custom-element-name.js';
8
+ export * from './whatwg/check-link-type.js';
2
9
  export * from './check.js';
3
10
  export * from './check-base.js';
4
- export * from './types.js';
11
+ export { getCandidate } from './get-candidate.js';
12
+ export { checkPattern } from './pattern.js';
13
+ export type * from './types.js';
package/lib/index.js CHANGED
@@ -1,4 +1,12 @@
1
+ /**
2
+ * @module @markuplint/types
3
+ *
4
+ * Provides type checking utilities for HTML attribute values,
5
+ * CSS syntax validation, and custom type definitions used by markuplint rules.
6
+ */
1
7
  export * from './whatwg/is-custom-element-name.js';
8
+ export * from './whatwg/check-link-type.js';
2
9
  export * from './check.js';
3
10
  export * from './check-base.js';
4
- export * from './types.js';
11
+ export { getCandidate } from './get-candidate.js';
12
+ export { checkPattern } from './pattern.js';
@@ -1,3 +1,16 @@
1
1
  import type { Defs, Result } from './types.js';
2
2
  import type { KeywordDefinedType } from './types.schema.js';
3
+ /**
4
+ * Checks a value against a keyword-defined type or CSS syntax type.
5
+ *
6
+ * Looks up the type in the definitions registry and validates the value.
7
+ * If the type is not found in custom definitions, falls back to CSS syntax matching.
8
+ * Results are cached by default for performance.
9
+ *
10
+ * @param value - The string value to check
11
+ * @param type - The keyword type identifier to look up
12
+ * @param defs - The type definitions registry
13
+ * @param cache - Whether to use cached results (defaults to `true`)
14
+ * @returns The validation result
15
+ */
3
16
  export declare function checkKeywordType(value: string, type: KeywordDefinedType, defs: Defs, cache?: boolean): Result;
@@ -4,6 +4,19 @@ import { log } from './debug.js';
4
4
  import { matched } from './match-result.js';
5
5
  const resultCache = new Map();
6
6
  const CACHE_KEY_PREFIX = '@markuplint/types/checkKeywordType/cache:::';
7
+ /**
8
+ * Checks a value against a keyword-defined type or CSS syntax type.
9
+ *
10
+ * Looks up the type in the definitions registry and validates the value.
11
+ * If the type is not found in custom definitions, falls back to CSS syntax matching.
12
+ * Results are cached by default for performance.
13
+ *
14
+ * @param value - The string value to check
15
+ * @param type - The keyword type identifier to look up
16
+ * @param defs - The type definitions registry
17
+ * @param cache - Whether to use cached results (defaults to `true`)
18
+ * @returns The validation result
19
+ */
7
20
  export function checkKeywordType(value, type, defs, cache = true) {
8
21
  const key = `${CACHE_KEY_PREFIX}${value}${type}`;
9
22
  if (cache) {
package/lib/list.d.ts CHANGED
@@ -1,4 +1,17 @@
1
1
  import type { Defs, Result } from './types.js';
2
2
  import type { List } from './types.schema.js';
3
3
  import type { ReadonlyDeep } from 'type-fest';
4
+ /**
5
+ * Checks a value as a separated list of tokens against a type definition.
6
+ *
7
+ * Parses the value into tokens based on the list separator configuration,
8
+ * then validates each individual token against the list's token type.
9
+ *
10
+ * @param value - The string value to check as a list
11
+ * @param type - The list type definition containing separator and token type
12
+ * @param defs - The type definitions registry for resolving nested types
13
+ * @param ref - Optional reference URL for the unmatched result
14
+ * @param cache - Whether to use cached results (defaults to `true`)
15
+ * @returns The validation result
16
+ */
4
17
  export declare function checkList(value: string, type: ReadonlyDeep<List>, defs: Defs, ref?: string, cache?: boolean): Result;
package/lib/list.js CHANGED
@@ -1,6 +1,19 @@
1
1
  import { checkBase } from './check-base.js';
2
2
  import { matched } from './match-result.js';
3
3
  import { Token, TokenCollection } from './token/index.js';
4
+ /**
5
+ * Checks a value as a separated list of tokens against a type definition.
6
+ *
7
+ * Parses the value into tokens based on the list separator configuration,
8
+ * then validates each individual token against the list's token type.
9
+ *
10
+ * @param value - The string value to check as a list
11
+ * @param type - The list type definition containing separator and token type
12
+ * @param defs - The type definitions registry for resolving nested types
13
+ * @param ref - Optional reference URL for the unmatched result
14
+ * @param cache - Whether to use cached results (defaults to `true`)
15
+ * @returns The validation result
16
+ */
4
17
  export function checkList(value, type, defs, ref, cache = true) {
5
18
  const tokens = new TokenCollection(value, type);
6
19
  const matches = tokens.check({ ref });
@@ -1,9 +1,30 @@
1
1
  import type { FormattedPrimitiveTypeCheck, MatchedResult, UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from './types.js';
2
+ /**
3
+ * Creates a value checker function that wraps a primitive type check
4
+ * and returns a matched or unmatched result.
5
+ *
6
+ * @param checker - The primitive type check function to wrap
7
+ * @param options - Optional settings for the unmatched result including ref and reason
8
+ * @returns A function that takes a string value and returns a match result
9
+ */
2
10
  export declare function matches(checker: FormattedPrimitiveTypeCheck, options?: UnmatchedResultOptions & {
3
11
  readonly ref?: string;
4
12
  readonly reason?: UnmatchedResultReason;
5
- }): (value: string) => UnmatchedResult | MatchedResult;
13
+ }): (value: string) => MatchedResult | UnmatchedResult;
14
+ /**
15
+ * Creates a successful match result.
16
+ *
17
+ * @returns A matched result object
18
+ */
6
19
  export declare function matched(): MatchedResult;
20
+ /**
21
+ * Creates a failed match result with location and reason information.
22
+ *
23
+ * @param value - The raw string value that failed to match
24
+ * @param reason - The reason for the mismatch
25
+ * @param options - Optional settings including ref URL and expected values
26
+ * @returns An unmatched result object with position details
27
+ */
7
28
  export declare function unmatched(value: string, reason?: UnmatchedResultReason, options?: UnmatchedResultOptions & {
8
29
  readonly ref?: string;
9
30
  }): UnmatchedResult;