phonedrawer
v0.0.6
Published
The most minimalistic way to format phone numbers by a string pattern
Downloads
13
Maintainers
Readme
phonedrawer
The most minimalistic way to format phone numbers by a string pattern
Motivation
What if we don't need no input mask and the only goal is to format phone numbers in a specific way? There is an extreamely lightweight and simple solution right for that case!
Usage with example
yarn
yarn add phonedrawer
npm
npm i -s phonedrawer
Then in your code
import { Config, Phonedrawer } from 'phonedrawer'
const config: Config = {
'+7XXXXXXXXXX': '+7 XXX XXX XX XX',
'+44XXXXXXXXXX': '+44 XXXX XXXXXX'
}
const phonedrawer = new Phonedrawer(config)
phonedrawer.format('+79998887766') -> '+7 999 888 77 66'
phonedrawer.format('+448888666666') -> '+44 8888 6666666'
phonedrawer.format('+44888866666693469_and_something_longer_than_pattern') -> '+44 8888 6666666' // still
phonedrawer.format('+3369346824') -> '+3369346824' // no pattern -> no formatting