phonumber
Version:
Phone number parser. Good for formatting phone numbers entered by users.
56 lines (55 loc) • 2.88 kB
TypeScript
export declare type ParserPhoneNumberOptions = {
resolvers?: Array<Resolver>;
formats?: Formats;
};
export declare type SetMaskParams = {
value: string;
mask?: string;
options?: MaskOptions;
};
export declare type ApplyResolversParams = {
value: string;
resolvers: Array<Resolver>;
};
export declare type ParserPhoneNumberResult = {
code: string | null;
dialCode: string | null;
nationalNumber: string | null;
formattedNumber: string;
};
export declare type Formats = Partial<Record<CountryCode, Format>>;
export declare type Format = {
mask?: string;
} & MaskOptions;
export declare type MaskOptions = {
withTail?: boolean;
};
export declare type Resolver = {
firstInputChars: Record<number, ResolverOption>;
resolveAs: ResolverTarget;
};
export declare type ResolverOption = {
mode: ResolverMode;
};
declare type ResolverMode = 'add' | 'replace';
export declare type ResolverTarget = {
firstChar: number;
code: CountryCode;
};
export declare type ResolverResult = {
resolvedCell: PhoneTableCell | null;
resolvedPhone: string;
};
export declare type PhoneTable = {
[key: string]: Array<PhoneTableCell>;
};
export declare type PhoneTableCell = {
secondNumbers: Array<number>;
countries: Array<Country>;
};
export declare type Country = {
code: CountryCode;
dialCode: string;
};
declare type CountryCode = 'US' | 'EG' | 'SS' | 'MA' | 'DZ' | 'TN' | 'LY' | 'GM' | 'SN' | 'MR' | 'ML' | 'GN' | 'CI' | 'BF' | 'NE' | 'TG' | 'BJ' | 'MU' | 'LR' | 'SL' | 'GH' | 'NG' | 'TD' | 'CF' | 'CM' | 'CV' | 'ST' | 'GQ' | 'GA' | 'CG' | 'CD' | 'AO' | 'GW' | 'IO' | 'AC' | 'SC' | 'SD' | 'RW' | 'ET' | 'SO' | 'DJ' | 'KE' | 'TZ' | 'UG' | 'BI' | 'MZ' | 'ZM' | 'MG' | 'RE' | 'ZW' | 'NA' | 'MW' | 'LS' | 'BW' | 'SZ' | 'KM' | 'ZA' | 'SH' | 'ER' | 'AW' | 'FO' | 'GL' | 'GR' | 'NL' | 'BE' | 'FR' | 'ES' | 'GI' | 'PT' | 'LU' | 'IE' | 'IS' | 'AL' | 'MT' | 'CY' | 'FI' | 'BG' | 'HU' | 'LT' | 'LV' | 'EE' | 'MD' | 'AM' | 'BY' | 'AD' | 'MC' | 'SM' | 'VA' | 'UA' | 'RS' | 'ME' | 'XK' | 'HR' | 'SI' | 'BA' | 'EU' | 'MK' | 'IT' | 'RO' | 'CH' | 'CZ' | 'SK' | 'LI' | 'AT' | 'UK' | 'DK' | 'SE' | 'NO' | 'PL' | 'DE' | 'FK' | 'BZ' | 'GT' | 'SV' | 'HN' | 'NI' | 'CR' | 'PA' | 'PM' | 'HT' | 'PE' | 'MX' | 'CU' | 'AR' | 'BR' | 'CL' | 'CO' | 'VE' | 'FK' | 'BZ' | 'GT' | 'SV' | 'HN' | 'NI' | 'CR' | 'PA' | 'PM' | 'HT' | 'MY' | 'AU' | 'ID' | 'PH' | 'NZ' | 'SG' | 'TH' | 'TL' | 'AQ' | 'BN' | 'NR' | 'PG' | 'TO' | 'SB' | 'VU' | 'FJ' | 'PW' | 'WF' | 'CK' | 'NU' | 'WS' | 'KI' | 'NC' | 'TV' | 'PF' | 'TK' | 'FM' | 'MH' | 'KZ' | 'RU' | 'JP' | 'KR' | 'VN' | 'KP' | 'HK' | 'MO' | 'KH' | 'LA' | 'CN' | 'BD' | 'TW' | 'TR' | 'IN' | 'PK' | 'AF' | 'LK' | 'MM' | 'MV' | 'LB' | 'JO' | 'SY' | 'IQ' | 'KW' | 'SA' | 'YE' | 'OM' | 'PS' | 'AE' | 'IL' | 'BH' | 'QA' | 'BT' | 'MN' | 'NP' | 'IR' | 'TJ' | 'TM' | 'AZ' | 'GE' | 'KG' | 'UZ';
export {};