Registry / productivity / node-phone-formatter

node-phone-formatter

JSON →
library0.0.4jsnpmunverified

A lightweight Node.js library for parsing and formatting phone numbers. Current stable version is 0.0.4 (last updated 2013). It provides two simple methods: normalize() to strip formatting from phone numbers, and format() to output phone numbers in a custom format using "N" placeholders. It can handle many US-centric formats but has limited international support. The library is minimal and has no external dependencies.

npm install node-phone-formatter
INSTALL
IMPORT
SIG · NODE-PHONE-FORMATT
N
node-phone-formatter
productivityjavascriptv0.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

phoneFormatter
const phoneFormatter = require('phone-formatter');
import phoneFormatter from 'phone-formatter';
This package is CommonJS only. ESM import will fail.
normalize
phoneFormatter.normalize('212.555.1212');
phoneFormatter.normalize('212-555-1212', {format: 'NNN.NNN.NNNN'});
normalize() only takes a phone number string, no options.
format
phoneFormatter.format('2125551212', '(NNN) NNN-NNNN');
phoneFormatter.format('(212) 555-1212', 'NNN.NNN.NNNN', {normalize: false});
Using {normalize: false} with non-normalized input may crash.

Demonstrates how to normalize a phone number and then format it with a custom pattern.

const phoneFormatter = require('phone-formatter'); const raw = '212.555.1212'; const normalized = phoneFormatter.normalize(raw); console.log(normalized); // '2125551212' const formatted = phoneFormatter.format(normalized, '(NNN) NNN-NNNN'); console.log(formatted); // '(212) 555-1212'
Debug
Known issues
deprecatedPackage has not been updated since 2013 and is effectively abandoned.
fix
Use a maintained alternative like libphonenumber-js or google-libphonenumber.
affects: >=0.0.0
breakingESM import will fail because the package only exports a CommonJS module.
fix
Use require() or wrap in a dynamic import.
affects: >=0.0.0
gotchanormalize() removes all non-digit characters, including leading '+' for country codes.
fix
Format with country code separately if needed.
affects: >=0.0.0
gotchaformat() with {normalize: false} on non-normalized input may produce unexpected results or errors.
fix
Always ensure input is normalized or omit the option.
affects: >=0.0.0
gotchaInternational numbers (non-US) may not be handled correctly.
fix
Use a library with full international support.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: phoneFormatter.normalize is not a function
Using ES6 import syntax which fails for CommonJS module.
fix
Use: const phoneFormatter = require('phone-formatter');
undefined is not a valid phone number
Passing undefined or null to normalize or format.
fix
Check input: phoneFormatter.normalize(input || '');
Upgrade
Version history
0.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
node-phone-formatter — npm install node-phone-formatter · libregistry