Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

phone-fns

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phone-fns

Silly simple phone functional library

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.3K
increased by1.97%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

phone-fns

A small modern, and functional phone number library which gather inspiration from the fun date-fns library

How-To

Standard module system

import { format } from 'phone-fns';

format(phone, layout);

Common JS

const { format } = require('phone-fns');

format(phone, layout);

Through the browser

<script src="path/to/location/dist/phone-fns.umd.js"></script>
phoneFns.format(phone, layout);

Methods

uglify(phone)

uglifies the phone number down to just the number string

Arguments
  • phone - String: the desired phone number to run against
Usage
import {uglify} from 'phone-fns';

console.log(uglify('555-444-1111'));
// Output: 5554441111

format(phone, format, isLD)

Customized formatting function allowing you to create your own custom formats

Arguments
  • phone - String: The desired phone number to run against
  • format - String: The desired format to set the number into, see above
  • isLD - Boolean: Tell the function to run the long distance rule
Formatting
  • A - Area Code Number
  • L - Local Code Number (Usually the first three digits)
  • N - Line Number (Usually the last four digits)
  • E - Extension Number (Usually an additional set of digits at the end)
  • C - Country Code Number (Usually the set of digits that go ahead of a number)
Usage
import { format } from 'phone-fns';

// Normal
format('4443332222', '(AAA) LLL-NNNN');
// Output: (444) 333-2222

// Long Distance
format('1124443332222', 'CCC + (AAA)-LLL.NNNN', true); // <-- Notice we have to make sure to tell the module we it is long distance
// Output: 112 + (444)-333.2222

// Extensions
format('44433322228989', '(AAA).LLL.NNNN x EEEE');
// Output: (444).333.2222 x 8989

find(phone, code)

Find a piece of the phone number and return it

Arguments
  • phone - String: the desired phone number to run against
  • code - String: the piece of the phone number to return can be areaCode, localCode, lineNumber, countryCode, or extension
Usage
import { find } from 'phone-fns';

console.log(find('555-444-3333', 'areaCode'));
// Output: 555

breakdown(phone, isLD)

Takes the provided phone string and breaks it down into an object like so:

{
  countryCode: '',
  areaCode: '',
  localCode: '',
  lineNumber: '',
  extension: ''
}
Arguments
  • phone - String: the desired phone number to run against
  • isLD - Boolean: tell the function if the phone is using a long distance style or not
Usage
import { breakdown } from 'phone-fns';

console.log(breakdown('555-444-3333'));
// Output:
/*
{
  countryCode: '',
  areaCode: '555',
  localCode: '444',
  lineNumber: '3333',
  extension: ''
}
*/

console.log(breakdown('112555-444-3333', true));
// Output:
/*
{
  countryCode: '112',
  areaCode: '555',
  localCode: '444',
  lineNumber: '3333',
  extension: ''
}
*/

console.log(breakdown('555-444-33338989'));
// Output:
/*
{
  countryCode: '',
  areaCode: '555',
  localCode: '444',
  lineNumber: '3333',
  extension: '8989'
}
*/

isValid(phone)

Validates if the phone number is valid or not

Arguments
  • phone - String: the desired phone number to run against
Usage
import { isValid } from 'phone-fns';

console.log(isValid('555-444-3333'));
// Output: true
console.log(isValid('8896'));
// Output: false

identical(x, y)

Validates if the phone number is valid or not

Arguments
  • x - String: the desired phone number to run against y
  • y - String: the desired phone number to run against x
Usage
import { identical } from 'phone-fns';

console.log(identical('555-444-3333', '555-444-3333'));
// Output: true
console.log(identical('555-444-3333', '555-333-4444'));
// Output: false

Keywords

FAQs

Package last updated on 31 Oct 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc