//#region src/constants.d.ts /** * @file constants.ts * @description Plate format definitions based on Chilean Civil Registration specifications. * @source [Instructivo para Validación de Patentes - Servicio de Registro Civil e Identificación](https://www.registrocivil.cl/PortalOI/Manuales/ValidacionPatentes.pdf) * @source [Wikipedia: Matrículas automovilísticas de Chile](https://es.wikipedia.org/wiki/Matrículas_automovilísticas_de_Chile) */ /** * All recognized Chilean plate categories, including `invalid` for unmatched inputs. * * @example * plateType('BCDF12') === PlateType.NewVehicle // true */ declare const PlateType: { readonly NewVehicle: "new_vehicle_plate"; readonly NewMotorcycle: "new_motorcycle_plate"; readonly Old: "old_plate"; readonly Police: "police"; readonly Ambulance: "ambulance"; readonly Invalid: "invalid"; }; type PlateType = typeof PlateType[keyof typeof PlateType]; /** * Indicates the institutional nature of a special plate. */ declare const AuthorityType: { readonly Civil: "civil"; readonly Police: "police"; readonly Governmental: "governmental"; }; type AuthorityType = typeof AuthorityType[keyof typeof AuthorityType]; interface PlatePattern { /** Plate category this pattern matches. */ type: PlateType; /** Regular expression to validate the normalized plate string. */ pattern: RegExp; } interface SpecialPlate { /** Two-letter prefix that identifies this special plate category. */ prefix: string; /** Short human-readable name in Spanish. */ label: string; /** Extended description of the plate category in Spanish. */ description: string; /** Institutional nature of this plate. */ authority: AuthorityType; } //#endregion //#region src/types.d.ts /** * Configuration options for {@link plateValid}. */ interface IPlateValidConfig { /** * When `true`, attempts to correct common OCR character substitutions * (e.g. `0→O`, `1→I`, `8→B`) before validating. * * Useful when the plate string comes from an image recognition pipeline. * * @example * plateValid('8CDF12', { fuzzy: true }) // true ('8' corrected to 'B') * plateValid('8CDF12') // false */ fuzzy?: boolean; } //#endregion //#region src/index.d.ts /** * Returns all valid plate strings that can be derived from the input * by correcting common OCR character substitutions. * * Useful when you need the corrected string itself, not just a boolean result. * Returns an empty array if no valid plate can be derived. * * Note that a single OCR input can theoretically correct to more than one valid plate * (e.g. ambiguous length-6 strings that match both old and new formats after correction). * In practice this is rare, but callers should handle the multi-result case. * * @param plate - The plate string to correct. Must be pre-normalized. * @returns An array of valid corrected plate strings, or `[]` if none match. * * @example * fuzzyCorrect('8CDF12') // ['BCDF12'] * fuzzyCorrect('BCDF12') // ['BCDF12'] — already valid, returned as-is * fuzzyCorrect('XXXX99') // [] */ declare function fuzzyCorrect(plate: string): string[]; /** * Strips all non-alphanumeric characters from a string and converts it to uppercase. * * Useful for sanitizing user input before passing it to {@link plateValid} or {@link plateType}. * The standalone validation functions are strict and do not normalize internally — * call this explicitly if the input may contain hyphens, spaces, or other separators. * * @param p - The raw plate string. * @returns A sanitized, uppercase string containing only letters and digits. * * @example * normalize('BC-DF 12') // 'BCDF12' */ declare const normalize: (p: string) => string; /** * Checks whether a string is a valid Chilean license plate. * * This function is strict: the input must already be normalized (uppercase, no separators). * Use {@link normalize} beforehand if the input may contain hyphens or spaces. * * @param plate - The plate string to validate. Must be pre-normalized. * @param config - Optional validation config. Use `{ fuzzy: true }` to enable OCR correction. * @returns `true` if the plate matches any known Chilean format, `false` otherwise. * * @example * plateValid('BCDF12') // true * plateValid('8CDF12') // false — '8' not corrected in strict mode * plateValid('8CDF12', { fuzzy: true }) // true — '8' corrected to 'B' * plateValid('BC-DF12') // false — use normalize() first if needed */ declare function plateValid(plate: string, config?: IPlateValidConfig): boolean; /** * Shorthand for {@link plateValid}`(plate, { fuzzy: true })`. * * Attempts to correct common OCR character substitutions before validating. * Prefer this over `plateValid` when the input comes from an image recognition pipeline. * * @param plate - The plate string to validate. Must be pre-normalized. * @returns `true` if the plate matches any known Chilean format after OCR correction. * * @example * fuzzyPlateValid('8CDF12') // true — '8' corrected to 'B' * fuzzyPlateValid('BCDF12') // true — no correction needed * fuzzyPlateValid('XXXX99') // false — no valid format found */ declare function fuzzyPlateValid(plate: string): boolean; /** * Identifies the category of a Chilean license plate. * * This function is strict: the input must already be normalized (uppercase, no separators). * Use {@link normalize} beforehand if the input may contain hyphens or spaces. * * For plates matching the old format, the function further checks against * {@link SPECIAL_PLATES} to return a more specific category (e.g. `PlateType.Old`), * but the returned value will still be `PlateType.Old` — use {@link specialPlateInfo} * to get the full special plate metadata. * * @param plate - The plate string to identify. Must be pre-normalized. * @returns The {@link PlateType} of the plate, or `PlateType.Invalid` if no format matches. * * @example * plateType('BCDF12') // 'new_vehicle_plate' * plateType('CD1234') // 'old_plate' * plateType('BC-DF12') // 'invalid' — use normalize() first if needed */ declare function plateType(plate: string): PlateType; /** * Returns the {@link SpecialPlate} metadata for a plate that matches the old format, * or `null` if the plate is not a recognized special category. * * @param plate - The plate string to check. Must be pre-normalized. * @returns The matching {@link SpecialPlate} entry, or `null`. * * @example * specialPlateInfo('CD1234') // { prefix: 'CD', label: 'Cuerpo diplomático', ... } * specialPlateInfo('AA1234') // null * specialPlateInfo('BCDF12') // null */ declare function specialPlateInfo(plate: string): SpecialPlate | null; /** * Represents a Chilean license plate with utilities for validation, classification, and formatting. * * The constructor accepts raw input and normalizes it internally via {@link normalize}, * so hyphens and spaces are handled automatically. Validation and type detection * are performed on the normalized string. * * @example * const plate = new CLPlate('BC-DF12') * plate.clean // 'BCDF12' * plate.isValid // true * plate.type // 'new_vehicle_plate' * plate.formatted // 'BCDF-12' * plate.specialInfo // null * * const special = new CLPlate('CD-1234') * special.type // 'old_plate' * special.specialInfo // { prefix: 'CD', label: 'Cuerpo diplomático', ... } */ declare class CLPlate { /** The normalized plate string (uppercase, alphanumeric only). */ readonly clean: string; private readonly _type; private readonly _specialInfo; constructor(plate: string); /** * Strips all non-alphanumeric characters and converts to uppercase. * * Static convenience wrapper around the standalone {@link normalize} function, * useful when working exclusively with the `CLPlate` class without importing * standalone utilities. * * @param plate - The raw plate string. * @returns A sanitized, uppercase string containing only letters and digits. * * @example * CLPlate.normalize('BC-DF 12') // 'BCDF12' */ static normalize(plate: string): string; /** * Returns all valid plate strings that can be derived from the input * by correcting common OCR character substitutions. * * Static convenience wrapper around the standalone {@link fuzzyCorrect} function. * The input must be pre-normalized. * * @param plate - The plate string to correct. Must be pre-normalized. * @returns An array of valid corrected plate strings, or `[]` if none match. * * @example * CLPlate.fuzzyCorrect('8CDF12') // ['BCDF12'] * CLPlate.fuzzyCorrect('BCDF12') // ['BCDF12'] — already valid, returned as-is * CLPlate.fuzzyCorrect('XXXX99') // [] */ static fuzzyCorrect(plate: string): string[]; /** * Returns `true` if the plate matches a known Chilean format after OCR correction. * * Static convenience wrapper around {@link fuzzyPlateValid}. * Prefer this over `CLPlate.fuzzyCorrect(plate).length > 0` when you only need * a boolean result. * * @param plate - The plate string to validate. Must be pre-normalized. * @returns `true` if a valid plate can be derived via OCR correction. * * @example * CLPlate.isValidFuzzy('8CDF12') // true — '8' corrected to 'B' * CLPlate.isValidFuzzy('BCDF12') // true — no correction needed * CLPlate.isValidFuzzy('XXXX99') // false — no valid format found */ static isValidFuzzy(plate: string): boolean; /** * All valid plate strings derivable from {@link clean} via OCR correction. * * In rare cases a single input may correct to more than one valid plate; callers * should handle the multi-result case. * * @example * new CLPlate('8CDF12').fuzzyCorrections // ['BCDF12'] * new CLPlate('BCDF12').fuzzyCorrections // ['BCDF12'] — already valid, returned as-is * new CLPlate('XXXX99').fuzzyCorrections // [] */ get fuzzyCorrections(): string[]; /** Whether the plate matches a known Chilean format. */ get isValid(): boolean; /** The plate category. Returns `PlateType.Invalid` if no known format matches. */ get type(): PlateType; /** * Full metadata for special plates (old format with a recognized two-letter prefix). * Returns `null` for standard plates. * * @example * new CLPlate('CD1234').specialInfo // { prefix: 'CD', label: 'Cuerpo diplomático', ... } * new CLPlate('AA1234').specialInfo // null */ get specialInfo(): SpecialPlate | null; /** * The plate formatted for display, with a hyphen inserted at the appropriate position. * * If the plate is invalid, returns the raw normalized string without modification. * * @example * new CLPlate('AA1234').formatted // 'AA-1234' * new CLPlate('BCDF12').formatted // 'BCDF-12' * new CLPlate('A1234').formatted // 'A-1234' */ get formatted(): string; /** * Returns the formatted plate string, identical to {@link formatted}. * * Implemented so that string coercion (template literals, `String()`, `console.log`) * produces a human-readable value rather than `[object Object]`. * * @example * String(new CLPlate('BCDF12')) // 'BCDF-12' * `Plate: ${new CLPlate('AA1234')}` // 'Plate: AA-1234' */ toString(): string; } //#endregion export { AuthorityType, type AuthorityType as AuthorityTypeValue, CLPlate, type IPlateValidConfig, type PlatePattern, PlateType, type PlateType as PlateTypeValue, type SpecialPlate, fuzzyCorrect, fuzzyPlateValid, normalize, plateType, plateValid, specialPlateInfo };