/** * Pattern-based input masking with caret preservation. * * The engine is deliberately split into two phases, which is what makes it safe * to feed its own output back in on every keystroke: * * 1. `unmask` walks the input string *against the pattern*, consuming literals * that the input reproduced and skipping anything that can't fill a slot. * This is the part that has to tolerate the mask's own separators — a mask * like `(000) 000-0000` contains a space, and a naive "strip punctuation" * pass leaves that space in the payload where it fails the digit test and * truncates everything after it. * 2. `layout` lays the extracted payload back into the pattern, recording the * output index of every payload character so the caret can be re-derived * rather than guessed from a string diff. * * Literal characters that are *also* valid slot characters (the `1` in * `+1 (000) 000-0000`) are inherently ambiguous — the engine resolves the common * case (see `unmask`) and warns in development. Prefer keeping fixed dial codes * outside the mask. */ export interface MaskDefinition { /** The mask pattern (e.g., '(000) 000-0000', '+00 000 000 0000') */ mask: string; /** Placeholder character for unfilled positions */ placeholderChar?: string; /** Whether to show the mask when input is empty */ showMask?: boolean; /** Custom definitions for mask characters */ definitions?: Record; /** * When `true` (the default) the value stops at the last filled slot, so no * dangling separators trail the caret. When `false` the full mask is always * rendered with `placeholderChar` in the unfilled slots. */ lazy?: boolean; } export interface MaskResult { /** The masked/formatted value */ value: string; /** The unmasked/raw value */ unmaskedValue: string; /** Whether every slot in the mask is filled */ isComplete: boolean; /** Caret position within `value` after formatting */ cursorPosition: number; } interface PatternSlot { char: string; isFixed: boolean; regex?: RegExp; } /** * Creates a masking function for the given pattern. */ export declare function createMask(definition: MaskDefinition): { applyMask: (inputValue: string, previousValue?: string, cursorPos?: number) => MaskResult; getDisplayValue: (value: string) => string; processInput: (newValue: string, oldValue: string, selectionStart?: number) => MaskResult; /** Extract just the payload characters from any input. */ unmask: (input: string) => string; /** Number of fillable slots in the mask. */ slotCount: number; pattern: PatternSlot[]; definition: MaskDefinition; }; export type Mask = ReturnType; /** * Phone number specific masking presets. * * The `*_WITH_COUNTRY` style presets embed a literal dial code, which the engine * resolves for the leading position but which still costs the user a keystroke of * ambiguity. Prefer a national mask plus a separate non-editable prefix — that is * what `PhoneInput` does. */ export declare const PHONE_MASKS: { US: { applyMask: (inputValue: string, previousValue?: string, cursorPos?: number) => MaskResult; getDisplayValue: (value: string) => string; processInput: (newValue: string, oldValue: string, selectionStart?: number) => MaskResult; /** Extract just the payload characters from any input. */ unmask: (input: string) => string; /** Number of fillable slots in the mask. */ slotCount: number; pattern: PatternSlot[]; definition: MaskDefinition; }; US_WITH_COUNTRY: { applyMask: (inputValue: string, previousValue?: string, cursorPos?: number) => MaskResult; getDisplayValue: (value: string) => string; processInput: (newValue: string, oldValue: string, selectionStart?: number) => MaskResult; /** Extract just the payload characters from any input. */ unmask: (input: string) => string; /** Number of fillable slots in the mask. */ slotCount: number; pattern: PatternSlot[]; definition: MaskDefinition; }; UK: { applyMask: (inputValue: string, previousValue?: string, cursorPos?: number) => MaskResult; getDisplayValue: (value: string) => string; processInput: (newValue: string, oldValue: string, selectionStart?: number) => MaskResult; /** Extract just the payload characters from any input. */ unmask: (input: string) => string; /** Number of fillable slots in the mask. */ slotCount: number; pattern: PatternSlot[]; definition: MaskDefinition; }; UK_NATIONAL: { applyMask: (inputValue: string, previousValue?: string, cursorPos?: number) => MaskResult; getDisplayValue: (value: string) => string; processInput: (newValue: string, oldValue: string, selectionStart?: number) => MaskResult; /** Extract just the payload characters from any input. */ unmask: (input: string) => string; /** Number of fillable slots in the mask. */ slotCount: number; pattern: PatternSlot[]; definition: MaskDefinition; }; INTERNATIONAL: { applyMask: (inputValue: string, previousValue?: string, cursorPos?: number) => MaskResult; getDisplayValue: (value: string) => string; processInput: (newValue: string, oldValue: string, selectionStart?: number) => MaskResult; /** Extract just the payload characters from any input. */ unmask: (input: string) => string; /** Number of fillable slots in the mask. */ slotCount: number; pattern: PatternSlot[]; definition: MaskDefinition; }; }; /** * Other useful mask presets */ export declare const COMMON_MASKS: { CREDIT_CARD: { applyMask: (inputValue: string, previousValue?: string, cursorPos?: number) => MaskResult; getDisplayValue: (value: string) => string; processInput: (newValue: string, oldValue: string, selectionStart?: number) => MaskResult; /** Extract just the payload characters from any input. */ unmask: (input: string) => string; /** Number of fillable slots in the mask. */ slotCount: number; pattern: PatternSlot[]; definition: MaskDefinition; }; DATE: { applyMask: (inputValue: string, previousValue?: string, cursorPos?: number) => MaskResult; getDisplayValue: (value: string) => string; processInput: (newValue: string, oldValue: string, selectionStart?: number) => MaskResult; /** Extract just the payload characters from any input. */ unmask: (input: string) => string; /** Number of fillable slots in the mask. */ slotCount: number; pattern: PatternSlot[]; definition: MaskDefinition; }; SSN: { applyMask: (inputValue: string, previousValue?: string, cursorPos?: number) => MaskResult; getDisplayValue: (value: string) => string; processInput: (newValue: string, oldValue: string, selectionStart?: number) => MaskResult; /** Extract just the payload characters from any input. */ unmask: (input: string) => string; /** Number of fillable slots in the mask. */ slotCount: number; pattern: PatternSlot[]; definition: MaskDefinition; }; ZIP_CODE: { applyMask: (inputValue: string, previousValue?: string, cursorPos?: number) => MaskResult; getDisplayValue: (value: string) => string; processInput: (newValue: string, oldValue: string, selectionStart?: number) => MaskResult; /** Extract just the payload characters from any input. */ unmask: (input: string) => string; /** Number of fillable slots in the mask. */ slotCount: number; pattern: PatternSlot[]; definition: MaskDefinition; }; }; export {};