npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@arctics/google-phonelib

v0.2.0-dev

Published

A JavaScript/TypeScript package providing wrapper for Google's libphonenumber library

Downloads

78

Readme

@arctics/google-phonelib (beta)

license npm latest package npm downloads Checks Build CI install size npm bundle size Known Vulnerabilities

Table of Contents

  1. Introduction
  2. Features
  3. Installation
  4. Usage
  5. API
  6. Notes
  7. Contributing
  8. License

Introduction

This package simplifies phone number handling by wrapping Google's libphonenumber. While offering complete access to i18n.phonenumbers.PhoneNumber and i18n.phonenumbers.PhoneNumberUtil through getParsedPhoneNumber() and getPhoneNumberUtil(), it prioritizes ease of use. The constructor and getPhoneNumberInfo() provide a quick way to perform common tasks and access essential information. Designed to abstract frequently used features, this package welcomes user feedback and encourages feature requests.

Features

  • Phone Number Parsing:
    • Parses phone numbers from various formats into a structured IPhoneNumber object.
    • Supports parsing with or without keeping the raw input.
    • Handles lenient parsing, allowing for punctuation, whitespace, and leading text.
  • Phone Number Formatting:
    • Formats parsed phone numbers into E.164, international, national, and RFC3966 formats.
    • Formats numbers in their original format.
  • Phone Number Information Retrieval:
    • Retrieves detailed information about a phone number, including:
      • Country code.
      • National number.
      • Number type (mobile, fixed-line, etc.).
      • Validity checks (possible, valid, valid for region).
      • Raw Input.
      • Region Code.
      • Extension.
  • Phone Number Type Detection:
    • Identifies the type of phone number (mobile, fixed-line, toll-free, etc.).
  • Validation:
    • Checks if a number is valid, possible, and valid for a region.
  • As-You-Type Formatting:
    • Formats phone numbers in real-time as they are being typed.
    • Clears the input in the formatter.
  • TypeScript Support:
    • Provides type definitions for enhanced development experience.
  • Future Features:
    • ShortNumberInfo will be added in future releases.

Installation

npm install @arctics/google-phonelib

or

yarn add @arctics/google-phonelib

Usage

import {
  PhoneNumberHandler,
  PhoneNumberFormat,
  AsYouTypeHandler,
} from '@arctics/google-phonelib';

// Parsing and retrieving information
const handler = new PhoneNumberHandler('+12025550100', 'US');
const info = handler.getPhoneNumberInfo();

console.log(info.nationalNumber); // Output: 2025550100
console.log(info.countryCode); // Output: 1
console.log(info.numberType); // Output: FIXED_LINE_OR_MOBILE

// Formatting
const formattedNational = handler.format(PhoneNumberFormat.NATIONAL);
console.log(formattedNational); // Output: (202) 555-0100

const formattedE164 = handler.format(PhoneNumberFormat.E164);
console.log(formattedE164); // Output: +12025550100

//Original formatting
const originalFormat = handler.formatInOriginalFormat('US');
console.log(originalFormat);

// AsYouTypeHandler usage
const asYouTypeHandler = new AsYouTypeHandler('US');
console.log(asYouTypeHandler.typeNumber('202')); // Output: 202
console.log(asYouTypeHandler.typeNumber('555')); // Output: 202-555
console.log(asYouTypeHandler.typeNumber('0100')); // Output: (202) 555-0100
asYouTypeHandler.clearInput();

API

PhoneNumberHandler Class

  • Constructor:

    • constructor(phoneNumber: string, regionCode: string, mode?: string)

      • Creates a new PhoneNumberHandler instance.
      • phoneNumber: The phone number string to parse.
      • regionCode: The region code (e.g., 'US', 'GB').
      • mode: Parsing mode ('parse' or 'parseAndKeepRawInput'). Defaults to 'parseAndKeepRawInput'.
  • Methods:

    • getParsedPhoneNumber(): IPhoneNumber | null
      • Returns the parsed IPhoneNumber object.
    • getPhoneNumberUtil(): IPhoneNumberUtil
      • Returns the PhoneNumberUtil instance.
    • format(numberFormat: NumberFormat): string
      • Formats the phone number according to the specified NumberFormat (E164, INTERNATIONAL, NATIONAL, RFC3966).
    • formatInOriginalFormat(regionCallingFrom: string): string
      • Formats the phone number in its original format.
    • formatOutOfCountryCallingNumber(regionCallingFrom: string): string
      • Formats a phone number for out-of-country dialing purposes.
    • getPhoneNumberInfo(): IPhoneNumberInfo
      • Returns an object containing detailed information about the phone number.

AsYouTypeHandler Class

  • Constructor:

    • constructor(regionCode: string)

      • Creates a new AsYouTypeHandler instance.
      • regionCode: The region code for formatting the phone number.
  • Methods:

    • typeNumber(phoneNumber: string): string
      • Formats the phone number as you type.
      • phoneNumber: The phone number to format.
      • Returns the formatted phone number.
    • clearInput(): void
      • Clears the input in the formatter.

Enums & Interfaces

  • PhoneNumberType Enum

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

    • E164
    • INTERNATIONAL
    • NATIONAL
    • RFC3966
  • CountryCodeSource Enum

    • FROM_DEFAULT_COUNTRY
    • FROM_NUMBER_WITHOUT_PLUS_SIGN
    • FROM_NUMBER_WITH_IDD
    • FROM_NUMBER_WITH_PLUS_SIGN
    • UNSPECIFIED
  • Interfaces

    • IPhoneNumber
    • IPhoneNumberInfo
    • IPhoneNumberUtil

    (Refer to the source code for detailed interface definitions.)

Notes

Unavailable methods and classes

The following methods or classes are unavailable on the original JS port of Google's libphonenumber:

  • findNumbers - finds numbers in text (useful for highlighting or linking phone numbers inside text messages).
  • PhoneNumberOfflineGeocoder - provides geographical information related to a phone number.
  • PhoneNumberToCarrierMapper - provides carrier information related to a phone number.
  • PhoneNumberToTimeZonesMapper - provides timezone information related to a phone number.

Metadata issues

Most of the issues submitted to this repository are related to carrier metadata - things like unexpected phone validations, errors in formatting numbers, unknown carriers and so on.

First, try the same input using the official demo page. If the result is different, then it might mean that a metadata update is due on this package, as the demo page always runs on the latest and official metadata version.

If the result is the same, it means there might be an issue with the currently available metadata. In that case, you should report your issue in the original project's issue tracker (moved out of GitHub on 05/12/2017).

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This package is licensed under MIT License.

The bundled libphonenumber library is licensed under Apache 2.0.