Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
google-libphonenumber
Advanced tools
The up-to-date and reliable Google's libphonenumber package for node.js.
The google-libphonenumber npm package is a JavaScript port of Google's libphonenumber library, which provides robust tools for parsing, formatting, and validating international phone numbers. It is designed to help developers work with phone numbers in various formats and provides functionalities such as number validation, formatting numbers for display, and extracting possible number types.
Parsing and validating phone numbers
This feature allows you to parse a phone number from a string and validate whether it is a possible number. The example demonstrates parsing and validating a US phone number.
const { PhoneNumberUtil } = require('google-libphonenumber');
const phoneUtil = PhoneNumberUtil.getInstance();
const number = phoneUtil.parseAndKeepRawInput('202-456-1111', 'US');
const isValid = phoneUtil.isValidNumber(number);
Formatting phone numbers
This feature enables the formatting of parsed phone numbers into various formats, such as international and national formats. The code sample shows how to format a US phone number into an international format.
const { PhoneNumberFormat, PhoneNumberUtil } = require('google-libphonenumber');
const phoneUtil = PhoneNumberUtil.getInstance();
const number = phoneUtil.parse('2024561111', 'US');
const formattedNumber = phoneUtil.format(number, PhoneNumberFormat.INTERNATIONAL);
Getting the type of a number
This functionality allows you to determine the type of a phone number (e.g., mobile, fixed-line). The example demonstrates how to parse a US phone number and get its type.
const { PhoneNumberType, PhoneNumberUtil } = require('google-libphonenumber');
const phoneUtil = PhoneNumberUtil.getInstance();
const number = phoneUtil.parse('202-456-1111', 'US');
const numberType = phoneUtil.getNumberType(number);
Similar to google-libphonenumber, awesome-phonenumber provides functionalities for parsing, validating, and formatting international phone numbers. It is lighter and has a simpler API, but might not be as comprehensive in terms of number validation rules and country coverage.
libphonenumber-js is another alternative that offers parsing, formatting, and validation of phone numbers. It aims to be a smaller and faster implementation compared to google-libphonenumber, by focusing on the most common use cases and dropping some of the less frequently used features.
A browserify-compatible wrapper for Google's libphonenumber, a library to parse, format, store and validate international phone numbers. Zero dependencies, always up-to-date.
Install the package via npm
:
npm install google-libphonenumber --save
Here's a simple example on how to format a US-based number in the international phone number format:
// Require `PhoneNumberFormat`.
var PNF = require('google-libphonenumber').PhoneNumberFormat;
// Get an instance of `PhoneNumberUtil`.
var phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
// Parse number with country code.
var phoneNumber = phoneUtil.parse('202-456-1414', 'US');
// Print number in the international format.
console.log(phoneUtil.format(phoneNumber, PNF.INTERNATIONAL));
// => +1 202-456-1414
// Require `AsYouTypeFormatter`.
var AsYouTypeFormatter = require('google-libphonenumber').AsYouTypeFormatter;
var formatter = new AsYouTypeFormatter('US');
console.log(formatter.inputDigit('6')); // => 6
console.log(formatter.inputDigit('5')); // => 65
console.log(formatter.inputDigit('0')); // => 650
console.log(formatter.inputDigit('2')); // => 650-2
console.log(formatter.inputDigit('5')); // => 650-25
console.log(formatter.inputDigit('3')); // => 650-253
console.log(formatter.inputDigit('2')); // => 650-2532
console.log(formatter.inputDigit('2')); // => (650) 253-22
formatter.clear();
libphonenumber
are exported as-is. No magic methods.google-closure
library version available from Google with performance and bug fixes.libphonenumber
library always up-to-date.A small subset of tests guarantees that the main library functions are working as expected and are correctly exported. The actual heavy lifting is done by libphonenumber
's extensive test suite.
npm test
npm version [<newversion> | major | minor | patch] -m "Release %s"
The exceptional work on libphonenumber
was made possible by these committers and contributors.
This package is licensed under MIT. The bundled libphonenumber library is licensed under Apache 2.0.
FAQs
The up-to-date and reliable Google's libphonenumber package for node.js.
The npm package google-libphonenumber receives a total of 549,744 weekly downloads. As such, google-libphonenumber popularity was classified as popular.
We found that google-libphonenumber demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.