Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
google-libphonenumber
Advanced tools
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 lightweight wrapper for Google's libphonenumber
, a library used by the Android Framework since version 4.0 to parse, format, store and validate international phone numbers. Based on mattbornski's fork.
$ npm install --save google-libphonenumber
var PNF = require('google-libphonenumber').PhoneNumberFormat;
var phoneUtil = require('google-libphonenumber').phoneUtil;
var phoneNumber = phoneUtil.parse('202-456-1414', 'US');
var result = phoneUtil.format(phoneNumber, PNF.INTERNATIONAL);
console.log('Result is', result);
// Result is +1 202-456-1414
libphonenumber
's repository (currently r679
) without any svn metadata:$ svn export http://libphonenumber.googlecode.com/svn/trunk/javascript/i18n/phonenumbers lib/closure/goog/i18n/phonenumbers --force
$ chmod +x node_modules/seegno-closure-library/closure/bin/build/depswriter.py
$ node_modules/seegno-closure-library/closure/bin/build/depswriter.py --root_with_prefix="./lib/closure/goog ../../../../lib/closure/goog" > ./lib/closure/goog/deps.js
This project uses a fork of closure-library
that has been published to npm. The package is maintained by Seegno and receives regular updates.
If you absolutely need to update to the latest closure-library
version you may have to fork the seegno-closure-library
and follow the README's instructions on how to rebase with the upstream repository. This is unlikely to happen because libphonenumber
uses a very small and stable set of closure dependences (only string
, array
, proto2
).
Push the changes to your fork and add the following lines to your project's package.json
:
"dependencies": {
"seegno-closure-library": "git://github.com/<username>/closure-library#<commit-sha1,branch,tag>"
}
Run npm install
and after a successfull install, this library should pick that version instead.
Alternatively, you may publish your own version of closure-library
to npm and use it that one instead.
google-closure
module to facilitate version tracking and control.google-closure
's own node.js wrapper.google-closure
's dependency management system to manange libphonenumber
dependencies.libphonenumber
revisions by simplying the update process.libphonenumber
.The javascript port of libphonenumber
throws errors as string, e.g. throw "Invalid country code"
. As Guillermo Rauch puts it, a string is not an error so, in an attempt to avoid future issues when developing an application, this module converts all string-based errors that occur on the PhoneNumberUtil
class to instances of Error
.
A small subset of tests guarantees that the main library functions are working as expected and are correctly exposed. The actual heavy lifting is done by libphonenumber
's extensive test suite.
$ npm test
The original library wrapper was created by Socialcam who first got it working on node.js and which was then improved by mattbornski. This package would not exist without the work of these previous contributions.
The exceptional work on libphonenumber
was made possible by these committers and contributors.
MIT
FAQs
The up-to-date and reliable Google's libphonenumber package for node.js.
The npm package google-libphonenumber receives a total of 874,371 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.