@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
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Creates a value checker function that wraps a primitive type check
3
+ * and returns a matched or unmatched result.
4
+ *
5
+ * @param checker - The primitive type check function to wrap
6
+ * @param options - Optional settings for the unmatched result including ref and reason
7
+ * @returns A function that takes a string value and returns a match result
8
+ */
1
9
  export function matches(checker, options) {
2
10
  return (value) => {
3
11
  const valid = checker(value);
@@ -7,11 +15,24 @@ export function matches(checker, options) {
7
15
  return valid ? matched() : unmatched(value, options?.reason, options);
8
16
  };
9
17
  }
18
+ /**
19
+ * Creates a successful match result.
20
+ *
21
+ * @returns A matched result object
22
+ */
10
23
  export function matched() {
11
24
  return {
12
25
  matched: true,
13
26
  };
14
27
  }
28
+ /**
29
+ * Creates a failed match result with location and reason information.
30
+ *
31
+ * @param value - The raw string value that failed to match
32
+ * @param reason - The reason for the mismatch
33
+ * @param options - Optional settings including ref URL and expected values
34
+ * @returns An unmatched result object with position details
35
+ */
15
36
  export function unmatched(value, reason, options) {
16
37
  return {
17
38
  ...options,
package/lib/number.d.ts CHANGED
@@ -1,3 +1,15 @@
1
1
  import type { Result } from './types.js';
2
2
  import type { Number as TypeNumber } from './types.schema.js';
3
+ /**
4
+ * Checks whether a value matches a number type definition.
5
+ *
6
+ * Validates the value as either an integer or float, then checks range
7
+ * constraints (gt, gte, lt, lte) if defined. Supports clampable values
8
+ * that suggest the nearest valid boundary value as a candidate.
9
+ *
10
+ * @param value - The string value to check
11
+ * @param type - The number type definition with format and range constraints
12
+ * @param ref - Optional reference URL for the unmatched result
13
+ * @returns The validation result
14
+ */
3
15
  export declare function checkNumber(value: string, type: Readonly<TypeNumber>, ref?: string): Result;
package/lib/number.js CHANGED
@@ -1,5 +1,17 @@
1
1
  import { matched, unmatched } from './match-result.js';
2
2
  import { isFloat, isInt } from './primitive/index.js';
3
+ /**
4
+ * Checks whether a value matches a number type definition.
5
+ *
6
+ * Validates the value as either an integer or float, then checks range
7
+ * constraints (gt, gte, lt, lte) if defined. Supports clampable values
8
+ * that suggest the nearest valid boundary value as a candidate.
9
+ *
10
+ * @param value - The string value to check
11
+ * @param type - The number type definition with format and range constraints
12
+ * @param ref - Optional reference URL for the unmatched result
13
+ * @returns The validation result
14
+ */
3
15
  export function checkNumber(value, type, ref) {
4
16
  if (!value) {
5
17
  return unmatched(value, 'empty-token');
@@ -0,0 +1,12 @@
1
+ import type { Pattern, Result } from './types.js';
2
+ import type { ReadonlyDeep } from 'type-fest';
3
+ /**
4
+ * Validates a string value against a pattern type definition.
5
+ * The pattern can be either a regular expression literal in the form
6
+ * `/pattern/flags` or a plain string for exact equality matching.
7
+ *
8
+ * @param value - The string value to validate
9
+ * @param type - The pattern type definition containing the pattern string
10
+ * @returns A result indicating whether the value matches the pattern
11
+ */
12
+ export declare function checkPattern(value: string, type: ReadonlyDeep<Pattern>): Result;
package/lib/pattern.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Validates a string value against a pattern type definition.
3
+ * The pattern can be either a regular expression literal in the form
4
+ * `/pattern/flags` or a plain string for exact equality matching.
5
+ *
6
+ * @param value - The string value to validate
7
+ * @param type - The pattern type definition containing the pattern string
8
+ * @returns A result indicating whether the value matches the pattern
9
+ */
10
+ export function checkPattern(value, type) {
11
+ const regexMatch = type.pattern.match(/^\/(.*)\/([gim])*$/);
12
+ if (regexMatch && regexMatch[1]) {
13
+ const re = regexMatch[1];
14
+ const flag = regexMatch[2];
15
+ if (new RegExp(re, flag).test(value)) {
16
+ return { matched: true };
17
+ }
18
+ }
19
+ else if (value === type.pattern) {
20
+ return { matched: true };
21
+ }
22
+ return {
23
+ matched: false,
24
+ ref: null,
25
+ raw: value,
26
+ length: value.length,
27
+ offset: 0,
28
+ line: 1,
29
+ column: 1,
30
+ reason: 'syntax-error',
31
+ expects: [{ type: 'regexp', value: type.pattern }],
32
+ };
33
+ }
@@ -1,6 +1,9 @@
1
1
  /**
2
+ * Checks whether a string is a valid floating-point number.
3
+ *
2
4
  * @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#floating-point-numbers
3
5
  *
4
- * @param value
6
+ * @param value - The string to validate
7
+ * @returns Whether the value is a valid floating-point number
5
8
  */
6
9
  export declare function isFloat(value: string): boolean;
@@ -1,7 +1,10 @@
1
1
  /**
2
+ * Checks whether a string is a valid floating-point number.
3
+ *
2
4
  * @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#floating-point-numbers
3
5
  *
4
- * @param value
6
+ * @param value - The string to validate
7
+ * @returns Whether the value is a valid floating-point number
5
8
  */
6
9
  export function isFloat(value) {
7
10
  return value === value.trim() && Number.isFinite(Number.parseFloat(value));
@@ -1,6 +1,9 @@
1
1
  /**
2
+ * Checks whether a string is a valid signed integer.
3
+ *
2
4
  * @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#signed-integers
3
5
  *
4
- * @param value
6
+ * @param value - The string to validate
7
+ * @returns Whether the value is a valid signed integer
5
8
  */
6
9
  export declare function isInt(value: string): boolean;
@@ -1,7 +1,10 @@
1
1
  /**
2
+ * Checks whether a string is a valid signed integer.
3
+ *
2
4
  * @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#signed-integers
3
5
  *
4
- * @param value
6
+ * @param value - The string to validate
7
+ * @returns Whether the value is a valid signed integer
5
8
  */
6
9
  export function isInt(value) {
7
10
  return /^-?\d+$/.test(value);
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Non-negative integer greater than zero
2
+ * Checks whether a string is a valid non-negative integer greater than zero.
3
3
  *
4
- * @param value
4
+ * @param value - The string to validate
5
+ * @returns Whether the value is a valid non-zero unsigned integer
5
6
  */
6
7
  export declare function isNonZeroUint(value: string): boolean;
@@ -1,7 +1,8 @@
1
1
  /**
2
- * Non-negative integer greater than zero
2
+ * Checks whether a string is a valid non-negative integer greater than zero.
3
3
  *
4
- * @param value
4
+ * @param value - The string to validate
5
+ * @returns Whether the value is a valid non-zero unsigned integer
5
6
  */
6
7
  export function isNonZeroUint(value) {
7
8
  return /^\d+$/.test(value) && !/^0+$/.test(value);
@@ -1,7 +1,9 @@
1
1
  /**
2
+ * Checks whether a string is a valid number with one of the allowed unit suffixes.
2
3
  *
3
- * @param value
4
- * @param units
5
- * @param numberType
4
+ * @param value - The string to validate (e.g., "10px", "1.5em")
5
+ * @param units - The allowed unit suffixes (e.g., `["px", "em", "rem"]`)
6
+ * @param numberType - The number format constraint: `"int"`, `"uint"`, or `"float"` (defaults to `"float"`)
7
+ * @returns Whether the value is a valid quantity with an allowed unit
6
8
  */
7
9
  export declare function isQuantity(value: string, units: readonly string[], numberType?: 'int' | 'uint' | 'float'): boolean;
@@ -3,10 +3,12 @@ import { isInt } from './is-int.js';
3
3
  import { isUint } from './is-uint.js';
4
4
  import { splitUnit } from './split-unit.js';
5
5
  /**
6
+ * Checks whether a string is a valid number with one of the allowed unit suffixes.
6
7
  *
7
- * @param value
8
- * @param units
9
- * @param numberType
8
+ * @param value - The string to validate (e.g., "10px", "1.5em")
9
+ * @param units - The allowed unit suffixes (e.g., `["px", "em", "rem"]`)
10
+ * @param numberType - The number format constraint: `"int"`, `"uint"`, or `"float"` (defaults to `"float"`)
11
+ * @returns Whether the value is a valid quantity with an allowed unit
10
12
  */
11
13
  export function isQuantity(value, units, numberType = 'float') {
12
14
  const { num, unit } = splitUnit(value);
@@ -1,7 +1,11 @@
1
1
  /**
2
+ * Checks whether a string is a valid non-negative integer.
3
+ *
2
4
  * @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#non-negative-integers
3
5
  *
4
- * @param value
6
+ * @param value - The string to validate
7
+ * @param options - Optional constraints; use `gt` to require a value greater than the specified number
8
+ * @returns Whether the value is a valid non-negative integer within the constraints
5
9
  */
6
10
  export declare function isUint(value: string, options?: {
7
11
  readonly gt?: number;
@@ -1,7 +1,11 @@
1
1
  /**
2
+ * Checks whether a string is a valid non-negative integer.
3
+ *
2
4
  * @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#non-negative-integers
3
5
  *
4
- * @param value
6
+ * @param value - The string to validate
7
+ * @param options - Optional constraints; use `gt` to require a value greater than the specified number
8
+ * @returns Whether the value is a valid non-negative integer within the constraints
5
9
  */
6
10
  export function isUint(value, options) {
7
11
  const matched = /^\d+$/.test(value);
@@ -1,8 +1,9 @@
1
1
  /**
2
- * It is in the range between `from` and `to`.
2
+ * Checks whether a numeric string value falls within an inclusive range.
3
3
  *
4
- * @param value
5
- * @param from
6
- * @param to
4
+ * @param value - The string to parse as a number and validate
5
+ * @param from - The minimum allowed value (inclusive)
6
+ * @param to - The maximum allowed value (inclusive)
7
+ * @returns Whether the parsed number is within the range `[from, to]`
7
8
  */
8
9
  export declare function range(value: string, from: number, to: number): boolean;
@@ -1,9 +1,10 @@
1
1
  /**
2
- * It is in the range between `from` and `to`.
2
+ * Checks whether a numeric string value falls within an inclusive range.
3
3
  *
4
- * @param value
5
- * @param from
6
- * @param to
4
+ * @param value - The string to parse as a number and validate
5
+ * @param from - The minimum allowed value (inclusive)
6
+ * @param to - The maximum allowed value (inclusive)
7
+ * @returns Whether the parsed number is within the range `[from, to]`
7
8
  */
8
9
  export function range(value, from, to) {
9
10
  const num = Number.parseFloat(value);
@@ -1,7 +1,8 @@
1
1
  /**
2
+ * Splits a value string into its numeric and unit parts.
2
3
  *
3
- * @param value
4
- * @returns
4
+ * @param value - The string to split (e.g., "10px", "1.5em")
5
+ * @returns An object with `num` (the numeric part) and `unit` (the unit suffix, or empty string)
5
6
  */
6
7
  export declare function splitUnit(value: string): {
7
8
  num: string;
@@ -1,7 +1,8 @@
1
1
  /**
2
+ * Splits a value string into its numeric and unit parts.
2
3
  *
3
- * @param value
4
- * @returns
4
+ * @param value - The string to split (e.g., "10px", "1.5em")
5
+ * @returns An object with `num` (the numeric part) and `unit` (the unit suffix, or empty string)
5
6
  */
6
7
  export function splitUnit(value) {
7
8
  value = value.trim().toLowerCase();
@@ -1,5 +1,7 @@
1
1
  import type { FormattedPrimitiveTypeCreator } from '../types.js';
2
2
  /**
3
+ * Checks whether a string is a valid BCP 47 language tag.
4
+ *
3
5
  * @see https://tools.ietf.org/rfc/bcp/bcp47.html
4
6
  */
5
7
  export declare const isBCP47: FormattedPrimitiveTypeCreator;
@@ -1,10 +1,12 @@
1
1
  import { parse } from 'bcp-47';
2
2
  /**
3
+ * Checks whether a string is a valid BCP 47 language tag.
4
+ *
3
5
  * @see https://tools.ietf.org/rfc/bcp/bcp47.html
4
6
  */
5
7
  export const isBCP47 = () => {
6
8
  return value => {
7
- const { language } = parse(value);
8
- return !!language;
9
+ const { language, privateuse } = parse(value);
10
+ return !!language || (privateuse != null && privateuse.length > 0);
9
11
  };
10
12
  };
@@ -4,8 +4,28 @@ import { Token } from './token.js';
4
4
  type TokenCollectionOptions = Partial<Omit<List, 'token'> & {
5
5
  specificSeparator: string | string[];
6
6
  }>;
7
+ /**
8
+ * Callback function for sequential token checking in {@link TokenCollection.eachCheck}.
9
+ * Receives the current head token and remaining tail tokens.
10
+ * Returns a result to stop iteration, or `void` to continue.
11
+ */
7
12
  export type TokenEachCheck = (head: Readonly<Token> | null, tail: TokenCollection) => Result | void;
13
+ /**
14
+ * An ordered collection of tokens parsed from a string value.
15
+ *
16
+ * Extends `Array<Token>` with parsing, validation, and query capabilities.
17
+ * Supports configurable separators (space, comma, or custom), uniqueness
18
+ * constraints, ordering checks, and case sensitivity options.
19
+ */
8
20
  export declare class TokenCollection extends Array<Token> {
21
+ /**
22
+ * Creates a TokenCollection by matching a value against a sequence of regex patterns.
23
+ *
24
+ * @param value - The source token or string to parse
25
+ * @param patterns - The regex patterns to match sequentially
26
+ * @param typeOptions - Optional collection configuration
27
+ * @returns A new TokenCollection containing the matched tokens
28
+ */
9
29
  static fromPatterns(value: Readonly<Token> | string, patterns: readonly Readonly<RegExp>[], typeOptions?: Omit<TokenCollectionOptions, 'specificSeparator'> & {
10
30
  repeat?: boolean;
11
31
  }): TokenCollection;
@@ -19,39 +39,124 @@ export declare class TokenCollection extends Array<Token> {
19
39
  readonly unique: NonNullable<List['unique']>;
20
40
  constructor(value?: string, typeOptions?: TokenCollectionOptions);
21
41
  constructor(value?: number);
42
+ /**
43
+ * The concatenated string value of all tokens in this collection.
44
+ */
22
45
  get value(): string;
46
+ /**
47
+ * Validates the token collection structure against its configuration.
48
+ *
49
+ * Checks for unexpected spaces, consecutive commas, empty tokens,
50
+ * and duplicate values based on the collection's separator, allowEmpty,
51
+ * and unique settings.
52
+ *
53
+ * @param options - Optional validation settings including expected values and reference URL
54
+ * @returns The validation result
55
+ */
23
56
  check(options?: {
24
57
  expects?: Expect[];
25
58
  ref?: string;
26
59
  cache?: boolean;
27
- }): UnmatchedResult | import("../types.js").MatchedResult;
60
+ }): import("../types.js").MatchedResult | UnmatchedResult;
61
+ /**
62
+ * Splits this collection into chunks of the specified size.
63
+ *
64
+ * @param split - The number of tokens per chunk
65
+ * @returns An array of TokenCollection chunks
66
+ */
28
67
  chunk(split: number): TokenCollection[];
68
+ /**
69
+ * Iterates over consecutive token pairs, calling the callback for each pair.
70
+ *
71
+ * @param callback - A function receiving the previous and current token; return a token to stop iteration
72
+ * @returns The token returned by the callback, or `null` if iteration completes
73
+ */
29
74
  compareTokens(callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void): Readonly<Token> | null | undefined;
75
+ /**
76
+ * Splits this collection into two at the given position.
77
+ *
78
+ * @param position - The index at which to split
79
+ * @returns A tuple of two TokenCollections: before and after the position
80
+ */
30
81
  divide(position: number): readonly [TokenCollection, TokenCollection];
82
+ /**
83
+ * Applies a sequence of check callbacks to consecutive tokens.
84
+ *
85
+ * Each callback receives the current head token and remaining tail.
86
+ * Tracks pass count and cumulative offset for error reporting.
87
+ *
88
+ * @param callbacks - The check functions to apply sequentially
89
+ * @returns The validation result
90
+ */
31
91
  eachCheck(...callbacks: readonly TokenEachCheck[]): Result;
92
+ /**
93
+ * Creates a new TokenCollection containing only tokens that pass the test.
94
+ *
95
+ * @param callback - The filter predicate function
96
+ * @returns A new TokenCollection with the filtered tokens
97
+ */
32
98
  filter(callback: Parameters<Array<Token>['filter']>[0]): TokenCollection;
99
+ /**
100
+ * Finds the first occurrence of two consecutive tokens of the same type.
101
+ *
102
+ * @param tokenType - The token type number to check for consecutive occurrences
103
+ * @returns The second consecutive token, or `null` if none found
104
+ */
33
105
  getConsecutiveToken(tokenType: number): Readonly<Token> | null;
106
+ /**
107
+ * Finds the first duplicated token in this collection.
108
+ *
109
+ * Comparison respects the `caseInsensitive` setting of this collection.
110
+ *
111
+ * @returns The duplicated token, or `null` if all tokens are unique
112
+ */
34
113
  getDuplicated(): Token | null;
114
+ /**
115
+ * Returns only the identifier tokens, excluding whitespace and separators.
116
+ *
117
+ * @returns A new TokenCollection containing only Ident-type tokens
118
+ */
35
119
  getIdentTokens(): TokenCollection;
36
120
  /**
121
+ * Checks whether any token in this collection matches the given value.
37
122
  *
38
- * @param value The token value or the token type or its list
123
+ * @param value - The token value, type number, regex, or array to check against
124
+ * @returns Whether any token matches
39
125
  */
40
126
  has(value: TokenValue): boolean;
127
+ /**
128
+ * Splits this collection into a head token and a tail collection.
129
+ *
130
+ * @returns An object with `head` (first token or null) and `tail` (remaining tokens)
131
+ */
41
132
  headAndTail(): {
42
133
  head: Token | null;
43
134
  tail: TokenCollection;
44
135
  };
45
136
  /**
137
+ * Searches for the first token that includes the given value.
46
138
  *
47
- * @param value The token value or the token type or its list
139
+ * @param value - The token value, type number, regex, or array to search for
140
+ * @returns The first matching token, or `null` if not found
48
141
  */
49
142
  search(value: TokenValue): Token | null;
143
+ /**
144
+ * Verifies that tokens alternate between the specified types in order.
145
+ *
146
+ * @param tokenNumbers - The expected repeating pattern of token types
147
+ * @param lastTokenNumber - Optional expected type for the last token
148
+ * @returns An error object if the pattern is violated, or `null` if valid
149
+ */
50
150
  takeTurns(tokenNumbers: ReadonlyArray<number>, lastTokenNumber?: number): {
51
151
  unexpectedLastToken: boolean;
52
152
  expectedTokenNumber: number | undefined;
53
153
  token: Token;
54
154
  } | null;
155
+ /**
156
+ * Converts all tokens in this collection to plain JSON-serializable objects.
157
+ *
158
+ * @returns An array of plain token objects
159
+ */
55
160
  toJSON(): {
56
161
  type: number;
57
162
  value: string;