A dead-simple npm package to format inputted phone numbers strings into pretty, readable, presentable, and useful strings.
npm install phone-formatsA dead-simple and easy-to-use package to format inputted phone numbers strings into pretty, readable, presentable, and useful strings. No bloat.
| Format Key | Preview |
| --------------- | ----------------- |
| LOCAL | 832-3096 |
| DOMESTIC | (239) 832-3096 |
| INTERNATIONAL | +1 (239) 832-3096 |
| E.164 | +12398323096 |
> Pro-tip: If the key is misspelled, left blank, or invalid, it defaults to DOMESTIC.
---
``bash`
npm install phone-formats
`bash`
yarn add phone-formats
`html`
`js`
import { format as phoneFormat } from "phone-formats";
`js`
var { format: phoneFormat } = require("phone-formats");
> Pro-tip: You can replace phoneFormat with any word/variable of your choosing, or omit it entirely and use format .
`js`
phoneFormat(phone, key);
`js
var formatted = phoneFormat(2398323096);
console.log(formatted);
// > (239) 832-3096
`
`jsLOCAL
var formatted = phoneFormat(8323096, );
console.log(formatted);
// > 832-3096
`
`jsDOMESTIC
var formatted = phoneFormat(2398323096, );
console.log(formatted);
// > (239) 832-3096
`
`js+12398323096
var formatted = phoneFormat(, INTERNATIONAL);
console.log(formatted);
// > +1 (239) 832-3096
`
`jsrandom-+1239-word-83230-test-96
var formatted = phoneFormat(, INTERNATIONAL);
console.log(formatted);
// > +1 (239) 832-3096
`
`jsreact
import { useState } from phone-formats
import { format as phoneFormat } from
export default function Example() {
var [phone, setPhone] = useState()
return (
<>
type='text'
value={phone}
onChange={(e) => setPhone(e.target.value)}
/>
{phoneFormat(phone)}
- GitHub
- npm
- Discord
- Sebastian Alsina