Phone-Fns

Functions

breakdown(phone) → {Object}

Source:
Since:
  • v0.1.0
Category:
  • Function
Signature:
  • String -> String -> Object

Takes a provided phone string and breaks it down into an object of codes

Example
breakdown('111-222-3333');
// => { areaCode: '111', localCode: '222', lineNumber: '3333', extension: '' }

breakdown('5554441111');
// => { areaCode: '555', localCode: '444', lineNumber: '1111', extension: '' }

breakdown('555-444-3333 x 8989');
// => { areaCode: '555', localCode: '444', lineNumber: '3333', extension: '8989' }

// Works with placeholder syntax
breakdown('555-___-____')
// => { areaCode: '555', localCode: '___', lineNumber: '____', extension: '' }
Parameters:
Name Type Description
phone String

The phone number to breakdown

Returns:

Returns an object of the broken down phone number

Type
Object

format(layout, phone) → {String}

Source:
Since:
  • v0.1.0
Category:
  • Function
Signature:
  • String -> String -> String

Allows you to format phone numbers however you desire using N as number placeholders and C as country code placeholders these placeholders are case insensitive

Example
format('(NNN) NNN.NNNN', '444-555-6666') // => '(444) 555.6666'
format('C + (NNN) NNN.NNNN', '1444-555-6666') // => '1 + (444) 555.6666'
format('CC + NNN.NNN.NNNN', '163334445555') // => '16 + 333.444.5555'
format('(NNN) NNN.NNNN x NNNN', '44455566668989') // => '(444) 555.6666 x 8989'

// Format is case insensitive
format('(NNN) nnn-NNnn', '4445556666') // => (444) 555-6666

// Format is also curried
const fn = format('NNN.NNN.NNNN')

fn('4445556666') // => '444.555.6666'
fn('(333) 444-5555') // => '333.444.5555'
Parameters:
Name Type Description
layout String

The desired layout of the phone number

phone String

The phone number to breakdown

Returns:

Returns a string which is the formatted phone number

Type
String

isValid(phone) → {Boolean}

Source:
Since:
  • v0.1.0
Category:
  • Function
Signature:
  • String -> Boolean

Validates the base number, does not take the country code or extension into consideration for this validation

Example
isValid('555-444-3333') // => true
isValid('5555') // => false
Parameters:
Name Type Description
phone String

The phone number to breakdown

Returns:

Returns a boolean if the number provided is valid or not

Type
Boolean

uglify(phone) → {String}

Source:
Since:
  • v0.1.0
Category:
  • Function
Signature:
  • String -> String

Strips all of the special characters from the given string

Example
uglify('555-444-3333') // => '5554443333'
uglify('5554443333') // => '5554443333'
Parameters:
Name Type Description
phone String

The phone number to trim and strip down

Returns:

Returns the newly created phone number string

Type
String