Socket
Socket
Sign inDemoInstall

libphonenumbers

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libphonenumbers

Google's common JavaScript library for parsing, formatting, and validating international phone numbers for Node.js.


Version published
Maintainers
1
Created
Source

libphonenumbers

libphonenumbers – Google's common JavaScript library for parsing, formatting, and validating international phone numbers for Node.js.

libphonenumbers is JS port of Google's libphonenumber.

🎁 Features

libphonenumbers is compatible with both JavaScript and TypeScript.

  • PhoneNumberUtil

    • format(number, numberFormat)
    • formatInOriginalFormat(number, regionCallingFrom)
    • formatOutOfCountryCallingNumber(number, regionCallingFrom)
    • getNumberType(number)
    • getRegionCodeForNumber(number)
    • isPossibleNumber(number)
    • isValidNumber(number)
    • isValidNumberForRegion(number, regionCode)
    • parseAndKeepRawInput(numberToParse, defaultRegion)
    • parse(numberToParse, defaultRegion)
  • ShortNumberInfo

    • connectsToEmergencyNumber(number, regionCode)
    • isPossibleShortNumberForRegion(number, regionDialingFrom)
    • isValidShortNumber(number)
    • isPossibleShortNumber(number)
    • isValidShortNumberForRegion(number, regionDialingFrom)
  • PhoneNumberType

    • FIXED_LINE
    • MOBILE
    • SHARED_COST
    • FIXED_LINE_OR_MOBILE
    • TOLL_FREE
    • PREMIUM_RATE
    • PAGER
    • VOIP
    • PERSONAL_NUMBER
    • VOICEMAIL
    • UAN
    • UNKNOWN
  • PhoneNumberFormat

    • PhoneNumberFormat.E164
    • PhoneNumberFormat.INTERNATIONAL
    • PhoneNumberFormat.NATIONAL
    • PhoneNumberFormat.RFC3966
  • CountryCodeSource

    • UNSPECIFIED
    • FROM_NUMBER_WITH_IDD
    • FROM_NUMBER_WITHOUT_PLUS_SIGN
    • FROM_NUMBER_WITH_PLUS_SIGN
    • FROM_DEFAULT_COUNTRY
  • PhoneNumber

    • getCountryCode()
    • getCountryCodeSource()
    • getExtension()
    • getItalianLeadingZero()
    • getNationalNumber()
    • getRawInput()

❌ Missing Features:

JS port of Google's libphonenumber does not support the following functions and classes:

  • findNumbers
  • PhoneNumberOfflineGeocoder
  • PhoneNumberToTimeZonesMapper
  • PhoneNumberToCarrierMapper

🔧 Install

libphonenumbers is available on npm. It can be installed with the following command:

npm install libphonenumbers --save

libphonenumbers is available on yarn as well. It can be installed with the following command:

yarn add libphonenumbers

💡 Usage

🎀 PhoneNumberUtil

format(number, numberFormat)

Using Standard JavaScript:

const PNF = require('libphonenumbers').PhoneNumberFormat;
// Create an instance of PhoneNumberUtil
const phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance(); 

const number = phoneUtil.parseAndKeepRawInput('300-577-8989', 'US');

// Format number in the RFC3966 format
console.log(phoneUtil.format(number, PNF.RFC3966));
// => tel:+1-300-577-8989

// Format number in the national format
console.log(phoneUtil.format(number, PNF.NATIONAL));
// => (300) 577-8989

// Format number in the international format
console.log(phoneUtil.format(number, PNF.INTERNATIONAL));
// => +1 300-577-8989

Using ECMAScript (ES):

import libphonenumbers from 'libphonenumbers';

const PNF = libphonenumbers.PhoneNumberFormat;

// Create an instance of PhoneNumberUtil
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();

const number = phoneUtil.parseAndKeepRawInput('300-577-8989', 'US');

// Format number in the RFC3966 format
console.log(phoneUtil.format(number, PNF.RFC3966));
// => tel:+1-300-577-8989

// Format number in the national format
console.log(phoneUtil.format(number, PNF.NATIONAL));
// => (300) 577-8989

// Format number in the international format
console.log(phoneUtil.format(number, PNF.INTERNATIONAL));
// => +1 300-577-8989

🦄 Credit and Inspiration

Inspired by Google's libphonenumber.

⚖️ License

The MIT License License: MIT

Keywords

FAQs

Package last updated on 20 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc