gwl-number-formatter
v1.1.1
Published
A package to format phone number in various formats.
Downloads
2
Maintainers
Readme
gwl-number-formatter
It is a package to format a phone number in various formats.
Install
npm i gwl-number-formatter
Why
To format the input contact numbers in various formats as follow-:
xxxxxxxxxx
(xxx) xxx-xxxx
xxx-xxx-xxxx
(xxx)xxx-xxxx
(xxx)-xxx-xxxx
xxx.xxx.xxxx
xxx xxx xxxx
Usage
import {phoneNumberFormatter} from "gwl-number-formatter";
phoneNumberFormatter(contact_number,'2')
.then((formattedNumber) => {
// contact_number is your input value.
if (formattedNumber !== undefined) {
var contact = formattedNumber; //In this case "contact" value would be (xxx) xxx-xxxx as second param is '2'.
}
})
.catch((error) => {
console.error('Error formatting phone number:', error);
});
Formats
For various formats, pass the second parameter values between 1-7.
phoneNumberFormatter(contact_number,'1')
.then((formattedNumber) => {
var contact = formattedNumber;
// OUTPUT -:
// contact = xxxxxxxxxx
})
phoneNumberFormatter(contact_number,'2')
.then((formattedNumber) => {
var contact = formattedNumber;
// OUTPUT -:
// contact = (xxx) xxx-xxxx
})
phoneNumberFormatter(contact_number,'3')
.then((formattedNumber) => {
var contact = formattedNumber;
// OUTPUT -:
// contact = xxx-xxx-xxxx
})
phoneNumberFormatter(contact_number,'4')
.then((formattedNumber) => {
var contact = formattedNumber;
// OUTPUT -:
// contact = (xxx)xxx-xxxx
})
phoneNumberFormatter(contact_number,'5')
.then((formattedNumber) => {
var contact = formattedNumber;
// OUTPUT -:
// contact = (xxx)-xxx-xxxx
})
phoneNumberFormatter(contact_number,'6')
.then((formattedNumber) => {
var contact = formattedNumber;
// OUTPUT -:
// contact = xxx.xxx.xxxx
})
phoneNumberFormatter(contact_number,'7')
.then((formattedNumber) => {
var contact = formattedNumber;
// OUTPUT -:
// contact = xxx xxx xxxx
})