Registry / productivity / phone-formatter

phone-formatter

JSON →
library0.0.2jsnpmunverified

Phone-formatter is a minimal Node.js library (v0.0.2, last updated 2013) for normalizing and formatting US-centric telephone numbers. It provides two methods: normalize() strips non-digits and leading country codes, returning 10 digits; format() renders a 10-digit string into arbitrary formats using 'N' placeholders. The library is simple but unmaintained, lacks international support, and has no TypeScript types, testing, or active development. It is suitable for legacy projects only.

npm install phone-formatter
INSTALL
IMPORT
SIG · PHONE-FORMATTER
P
phone-formatter
productivityjavascriptv0.0.2
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 does not support ESM imports. Use CommonJS require().
normalize
phoneFormatter.normalize('(212) 555-1212');
phoneFormatter.normalize(2125551212);
Argument must be a string, not a number.
format
phoneFormatter.format('2125551212', '(NNN) NNN-NNNN');
phoneFormatter.format('2125551212', '(AAA) AAA-AAAA');
Placeholders must be 'N', not other letters.

Demonstrates normalize, format, and combined usage with options object.

const phoneFormatter = require('phone-formatter'); // Normalize a phone number to 10 digits const normalized = phoneFormatter.normalize('+1 (212) 555-1212'); console.log(normalized); // "2125551212" // Format a 10-digit string const formatted = phoneFormatter.format('2125551212', '(NNN) NNN-NNNN'); console.log(formatted); // "(212) 555-1212" // Normalize and format in one step const both = phoneFormatter.format('(212) 555-1212', 'NNN.NNN.NNNN', { normalize: true }); console.log(both); // "212.555.1212"
Debug
Known issues
deprecatedThis package is unmaintained since 2013 and may not work with modern Node.js versions.
fix
Migrate to a maintained alternative like google-libphonenumber.
affects: *
gotchaNormalize may return fewer than 10 digits for non-US numbers (e.g., '+45 (212) 555-1212' returns '2125551212', dropping country code).
fix
Do not use for international numbers; only US numbers are reliably handled.
affects: all
gotchaFormat() expects exactly 10 digits; passing fewer digits will produce unexpected results.
fix
Ensure input has exactly 10 numeric characters before formatting.
affects: all
gotchaNo TypeScript definitions included; users must create their own .d.ts or use @ts-ignore.
fix
Install @types/phone-formatter if available (none published) or declare module manually.
affects: all
Errors
Common errors & fixes
TypeError: phoneFormatter.normalize is not a function
Using ESM import syntax on a CommonJS-only package.
fix
Use const phoneFormatter = require('phone-formatter'); instead of import.
phoneFormatter.format is not a function
Same as above: incorrect import style or missing require.
fix
Ensure you are using require('phone-formatter') in a CommonJS context.
Expected 10 digits, got 11
Phone number includes leading '1' (country code) not stripped by normalize.
fix
Use normalize first, then check length; if 11 digits, slice(1) to remove country code.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

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