/** * Template literal validation core module * Provides a validator that checks whether a string matches a template * literal pattern composed of string fragments and primitive validators * (string / number / boolean / bigint). The runtime check is performed by * an auto-generated regular expression assembled from the parts, while the * inferred type is the corresponding TypeScript template literal type. */ import { type StandardSchemaV1 } from "../../Validate/standardSchema"; import type { ValidateType } from "../../Validate/type"; export type TemplateLiteralAnyValidator = (value?: any) => { type: unknown; }; /** * Allowed parts of a template literal definition. Each element is either a * string literal that must appear verbatim, or a primitive validator whose * accepted shape is converted to a regex fragment at construction time. */ export type TemplateLiteralPart = string | TemplateLiteralAnyValidator; export type ExtractValidatorTag = V extends (value: never) => { type: infer T; } ? T : never; export type TagToTemplate = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T extends "bigint" ? bigint : ValidateType; export type PartToTemplate

= P extends string ? P : TagToTemplate>; /** * Builds the template literal type produced by joining `Parts`. Each part is * mapped to either its literal string value or to the runtime type that the * corresponding validator accepts. */ export type BuildTemplateLiteral = Parts extends readonly [ infer Head, ...infer Tail extends readonly TemplateLiteralPart[] ] ? `${Extract, string | number | bigint | boolean>}${BuildTemplateLiteral}` : ""; /** * Return type produced by a `templateLiteral` validator. Preserves the * literal template string type through the `type` field so consumers like * `union()`, `intersection()`, and `SchemaToInterface` can recover it. * @template T - The inferred template literal type */ export interface TemplateLiteralReturnType { validate: boolean; message: string; type: T; } /** * Creates a validator that checks whether a value matches a template literal * pattern. Each part is either a string literal that must appear verbatim or * a primitive validator (string / number / boolean / bigint) that contributes * a regex fragment. * @template Parts - Tuple describing the template parts * @param {Parts} parts - Tuple of literal strings and primitive validators * @param {string} [message] - Custom error message for validation failure * @returns {Function} - Validator function for template literal strings */ export declare const templateLiteral: (parts: Parts, message?: string) => ((value: BuildTemplateLiteral) => TemplateLiteralReturnType>) & StandardSchemaV1, BuildTemplateLiteral>;