Skip to content

Latest commit

 

History

History

phone

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

@shopify/phone

Build Status Build Status License: MIT npm version npm bundle size (minified + gzip)

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