Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
phone-fns
Advanced tools
Changelog
v4.0.1
isValid
and breakdown
Readme
A small modern, and functional phone number library which gathers inspiration from the fun date-fns library
[!NOTE] Currently Phone-Fns is focused on US based phone numbers, I am happy to welcome contributions to internationalize the library!
npm i phone-fns
Standard module system
import * as phoneFns from 'phone-fns'
phoneFns.uglify('555-444-3333') // => '5554443333'
Common JS
const phoneFns = require('phone-fns')
phoneFns.uglify('555-444-3333') // => '5554443333'
Using Unpkg or jsdelivr CDN (As of v4.0.0+)
<script src="https://cdn.jsdelivr.net/npm/phone-fns@4.0.0/dist/phone-fns.iife.min.js"></script>
<script>
phoneFns.uglify('555-444-3333') // => '5554443333'
</script>
Through the browser
<script src="path/to/location/dist/phone-fns.iife.min.js"></script>
<script>
phoneFns.uglify('555-444-3333') // => '5554443333'
</script>
import * as phoneFns from 'phone-fns'
phoneFns.breakdown('4443332222')
// => { areaCode: '444', localCode: '333', lineNumber: '2222', extension: '' }
phoneFns.format('(NNN) NNN-NNNN', '4443332222')
// => '(444) 333-2222'
You can also destructure to only use the functions you want
import { breakdown, format } from 'phone-fns'
breakdown('4443332222')
// => { areaCode: '444', localCode: '333', lineNumber: '2222', extension: '' }
format('(NNN) NNN-NNNN', '4443332222')
// => '(444) 333-2222'
Phone-Fns as of v3.2.0 now supports placeholder syntax using Underscores _
const fn = format('NNN-NNN-NNNN')
fn('__________') // => '___-___-____'
fn('444_______') // => '444-___-____'
fn('444555____') // => '444-555-____'
fn('4445556666') // => '444-555-6666'
format('NNN-NNN-NNNN x NNNN', '5554443333____') // => '555-444-3333 x ____'
This will only work with underscores or other characters not picked up by the Regex \W
type.
Just call format as the phone number updates in order to get back the newly updated string. Useful for using it with a input mask setup
FAQs
A small, modern, and functional phone library for javascript
The npm package phone-fns receives a total of 3,107 weekly downloads. As such, phone-fns popularity was classified as popular.
We found that phone-fns 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.