@shopify/phone
v1.1.0
Published
Phone number utilities for formatting phone numbers
Downloads
504
Keywords
Readme
@shopify/phone
Phone number utilities for formatting phone numbers.
Installation
yarn add @shopify/phone
PhoneNumberFormatter methods
import PhoneNumberFormatter from '@shopify/phone';
// Pass a region code to the constructor
const phoneFormatter = new PhoneNumberFormatter('US');
const formatted = phoneFormatter.format(myPhoneNumber);
format(phoneNumber: string): string
Formats the given phone number
update(regionCode: string): void
Update formatter regionCode which will format number based on that (eg: 'CA' | 'JP' etc.)
getNormalizedNumber(phoneNumber: string): string
Returns phone number in E164 format
getNationalNumber(phoneNumber: string): string
Returns the non-formatted version without the country code
requiresItalianLeadingZero(phoneNumber: string)
Indicates if the leading zero of a national number should be retained when dialling internationally
updateCountryCode(phoneNumber: string): void
Updates the country code of the formatter based on the phoneNumber passed
Exported functions
getRegionCodeFromNumber(phoneNumber: string): string
Returns the region code from the provided phone number
getCountryCodeFromNumber(phoneNumber: string): number | undefined
Returns the country code from the provided phone number