UNPKG

1.14 kBTypeScriptView Raw
1import countryPhoneData from './data/country_phone_data';
2export interface PhoneInvalidResult {
3 isValid: false;
4 phoneNumber: null;
5 countryIso2: null;
6 countryIso3: null;
7 countryCode: null;
8}
9export interface PhoneValidResult {
10 isValid: true;
11 phoneNumber: string;
12 countryIso2: string;
13 countryIso3: string;
14 countryCode: string;
15}
16export type PhoneResult = PhoneInvalidResult | PhoneValidResult;
17/**
18 * @typedef {Object} Option
19 * @property {string=} country - country code in ISO3166 alpha 2 or 3
20 * @property {boolean=} validateMobilePrefix - true to validate phone number prefix
21 * @property {boolean=} strictDetection - true to disable remove truck code and detection logic
22 *
23 * @param {string} phoneNumber - phone number
24 * @param {Option} option
25 * @returns {{phoneNumber: string|null, countryIso2: string|null, countryIso3: string|null}}
26 */
27export default function phone(phoneNumber: string, { country, validateMobilePrefix, strictDetection }?: {
28 country?: string;
29 validateMobilePrefix?: boolean;
30 strictDetection?: boolean;
31}): PhoneResult;
32export { phone, countryPhoneData, };