UNPKG

@artmajeur/react-native-paper-phone-number-input

Version:

A performant phone number input component for react-native-paper with country picker

34 lines 1.05 kB
import parsePhoneNumberFromString, { AsYouType } from 'libphonenumber-js'; import { countriesMap } from './data/countries'; export const getCountryByCode = (code = '##') => { const country = countriesMap[code]; if (!country) { throw new Error(`Country with code ${code} not found`); } return country; }; export const getDialCodeByCode = (code = '##') => { const country = countriesMap[code]; if (!country) { throw new Error(`Country with code ${code} not found`); } return country.dialCode; }; export const extractPhoneInfo = input => { const phoneNumber = parsePhoneNumberFromString(input); if (!phoneNumber || !phoneNumber.isValid()) { return { error: 'Invalid phone number' }; } return { dialCode: phoneNumber.countryCallingCode, nationalNumber: phoneNumber.formatNational(), code: phoneNumber.country }; }; export const liveFormatPhoneNumber = (input, countryCode) => { const formatter = new AsYouType(countryCode); return formatter.input(input); }; //# sourceMappingURL=utils.js.map