@markuplint/types 4.8.1 → 4.8.2

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 (112) hide show
  1. package/ARCHITECTURE.ja.md +252 -0
  2. package/ARCHITECTURE.md +252 -0
  3. package/CHANGELOG.md +3 -3
  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 +514 -0
  13. package/docs/validators.md +514 -0
  14. package/lib/check-base.d.ts +71 -0
  15. package/lib/check-base.js +71 -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 +8 -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 +6 -0
  39. package/lib/index.js +6 -0
  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/primitive/is-float.d.ts +4 -1
  49. package/lib/primitive/is-float.js +4 -1
  50. package/lib/primitive/is-int.d.ts +4 -1
  51. package/lib/primitive/is-int.js +4 -1
  52. package/lib/primitive/is-non-zero-uint.d.ts +3 -2
  53. package/lib/primitive/is-non-zero-uint.js +3 -2
  54. package/lib/primitive/is-quantity.d.ts +5 -3
  55. package/lib/primitive/is-quantity.js +5 -3
  56. package/lib/primitive/is-uint.d.ts +5 -1
  57. package/lib/primitive/is-uint.js +5 -1
  58. package/lib/primitive/range.d.ts +5 -4
  59. package/lib/primitive/range.js +5 -4
  60. package/lib/primitive/split-unit.d.ts +3 -2
  61. package/lib/primitive/split-unit.js +3 -2
  62. package/lib/rfc/is-bcp-47.d.ts +2 -0
  63. package/lib/rfc/is-bcp-47.js +2 -0
  64. package/lib/token/token-collection.d.ts +107 -2
  65. package/lib/token/token-collection.js +103 -3
  66. package/lib/token/token.d.ts +66 -2
  67. package/lib/token/token.js +66 -2
  68. package/lib/token/types.d.ts +9 -0
  69. package/lib/types.d.ts +107 -0
  70. package/lib/w3c/check-serialized-permissions-policy.d.ts +2 -0
  71. package/lib/w3c/check-serialized-permissions-policy.js +2 -0
  72. package/lib/whatwg/check-autocomplete.d.ts +5 -0
  73. package/lib/whatwg/check-autocomplete.js +6 -0
  74. package/lib/whatwg/check-datetime/date-string.d.ts +2 -0
  75. package/lib/whatwg/check-datetime/date-string.js +2 -0
  76. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +13 -0
  77. package/lib/whatwg/check-datetime/datetime-tokens.js +13 -0
  78. package/lib/whatwg/check-datetime/duration-string.d.ts +7 -0
  79. package/lib/whatwg/check-datetime/duration-string.js +7 -0
  80. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +2 -0
  81. package/lib/whatwg/check-datetime/global-date-and-time-string.js +2 -0
  82. package/lib/whatwg/check-datetime/index.d.ts +5 -0
  83. package/lib/whatwg/check-datetime/index.js +5 -0
  84. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +4 -0
  85. package/lib/whatwg/check-datetime/local-date-and-time-string.js +4 -0
  86. package/lib/whatwg/check-datetime/month-string.d.ts +2 -0
  87. package/lib/whatwg/check-datetime/month-string.js +2 -0
  88. package/lib/whatwg/check-datetime/time-string.d.ts +2 -0
  89. package/lib/whatwg/check-datetime/time-string.js +2 -0
  90. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +8 -0
  91. package/lib/whatwg/check-datetime/time-zone-offset-string.js +8 -0
  92. package/lib/whatwg/check-datetime/week-string.d.ts +2 -0
  93. package/lib/whatwg/check-datetime/week-string.js +2 -0
  94. package/lib/whatwg/check-datetime/year-string.d.ts +2 -0
  95. package/lib/whatwg/check-datetime/year-string.js +2 -0
  96. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +2 -0
  97. package/lib/whatwg/check-datetime/yearless-date-string.js +2 -0
  98. package/lib/whatwg/check-link-type.d.ts +5 -1
  99. package/lib/whatwg/check-link-type.js +5 -1
  100. package/lib/whatwg/check-mime-type.d.ts +4 -1
  101. package/lib/whatwg/check-mime-type.js +4 -1
  102. package/lib/whatwg/is-abs-url.d.ts +2 -0
  103. package/lib/whatwg/is-abs-url.js +2 -0
  104. package/lib/whatwg/is-browser-context-name.d.ts +2 -2
  105. package/lib/whatwg/is-browser-context-name.js +2 -2
  106. package/lib/whatwg/is-custom-element-name.d.ts +1 -1
  107. package/lib/whatwg/is-custom-element-name.js +1 -1
  108. package/lib/whatwg/is-itemprop-name.d.ts +1 -0
  109. package/lib/whatwg/is-itemprop-name.js +1 -0
  110. package/lib/whatwg/is-navigable-target-name.d.ts +2 -0
  111. package/lib/whatwg/is-navigable-target-name.js +2 -0
  112. package/package.json +3 -3
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Represents a single token within a parsed string value.
3
+ *
4
+ * Tracks the token's value, type (whitespace, comma, or identifier),
5
+ * offset position within the original string, and provides methods
6
+ * for matching and comparison operations.
7
+ */
1
8
  export class Token {
2
9
  /**
3
10
  * @deprecated Use {@link getPosition} instead. Will be removed in v5.0.0.
@@ -12,12 +19,26 @@ export class Token {
12
19
  static getLine(value, offset) {
13
20
  return value.slice(0, offset).split(/\n/).length;
14
21
  }
22
+ /**
23
+ * Calculates the line and column position at the given offset within a string.
24
+ *
25
+ * @param value - The source string
26
+ * @param offset - The character offset to calculate the position for
27
+ * @returns The line number (1-based) and column number (1-based)
28
+ */
15
29
  static getPosition(value, offset) {
16
30
  const lines = value.slice(0, offset).split(/\n/);
17
31
  const line = lines.length;
18
32
  const column = (lines.at(-1) ?? '').length + 1;
19
33
  return { line, column };
20
34
  }
35
+ /**
36
+ * Determines the token type based on the first character.
37
+ *
38
+ * @param value - The token string value
39
+ * @param separators - Optional separator characters to detect
40
+ * @returns The token type number (WhiteSpace, Comma, or Ident)
41
+ */
21
42
  static getType(value, separators) {
22
43
  if (Token.whitespace.includes(value[0] ?? '')) {
23
44
  return Token.WhiteSpace;
@@ -31,6 +52,13 @@ export class Token {
31
52
  }
32
53
  return Token.Ident;
33
54
  }
55
+ /**
56
+ * Calculates a new position by shifting from a token's offset.
57
+ *
58
+ * @param token - The base token to shift from
59
+ * @param offset - The additional offset to apply
60
+ * @returns The shifted offset, line, and column
61
+ */
34
62
  static shiftLocation(token, offset) {
35
63
  const shifted = token.offset + offset;
36
64
  const { line, column } = Token.getPosition(token.originalValue, shifted);
@@ -40,21 +68,38 @@ export class Token {
40
68
  column,
41
69
  };
42
70
  }
71
+ /**
72
+ * @param value - The token string value
73
+ * @param offset - The offset position within the original string
74
+ * @param originalValue - The complete original string this token was parsed from
75
+ * @param separators - Optional separator characters used for type detection
76
+ */
43
77
  constructor(value, offset, originalValue, separators) {
44
78
  this.type = Token.getType(value, separators);
45
79
  this.value = value;
46
80
  this.offset = offset;
47
81
  this.originalValue = originalValue;
48
82
  }
83
+ /**
84
+ * The character length of the token value.
85
+ */
49
86
  get length() {
50
87
  return this.value.length;
51
88
  }
89
+ /**
90
+ * Creates a copy of this token.
91
+ *
92
+ * @returns A new Token instance with the same value, offset, and original value
93
+ */
52
94
  clone() {
53
95
  return new Token(this.value, this.offset, this.originalValue);
54
96
  }
55
97
  /**
98
+ * Checks whether this token's value contains the given value.
56
99
  *
57
- * @param value The token value or the token type or its list
100
+ * @param value - The token value, type number, regex, or array to check against
101
+ * @param caseInsensitive - Whether to perform case-insensitive comparison
102
+ * @returns Whether this token includes the given value
58
103
  */
59
104
  includes(value, caseInsensitive) {
60
105
  if (Array.isArray(value)) {
@@ -72,8 +117,11 @@ export class Token {
72
117
  return this.type === value;
73
118
  }
74
119
  /**
120
+ * Checks whether this token exactly matches the given value.
75
121
  *
76
- * @param value The token value or the token type or its list
122
+ * @param value - The token value, type number, regex, or array to match against
123
+ * @param caseInsensitive - Whether to perform case-insensitive comparison
124
+ * @returns Whether this token matches the given value
77
125
  */
78
126
  matches(value, caseInsensitive) {
79
127
  if (Array.isArray(value)) {
@@ -90,6 +138,11 @@ export class Token {
90
138
  }
91
139
  return this.type === value;
92
140
  }
141
+ /**
142
+ * Converts this token to a plain JSON-serializable object.
143
+ *
144
+ * @returns An object with type, value, and offset properties
145
+ */
93
146
  toJSON() {
94
147
  return {
95
148
  type: this.type,
@@ -97,10 +150,21 @@ export class Token {
97
150
  offset: this.offset,
98
151
  };
99
152
  }
153
+ /**
154
+ * Parses the token value as a floating-point number.
155
+ *
156
+ * @returns The parsed number, or 0 if parsing fails
157
+ */
100
158
  toNumber() {
101
159
  const num = Number.parseFloat(this.value);
102
160
  return Number.isNaN(num) ? 0 : num;
103
161
  }
162
+ /**
163
+ * Creates an unmatched result positioned at this token's location.
164
+ *
165
+ * @param options - Optional settings including ref, reason, and expected values
166
+ * @returns An unmatched result with this token's position information
167
+ */
104
168
  unmatched(options) {
105
169
  const { line, column } = Token.getPosition(this.originalValue, this.offset);
106
170
  return {
@@ -1,3 +1,12 @@
1
+ /**
2
+ * A single token value: a literal string, a regular expression pattern, or a token type number.
3
+ */
1
4
  export type TokenValueScalar = string | Readonly<RegExp> | number;
5
+ /**
6
+ * An array of token values for matching against multiple patterns.
7
+ */
2
8
  export type TokenValueArray = readonly TokenValue[];
9
+ /**
10
+ * A token value used for matching: either a scalar or an array of token values.
11
+ */
3
12
  export type TokenValue = TokenValueScalar | TokenValueArray;
package/lib/types.d.ts CHANGED
@@ -1,6 +1,26 @@
1
1
  import type { cssSyntaxMatch } from './css-syntax.js';
2
+ /**
3
+ * Re-exported types from the auto-generated schema definitions.
4
+ *
5
+ * - `Type` - Union of all possible type definitions (keyword, list, enum, number, directive)
6
+ * - `List` - Defines space-separated or comma-separated token sequences
7
+ * - `Enum` - Defines a fixed set of allowed string values
8
+ * - `CssSyntax` - String literal union of all recognized CSS value definition syntax names
9
+ * - `KeywordDefinedType` - Union of CSS syntax, extended types, and HTML attribute requirements
10
+ * - `Number` - Defines numeric validation with optional range constraints
11
+ * - `Directive` - Defines composite attribute values with separators and individual token validation
12
+ */
2
13
  export type { Type, List, Enum, CssSyntax, KeywordDefinedType, Number, Directive } from './types.schema.js';
14
+ /**
15
+ * The outcome of a type validation check. Either a successful match
16
+ * or a detailed mismatch containing error location and reason.
17
+ */
3
18
  export type Result = UnmatchedResult | MatchedResult;
19
+ /**
20
+ * Represents a failed type validation result. Contains detailed information
21
+ * about what went wrong, including the position within the input string
22
+ * where the mismatch occurred and the specific reason for the failure.
23
+ */
4
24
  export type UnmatchedResult = {
5
25
  readonly matched: false;
6
26
  readonly ref: string | null;
@@ -12,6 +32,11 @@ export type UnmatchedResult = {
12
32
  readonly reason: UnmatchedResultReason;
13
33
  readonly passCount?: number;
14
34
  } & UnmatchedResultOptions;
35
+ /**
36
+ * Optional metadata attached to an unmatched result, providing additional
37
+ * context such as the part of the value that failed, what was expected,
38
+ * and potential corrections or fallbacks.
39
+ */
15
40
  export type UnmatchedResultOptions = {
16
41
  readonly partName?: string;
17
42
  readonly expects?: readonly Expect[];
@@ -19,6 +44,12 @@ export type UnmatchedResultOptions = {
19
44
  readonly candidate?: string;
20
45
  readonly fallbackTo?: string;
21
46
  };
47
+ /**
48
+ * Describes the specific reason a type validation failed. Can be a simple
49
+ * string identifier for common failure modes (e.g., `'syntax-error'`,
50
+ * `'typo'`, `'out-of-range'`) or a structured object for range violations
51
+ * that includes the boundary values.
52
+ */
22
53
  export type UnmatchedResultReason = 'syntax-error' | 'typo' | 'missing-token' | 'missing-comma' | 'unexpected-token' | 'unexpected-space' | 'unexpected-newline' | 'unexpected-comma' | 'empty-token' | 'out-of-range' | 'doesnt-exist-in-enum' | 'duplicated' | 'illegal-combination' | 'illegal-order' | 'extra-token' | 'must-be-percent-encoded' | 'must-be-serialized' | {
23
54
  readonly type: 'out-of-range';
24
55
  readonly gt?: number;
@@ -34,23 +65,76 @@ export type UnmatchedResultReason = 'syntax-error' | 'typo' | 'missing-token' |
34
65
  readonly gte: number;
35
66
  readonly lte?: number;
36
67
  };
68
+ /**
69
+ * Represents a successful type validation result, indicating that the
70
+ * checked value conforms to the specified type definition.
71
+ */
37
72
  export type MatchedResult = {
38
73
  readonly matched: true;
39
74
  };
75
+ /**
76
+ * Describes an expected value or format that the input should conform to.
77
+ * Used in error reporting to communicate what the validator anticipated.
78
+ */
40
79
  export type Expect = {
41
80
  readonly type: 'const' | 'format' | 'syntax' | 'regexp' | 'common';
42
81
  readonly value: string;
43
82
  };
83
+ /**
84
+ * A predicate function that checks whether a string value conforms
85
+ * to a specific primitive type format (e.g., a valid custom element name).
86
+ *
87
+ * @param value - The string value to check
88
+ * @returns True if the value is valid for the primitive type
89
+ */
44
90
  export type FormattedPrimitiveTypeCheck = (value: string) => boolean;
91
+ /**
92
+ * A factory function that creates a {@link FormattedPrimitiveTypeCheck} predicate,
93
+ * optionally configured with the given options.
94
+ *
95
+ * @template O - The type of the optional configuration object passed to the factory
96
+ * @param options - Optional configuration for the created checker
97
+ * @returns A predicate function that validates strings against the primitive type
98
+ */
45
99
  export type FormattedPrimitiveTypeCreator<O = never> = (options?: O) => FormattedPrimitiveTypeCheck;
100
+ /**
101
+ * A read-only map of type definition names to their corresponding custom
102
+ * syntax or CSS syntax definitions. Used by the type checker to resolve
103
+ * keyword types during validation.
104
+ */
46
105
  export type Defs = Readonly<Record<string, CustomCssSyntax | CustomSyntax>>;
106
+ /**
107
+ * Defines a custom type using a programmatic checker function.
108
+ * Unlike CSS syntax definitions, custom syntax types use an imperative
109
+ * `is` function to validate values.
110
+ */
47
111
  export type CustomSyntax = {
48
112
  readonly ref: string;
49
113
  readonly expects?: readonly Expect[];
50
114
  readonly is: CustomSyntaxCheck;
51
115
  };
116
+ /**
117
+ * A function that validates a string value against a custom syntax rule
118
+ * and returns a detailed result indicating match or mismatch.
119
+ *
120
+ * @param value - The string value to validate
121
+ * @returns A result indicating whether the value matches the custom syntax
122
+ */
52
123
  export type CustomSyntaxCheck = (value: string) => Result;
124
+ /**
125
+ * A factory function that creates a {@link CustomSyntaxCheck} validator,
126
+ * optionally configured with the given options.
127
+ *
128
+ * @template O - The type of the optional configuration object passed to the factory
129
+ * @param options - Optional configuration for the created checker
130
+ * @returns A function that validates strings against the custom syntax
131
+ */
53
132
  export type CustomSyntaxChecker<O = {}> = (options?: O) => CustomSyntaxCheck;
133
+ /**
134
+ * Defines a custom type using CSS value definition syntax for matching.
135
+ * The `syntax` property specifies the CSS grammar to apply, along with
136
+ * any supplementary definitions needed for parsing.
137
+ */
54
138
  export type CustomCssSyntax = {
55
139
  readonly ref: string;
56
140
  readonly caseSensitive?: boolean;
@@ -68,6 +152,11 @@ export type CustomCssSyntax = {
68
152
  readonly properties?: Readonly<Record<string, string>>;
69
153
  };
70
154
  };
155
+ /**
156
+ * Represents a single token produced by the CSS syntax tokenizer.
157
+ * Each token captures its type, raw string value, position within
158
+ * the input, and a balance index for matching paired delimiters.
159
+ */
71
160
  export type CSSSyntaxToken = {
72
161
  readonly type: number;
73
162
  readonly value: string;
@@ -75,5 +164,23 @@ export type CSSSyntaxToken = {
75
164
  readonly balance: number;
76
165
  readonly node?: any;
77
166
  };
167
+ /**
168
+ * A custom tokenizer function used within CSS syntax definitions to
169
+ * perform token-level matching. It receives the current token, a
170
+ * function to peek ahead in the token stream, and the CSS syntax
171
+ * match utility.
172
+ *
173
+ * @param token - The current CSS syntax token to inspect, or null if at end of input
174
+ * @param getNextToken - A lookahead function that retrieves a token at the given offset
175
+ * @param match - The CSS syntax matching function for recursive grammar matching
176
+ * @returns The number of tokens consumed by this tokenizer (0 if no match)
177
+ */
78
178
  export type CssSyntaxTokenizer = (token: Readonly<CSSSyntaxToken> | null, getNextToken: GetNextToken, match: typeof cssSyntaxMatch) => number;
179
+ /**
180
+ * A lookahead function that retrieves a CSS syntax token at a given
181
+ * offset from the current position in the token stream.
182
+ *
183
+ * @param length - The offset (number of tokens ahead) to look up
184
+ * @returns The token at the given offset, or null if beyond the end of the token stream
185
+ */
79
186
  export type GetNextToken = (length: number) => CSSSyntaxToken | null;
@@ -1,5 +1,7 @@
1
1
  import type { CustomSyntaxChecker } from '../types.js';
2
2
  /**
3
+ * Validates a serialized permissions policy string according to the W3C specification.
4
+ *
3
5
  * @see https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy
4
6
  *
5
7
  * > Policy Directives in HTML attributes are represented as their
@@ -2,6 +2,8 @@ import { log } from '../debug.js';
2
2
  import { matched, unmatched } from '../match-result.js';
3
3
  import { TokenCollection } from '../token/index.js';
4
4
  /**
5
+ * Validates a serialized permissions policy string according to the W3C specification.
6
+ *
5
7
  * @see https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy
6
8
  *
7
9
  * > Policy Directives in HTML attributes are represented as their
@@ -1,5 +1,10 @@
1
1
  import type { CustomSyntaxChecker } from '../types.js';
2
2
  /**
3
+ * Validates the `autocomplete` attribute value according to the WHATWG specification.
4
+ *
5
+ * Supports "on"/"off" keywords, optional named groups (`section-*`),
6
+ * address parts (shipping/billing), contacting tokens, and autofill field names.
7
+ *
3
8
  * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete
4
9
  */
5
10
  export declare const checkAutoComplete: CustomSyntaxChecker;
@@ -90,6 +90,11 @@ const URL_PART_OF_ADDRESS = 'https://html.spec.whatwg.org/multipage/form-control
90
90
  const URL_AUTOFILL_FIELD = 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field';
91
91
  const URL_CONTACTABLE_FIELD = 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-tel';
92
92
  /**
93
+ * Validates the `autocomplete` attribute value according to the WHATWG specification.
94
+ *
95
+ * Supports "on"/"off" keywords, optional named groups (`section-*`),
96
+ * address parts (shipping/billing), contacting tokens, and autofill field names.
97
+ *
93
98
  * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete
94
99
  */
95
100
  export const checkAutoComplete = () => value => {
@@ -195,6 +200,7 @@ export const checkAutoComplete = () => value => {
195
200
  }
196
201
  }
197
202
  if (head.matches(contactingTokens, true)) {
203
+ // eslint-disable-next-line no-useless-assignment
198
204
  hasContactingToken = true;
199
205
  const contactableFiledToken = tail[0];
200
206
  if (!contactableFiledToken) {
@@ -1,5 +1,7 @@
1
1
  import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
+ * Validates a date string in the format `YYYY-MM-DD`.
4
+ *
3
5
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates
4
6
  */
5
7
  export declare const checkDateString: CustomSyntaxChecker;
@@ -2,6 +2,8 @@ import { log } from '../../debug.js';
2
2
  import { TokenCollection } from '../../token/index.js';
3
3
  import { datetimeTokenCheck } from './datetime-tokens.js';
4
4
  /**
5
+ * Validates a date string in the format `YYYY-MM-DD`.
6
+ *
5
7
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates
6
8
  */
7
9
  export const checkDateString = () => function checkDateString(value) {
@@ -1,3 +1,16 @@
1
1
  import type { TokenEachCheck } from '../../token/token-collection.js';
2
+ /**
3
+ * Collection of token check functions for datetime component validation.
4
+ *
5
+ * Each property is a {@link TokenEachCheck} function that validates a specific
6
+ * datetime component (year, month, date, hour, minute, second, etc.)
7
+ * according to the WHATWG specification.
8
+ */
2
9
  export declare const datetimeTokenCheck: Record<'year' | 'month' | 'date' | 'hour' | 'minute' | 'second' | 'secondFractionalPart' | 'week' | 'hyphen' | 'colon' | 'extra' | 'colonOrEnd' | 'decimalPointOrEnd' | 'localDateTimeSeparator' | 'normalizedlocalDateTimeSeparator' | 'plusOrMinusSign' | 'weekSign', TokenEachCheck> & Record<'_year' | '_month', number | null>;
10
+ /**
11
+ * Calculates the maximum ISO week number for a given year.
12
+ *
13
+ * @param year - The year to calculate for
14
+ * @returns The maximum week number (52 or 53) for the year
15
+ */
3
16
  export declare function getMaxWeekNum(year: number): number;
@@ -1,5 +1,12 @@
1
1
  import { log } from '../../debug.js';
2
2
  import { matched, unmatched } from '../../match-result.js';
3
+ /**
4
+ * Collection of token check functions for datetime component validation.
5
+ *
6
+ * Each property is a {@link TokenEachCheck} function that validates a specific
7
+ * datetime component (year, month, date, hour, minute, second, etc.)
8
+ * according to the WHATWG specification.
9
+ */
3
10
  export const datetimeTokenCheck = {
4
11
  /**
5
12
  * Temporary year state
@@ -489,6 +496,12 @@ const daysOfMonth = [
489
496
  // 12
490
497
  31,
491
498
  ];
499
+ /**
500
+ * Calculates the maximum ISO week number for a given year.
501
+ *
502
+ * @param year - The year to calculate for
503
+ * @returns The maximum week number (52 or 53) for the year
504
+ */
492
505
  export function getMaxWeekNum(year) {
493
506
  let date = 31;
494
507
  while (date > 0) {
@@ -1,6 +1,13 @@
1
1
  import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
+ * Validates a duration string in ISO 8601-like format (e.g., `PT1H30M`).
4
+ *
3
5
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#durations
4
6
  */
5
7
  export declare const checkDurationISO8601LikeString: CustomSyntaxChecker;
8
+ /**
9
+ * Validates a duration string in component list format (e.g., `1h 30m 5s`).
10
+ *
11
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#durations
12
+ */
6
13
  export declare const checkDurationComponentListString: CustomSyntaxChecker;
@@ -3,6 +3,8 @@ import { matched, unmatched } from '../../match-result.js';
3
3
  import { TokenCollection } from '../../token/index.js';
4
4
  import { datetimeTokenCheck } from './datetime-tokens.js';
5
5
  /**
6
+ * Validates a duration string in ISO 8601-like format (e.g., `PT1H30M`).
7
+ *
6
8
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#durations
7
9
  */
8
10
  export const checkDurationISO8601LikeString = () => function checkDurationISO8601LikeString(value) {
@@ -201,6 +203,11 @@ export const checkDurationISO8601LikeString = () => function checkDurationISO860
201
203
  }
202
204
  return res;
203
205
  };
206
+ /**
207
+ * Validates a duration string in component list format (e.g., `1h 30m 5s`).
208
+ *
209
+ * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#durations
210
+ */
204
211
  export const checkDurationComponentListString = () => function checkDurationComponentListString(value) {
205
212
  log('CHECK: duration-string (duration component list)');
206
213
  if (!value) {
@@ -1,5 +1,7 @@
1
1
  import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
+ * Validates a global date and time string (date + time + time-zone offset).
4
+ *
3
5
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#global-dates-and-times
4
6
  */
5
7
  export declare const checkGlobalDateAndTimeString: CustomSyntaxChecker;
@@ -4,6 +4,8 @@ import { TokenCollection } from '../../token/index.js';
4
4
  import { datetimeTokenCheck } from './datetime-tokens.js';
5
5
  import { parseTimeZone } from './time-zone-offset-string.js';
6
6
  /**
7
+ * Validates a global date and time string (date + time + time-zone offset).
8
+ *
7
9
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#global-dates-and-times
8
10
  */
9
11
  export const checkGlobalDateAndTimeString = () => function checkGlobalDateAndTimeString(value) {
@@ -1,5 +1,10 @@
1
1
  import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
+ * Validates a datetime string against all WHATWG date and time formats.
4
+ *
5
+ * Tries each format (date, time, month, yearless date, local/global date-time,
6
+ * time-zone offset, week, year, and duration strings) and returns the best match.
7
+ *
3
8
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates-and-times
4
9
  */
5
10
  export declare const checkDateTime: CustomSyntaxChecker;
@@ -24,6 +24,11 @@ const checks = [
24
24
  checkDurationComponentListString(),
25
25
  ];
26
26
  /**
27
+ * Validates a datetime string against all WHATWG date and time formats.
28
+ *
29
+ * Tries each format (date, time, month, yearless date, local/global date-time,
30
+ * time-zone offset, week, year, and duration strings) and returns the best match.
31
+ *
27
32
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates-and-times
28
33
  */
29
34
  export const checkDateTime = () => value => {
@@ -1,9 +1,13 @@
1
1
  import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
+ * Validates a local date and time string (date + `T` or space + time, no time-zone).
4
+ *
3
5
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string
4
6
  */
5
7
  export declare const checkLocalDateAndTimeString: CustomSyntaxChecker;
6
8
  /**
9
+ * Validates a normalized local date and time string (uses `T` separator only, omits zero seconds).
10
+ *
7
11
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-normalised-local-date-and-time-string
8
12
  */
9
13
  export declare const checkNormalizedLocalDateAndTimeString: CustomSyntaxChecker;
@@ -2,6 +2,8 @@ import { log } from '../../debug.js';
2
2
  import { TokenCollection } from '../../token/index.js';
3
3
  import { datetimeTokenCheck } from './datetime-tokens.js';
4
4
  /**
5
+ * Validates a local date and time string (date + `T` or space + time, no time-zone).
6
+ *
5
7
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string
6
8
  */
7
9
  export const checkLocalDateAndTimeString = () => function checkLocalDateAndTimeString(value) {
@@ -42,6 +44,8 @@ export const checkLocalDateAndTimeString = () => function checkLocalDateAndTimeS
42
44
  return res;
43
45
  };
44
46
  /**
47
+ * Validates a normalized local date and time string (uses `T` separator only, omits zero seconds).
48
+ *
45
49
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-normalised-local-date-and-time-string
46
50
  */
47
51
  export const checkNormalizedLocalDateAndTimeString = () => function checkNormalizedLocalDateAndTimeString(value) {
@@ -1,5 +1,7 @@
1
1
  import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
+ * Validates a month string in the format `YYYY-MM`.
4
+ *
3
5
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-month-string
4
6
  */
5
7
  export declare const checkMonthString: CustomSyntaxChecker;
@@ -2,6 +2,8 @@ import { log } from '../../debug.js';
2
2
  import { TokenCollection } from '../../token/index.js';
3
3
  import { datetimeTokenCheck } from './datetime-tokens.js';
4
4
  /**
5
+ * Validates a month string in the format `YYYY-MM`.
6
+ *
5
7
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-month-string
6
8
  */
7
9
  export const checkMonthString = () => function checkMonthString(value) {
@@ -1,5 +1,7 @@
1
1
  import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
+ * Validates a time string in the format `HH:MM[:SS[.sss]]`.
4
+ *
3
5
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#times
4
6
  */
5
7
  export declare const checkTimeString: CustomSyntaxChecker;
@@ -2,6 +2,8 @@ import { log } from '../../debug.js';
2
2
  import { TokenCollection } from '../../token/index.js';
3
3
  import { datetimeTokenCheck } from './datetime-tokens.js';
4
4
  /**
5
+ * Validates a time string in the format `HH:MM[:SS[.sss]]`.
6
+ *
5
7
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#times
6
8
  */
7
9
  export const checkTimeString = () => function checkTimeString(value) {
@@ -1,7 +1,15 @@
1
1
  import type { Token } from '../../token/index.js';
2
2
  import type { CustomSyntaxChecker } from '../../types.js';
3
3
  /**
4
+ * Validates a time-zone offset string (`Z`, `+HH:MM`, or `-HH:MM`).
5
+ *
4
6
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#time-zones
5
7
  */
6
8
  export declare const checkTimeZoneOffsetString: CustomSyntaxChecker;
9
+ /**
10
+ * Parses and validates a time-zone offset string (e.g., `Z`, `+09:00`, `-05:30`).
11
+ *
12
+ * @param zone - The time-zone string or token to validate
13
+ * @returns The validation result
14
+ */
7
15
  export declare function parseTimeZone(zone: string | Readonly<Token>): import("../../types.js").Result;
@@ -3,12 +3,20 @@ import { matched, unmatched } from '../../match-result.js';
3
3
  import { TokenCollection } from '../../token/index.js';
4
4
  import { datetimeTokenCheck } from './datetime-tokens.js';
5
5
  /**
6
+ * Validates a time-zone offset string (`Z`, `+HH:MM`, or `-HH:MM`).
7
+ *
6
8
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#time-zones
7
9
  */
8
10
  export const checkTimeZoneOffsetString = () => function checkTimeZoneOffsetString(value) {
9
11
  log('CHECK: time-zone-offset-string');
10
12
  return parseTimeZone(value);
11
13
  };
14
+ /**
15
+ * Parses and validates a time-zone offset string (e.g., `Z`, `+09:00`, `-05:30`).
16
+ *
17
+ * @param zone - The time-zone string or token to validate
18
+ * @returns The validation result
19
+ */
12
20
  export function parseTimeZone(zone) {
13
21
  const value = typeof zone === 'string' ? zone : zone.value;
14
22
  const zoneTokens = TokenCollection.fromPatterns(zone, [
@@ -1,5 +1,7 @@
1
1
  import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
+ * Validates a week string in the format `YYYY-Www`.
4
+ *
3
5
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#weeks
4
6
  */
5
7
  export declare const checkWeekString: CustomSyntaxChecker;
@@ -2,6 +2,8 @@ import { log } from '../../debug.js';
2
2
  import { TokenCollection } from '../../token/index.js';
3
3
  import { datetimeTokenCheck } from './datetime-tokens.js';
4
4
  /**
5
+ * Validates a week string in the format `YYYY-Www`.
6
+ *
5
7
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#weeks
6
8
  */
7
9
  export const checkWeekString = () => function checkWeekString(value) {
@@ -1,5 +1,7 @@
1
1
  import type { CustomSyntaxChecker } from '../../types.js';
2
2
  /**
3
+ * Validates a year string (four or more digits, greater than zero).
4
+ *
3
5
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html
4
6
  */
5
7
  export declare const checkYearString: CustomSyntaxChecker;
@@ -2,6 +2,8 @@ import { log } from '../../debug.js';
2
2
  import { TokenCollection } from '../../token/index.js';
3
3
  import { datetimeTokenCheck } from './datetime-tokens.js';
4
4
  /**
5
+ * Validates a year string (four or more digits, greater than zero).
6
+ *
5
7
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html
6
8
  */
7
9
  export const checkYearString = () => function checkYearString(value) {