breakdown(phone) → {Object}

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

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

Parameters

NameTypeDescription
phoneStringThe phone number to breakdown

Returns

TypeDescription
ObjectReturns an object of the broken down phone number
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: '' }

format(layout, phone) → {String}

Since:
  • v0.1.0
Kind:
  • function
Source:
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

Parameters

NameTypeDescription
layoutStringThe desired layout of the phone number
phoneStringThe phone number to breakdown

Returns

TypeDescription
StringReturns a string which is the formatted phone number
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'

isValid(phone) → {Boolean}

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

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

Parameters

NameTypeDescription
phoneStringThe phone number to breakdown

Returns

TypeDescription
BooleanReturns a boolean if the number provided is valid or not
isValid('555-444-3333') // => true
isValid('5555') // => false

uglify(phone) → {String}

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

Strips all of the special characters from the given string

Parameters

NameTypeDescription
phoneStringThe phone number to trim and strip down

Returns

TypeDescription
StringReturns the newly created phone number string
uglify('555-444-3333') // => '5554443333'
uglify('5554443333') // => '5554443333'