finform-react-builder
Version:
A powerful, flexible React form builder with dynamic field rendering, custom validation, multi-step forms, Material-UI integration, image component support, toggle/radio buttons, switches, autocomplete, and advanced button positioning
57 lines (56 loc) • 1.74 kB
TypeScript
/**
* Generic phone normalize / display helpers for FinMobileField.
* Country rules come from field props — no country hardcoding.
*/
export type DialCodeOption = {
dial_code: string;
label?: string;
iso?: string;
};
export type PhoneNormalizeOptions = {
dialCode?: string;
storeFormat?: string;
prefixes?: string[];
};
export type PhoneDisplayParts = {
dialCode: string;
national: string;
};
/** Digits only. */
export declare function digitsOnly(value: unknown): string;
/** Strip leading zeros from a dial code string ("0260" → "260", "+260" → "260"). */
export declare function normalizeDialCode(dialCode: unknown): string;
/**
* Parse storeFormat like "0XXXXXXXXX":
* - leadingDigits: literal digit prefix ("0")
* - xCount: number of X placeholders (9)
* - totalLen: expected national length (10)
*/
export declare function parseStoreFormat(storeFormat?: string): {
leadingDigits: string;
xCount: number;
totalLen: number;
};
/**
* Normalize any common input shape into the national store format.
* Accepts: "+260971234567", "0971234567", "971234567", with spaces/dashes.
*/
export declare function normalizePhoneToStoreFormat(raw: unknown, options?: PhoneNormalizeOptions): string;
/**
* Split a stored national value for UI: dial code + national digits.
*/
export declare function parsePhoneDisplayParts(stored: unknown, options?: {
dialCode?: string;
dialCodes?: DialCodeOption[];
}): PhoneDisplayParts;
/**
* Validate a store-format national number.
*/
export declare function validatePhone(storeValue: unknown, options?: {
pattern?: string | RegExp;
prefixes?: string[];
message?: string;
}): {
valid: boolean;
message?: string;
};