UNPKG

@nexim/sanitizer

Version:

A collection of sanitization utilities for phone numbers and numeric inputs with TypeScript type safety.

50 lines 2.1 kB
/** * Sanitizes a number to English format. If input is already a number, returns it as-is. * If input is a string, converts Unicode digits to English and validates it's a valid number. * * @param number - The input to sanitize (number or string) * @returns The sanitized number or string, or null if invalid * * @example * ```ts * sanitizeNumberToEnglish(123); // returns 123 * sanitizeNumberToEnglish('۱۲۳'); // returns '123' * sanitizeNumberToEnglish('abc'); // returns null * ``` */ export declare function sanitizeNumberToEnglish(number: number): number; export declare function sanitizeNumberToEnglish<T>(number: T): number | null; /** * Sanitizes a number to English string format, preserving leading zeros. * If input is a string, converts Unicode digits to English and validates it's a valid number. * If input is already a number, converts it to string. * * @param number - The input to sanitize (number or string) * @returns The sanitized number as string, or null if invalid * * @example * ```ts * sanitizeNumberStringToEnglish(123); // returns '123' * sanitizeNumberStringToEnglish('۰۱۲۳'); // returns '0123' (preserves leading zero) * sanitizeNumberStringToEnglish('abc'); // returns null * ``` */ export declare function sanitizeNumberStringToEnglish<T>(number: T): string | null; /** * Sanitizes a phone number by converting Unicode digits, removing special characters, * and standardizing the format with country code. * * @param input - The phone number input to sanitize * @param countryCode - The country code to apply (default: '98' for Iran) * @returns The sanitized phone number as a number, or null if invalid * * @example * ```ts * sanitizePhoneNumber('09123456789'); // returns 989123456789 * sanitizePhoneNumber('+98 912 345 6789'); // returns 989123456789 * sanitizePhoneNumber('۰۹۱۲۳۴۵۶۷۸۹'); // returns 989123456789 * sanitizePhoneNumber('invalid'); // returns null * ``` */ export declare function sanitizePhoneNumber(input: unknown, countryCode?: string): number | null; //# sourceMappingURL=main.d.ts.map