UNPKG

e164num

Version:

**Light validation and manipulation of E.164 phone numbers.**

47 lines (46 loc) 1.18 kB
/** * Returns a valid partial E.164 phone number based on the received phone * number or empty string for undefined/empty input. This can be used to process * phone numbers in input fields as the user types. * * @param phoneNumber The phone number to format. * * @param defaultCountryInfo The default country code and max length for the * desired country. In the case where the code is matched, the phone number will * be truncated at maxLength including the plus sign. (Defaults to +1 and 12 * characters for US phone numbers.) * * @example * ```ts * getPartialE164PhoneNumber('7') * // returns '+17' * ``` * * @example * ```ts * getPartialE164PhoneNumber('787123') * // returns '+1787123' * ``` * * @example * ```ts * getPartialE164PhoneNumber('787123', {code: '+34', maxLength: 12}) * // returns '+34787123' * ``` * * @example * ```ts * getPartialE164PhoneNumber('') * // returns '' * ``` * * @example * ```ts * getPartialE164PhoneNumber(undefined) * // returns '' * ``` */ export declare const getPartialE164PhoneNumber: (phoneNumber: string | undefined, defaultCountryInfo?: { code: string; maxLength: number; }) => string;