📅  最后修改于: 2023-12-03 14:59:25.948000             🧑  作者: Mango
awesome-phonenumber
is a JavaScript library that can be used to validate, format, and parse phone numbers from around the world.
You can install awesome-phonenumber
using npm:
npm install awesome-phonenumber
To use awesome-phonenumber
, you first need to create a PhoneNumber
object:
const PhoneNumber = require('awesome-phonenumber');
const number = new PhoneNumber('+1 (123) 456-7890');
Once you have a PhoneNumber
object, you can perform various operations on it:
number.isValid(); // true
number.getNumber('e164'); // '+11234567890'
number.getNumber('national'); // '(123) 456-7890'
number.getNumber('international'); // '+1 123-456-7890'
const number2 = PhoneNumber.parse('123-456-7890', 'US');
number2.getNumber('e164'); // '+14123456789'
number.getCountryCode(); // 1
number.getLocalNumber(); // '123-456-7890'
number.getInternationalNumber(); // '+1 123-456-7890'
number.getRegionCode(); // 'US'
number.getCarrier(); // null
number.getLineType(); // 'FIXED_LINE_OR_MOBILE'
awesome-phonenumber
is a powerful and flexible library for working with phone numbers in JavaScript. Its wide range of features makes it an essential tool for developers who need to work with phone numbers from around the world. Try it out today!