phone-parser
v0.0.2
Published
Parse the phone input into an output format of your choice. Good for formatting a user input.
Downloads
94
Readme
Phone Parser
Parse the phone input into an output format of your choice. Good for formatting a user input.
Installation
$ component install chenglou/phone-parser
API
'x'
represents a digit placeholder.
var phoneParser = require('phone-parser');
phoneParser('2341234447', '(xxx) xxx-xxxx'); // Returns '(234) 123-4447'.
phoneParser('+86 455 6988', 'xxxxxxxxx'); // Returns '864556988'.
phoneParser(' 123 4567 ', '+1 xxx xxxx'); // Returns '+1 123 4567'.
phoneParser('123 4567890', '+1 xxx xxxx'); // Error: phone format cannot be parsed.
Remember, only 'x'
is a placeholder. The rest is treated as part of the formatting.
Testing
Using npm:
If you haven't installed jasmine-node and CoffeeScript:
$ npm install
Then:
$ npm test
License
MIT.