@shopify/phone
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.038latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.038
1.0.11
1.0.00

Package Sidebar

Install

npm i @shopify/phone

Weekly Downloads

39

Version

1.1.0

License

MIT

Unpacked Size

28.8 kB

Total Files

20

Last publish

Collaborators

  • jaykay101
  • mishsmelle
  • shopify-dep
  • jaimie.rockburn
  • shopify-admin
  • maryharte
  • pmoloney89
  • netlohan