Socket
Book a DemoInstallSign in
Socket

phone-number-formats

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phone-number-formats

Format phone numbers

latest
Source
npmnpm
Version
2.2.1
Version published
Weekly downloads
419
-23.4%
Maintainers
1
Weekly downloads
 
Created
Source

Phone Number Formats

Easy way to format and convert phone numbers now with method chaining and custom types

Install

$ npm install phone-number-formats

Usage

const phoneNumberFormatter = require('phone-number-formats');

let home = new phoneNumberFormatter('1234567').format();
// 123-4567

let work = new phoneNumberFormatter('3-141-592-6535').format({type: 'domestic'});
// (141) 592-6535

let boss = new phoneNumberFormatter('18008675309').format({type: 'international', separator: '.'});
// +1.800.867.5309

let drew = new phoneNumberFormatter('+1 (800) 271-WHAT').format({type: 'international', areaCode: '996'}).convert();
// +996 (800) 271-8281

API

format

Format the number to local, domestic, international, or a custom type

let number = new phoneNumberFormatter('18001234567');
number.format({type: 'international', areaCode: '996', separator: '.', letters: true});
// +996.(800).123.4567

convert

Convert any letters to numbers

let number = new phoneNumberFormatter('123WHAT');
number.convert();
// 1239428

toString

Get phone number as a string

addType

Add new type to be used in format method

// The X's signify numbers and the Y's signify the area code by default
phoneNumberFormatter.addType('china', '0 +YYY XXX-XXX');
number = new phoneNumberFormatter('314159').format({type: 'china', areaCode: '591'});
// 0 +591 314-159

// Different letters or symbols can be used as delimiters
phoneNumberFormatter.addType('x-ray', '(VVV) WWW-XRAY', {number: 'W', areaCode: 'V'});
number = new phoneNumberFormatter('314159').format({type: 'x-ray'});
// (314) 159-XRAY

getType

Gets the key for any default or custom type

phoneNumberFormatter.getType('china');
// 0 +YYY XXX-XXX

Examples

See test.js for examples

License

MIT

FAQs

Package last updated on 07 May 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