phone-parser

Parse the phone input into an output format of your choice. Good for formatting a user input.

Phone Parser

Parse the phone input into an output format of your choice. Good for formatting a user input.

$ component install chenglou/phone-parser

'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.

Using npm:

If you haven't installed jasmine-node and CoffeeScript:

$ npm install

Then:

$ npm test

MIT.