libphonenumbers
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "libphonenumbers", | ||
"version": "0.0.2", | ||
"description": "Google's common JavaScript library for parsing, formatting, and validating international phone numbers for Node.js.", | ||
"version": "0.0.3", | ||
"description": "JavaScript port of Google's libphonenumber library for parsing, formatting, and validating international phone numbers in Node.js.", | ||
"author": "Bunlong <bunlong.van@gmail.com>", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
136
README.md
@@ -0,7 +1,11 @@ | ||
<p align="center"> | ||
<img src="https://raw.githubusercontent.com/Bunlong/libphonenumbers/main/static/images/libphonenumbers.png" alt="libphonenumbers" /> | ||
</p> | ||
# libphonenumbers | ||
libphonenumbers – Google's common JavaScript library for parsing, formatting, and validating international phone numbers for Node.js. | ||
> libphonenumbers is JS port of [Google's libphonenumber](https://github.com/google/libphonenumber/tree/master/javascript). | ||
libphonenumbers – JavaScript port of Google's libphonenumber library for parsing, formatting, and validating international phone numbers in Node.js. | ||
[![NPM](https://img.shields.io/npm/v/libphonenumbers.svg)](https://www.npmjs.com/package/libphonenumbers) | ||
@@ -15,4 +19,4 @@ | ||
* [format(number, numberFormat)](#formatnumber-numberformat) | ||
* formatInOriginalFormat(number, regionCallingFrom) | ||
* formatOutOfCountryCallingNumber(number, regionCallingFrom) | ||
* [formatInOriginalFormat(number, regionCallingFrom)](#formatinoriginalformatnumber-regioncallingfrom) | ||
* [formatOutOfCountryCallingNumber(number, regionCallingFrom)](#formatoutofcountrycallingnumbernumber-regioncallingfrom) | ||
* getNumberType(number) | ||
@@ -33,29 +37,2 @@ * getRegionCodeForNumber(number) | ||
* PhoneNumberType | ||
* FIXED_LINE | ||
* MOBILE | ||
* SHARED_COST | ||
* FIXED_LINE_OR_MOBILE | ||
* TOLL_FREE | ||
* PREMIUM_RATE | ||
* PAGER | ||
* VOIP | ||
* PERSONAL_NUMBER | ||
* VOICEMAIL | ||
* UAN | ||
* UNKNOWN | ||
* PhoneNumberFormat | ||
* PhoneNumberFormat.E164 | ||
* PhoneNumberFormat.INTERNATIONAL | ||
* PhoneNumberFormat.NATIONAL | ||
* PhoneNumberFormat.RFC3966 | ||
* CountryCodeSource | ||
* UNSPECIFIED | ||
* FROM_NUMBER_WITH_IDD | ||
* FROM_NUMBER_WITHOUT_PLUS_SIGN | ||
* FROM_NUMBER_WITH_PLUS_SIGN | ||
* FROM_DEFAULT_COUNTRY | ||
* PhoneNumber | ||
@@ -69,2 +46,29 @@ * getCountryCode() | ||
* PhoneNumberType | ||
* FIXED_LINE ( value: 0 ) | ||
* MOBILE ( value: 1 ) | ||
* FIXED_LINE_OR_MOBILE ( value: 2 ) | ||
* TOLL_FREE ( value: 3 ) | ||
* PREMIUM_RATE ( value: 4 ) | ||
* SHARED_COST ( value: 5 ) | ||
* VOIP ( value: 6 ) | ||
* PERSONAL_NUMBER ( value: 7 ) | ||
* PAGER ( value: 8 ) | ||
* UAN ( value: 8 ) | ||
* VOICEMAIL ( value: 10 ) | ||
* UNKNOWN ( value: -1 ) | ||
* PhoneNumberFormat | ||
* E164 ( value: 0 ) | ||
* INTERNATIONAL ( value: 1 ) | ||
* NATIONAL ( value: 2 ) | ||
* RFC3966: ( value: 3 ) | ||
* CountryCodeSource | ||
* UNSPECIFIED ( value: 0) | ||
* FROM_NUMBER_WITH_PLUS_SIGN ( value: 1) | ||
* FROM_NUMBER_WITH_IDD ( value: 5) | ||
* FROM_NUMBER_WITHOUT_PLUS_SIGN ( value: 10) | ||
* FROM_DEFAULT_COUNTRY ( value: 20) | ||
## ❌ Missing Features: | ||
@@ -106,2 +110,3 @@ | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('300-577-8989', 'US'); | ||
@@ -132,2 +137,3 @@ | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('300-577-8989', 'US'); | ||
@@ -148,2 +154,70 @@ | ||
#### formatInOriginalFormat(number, regionCallingFrom) | ||
Using Standard JavaScript: | ||
```js | ||
// Create an instance of PhoneNumberUtil | ||
const phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance(); | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('300-577-8989', 'US'); | ||
// Format number in the original format | ||
console.log(phoneUtil.formatInOriginalFormat(number, 'US')); | ||
// => (300) 577-8989 | ||
``` | ||
Using ECMAScript (ES): | ||
```js | ||
// Create an instance of PhoneNumberUtil | ||
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance(); | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('300-577-8989', 'US'); | ||
// Format number in the original format | ||
console.log(phoneUtil.formatInOriginalFormat(number, 'US')); | ||
// => (300) 577-8989 | ||
``` | ||
#### formatOutOfCountryCallingNumber(number, regionCallingFrom) | ||
Using Standard JavaScript: | ||
```js | ||
// Create an instance of PhoneNumberUtil | ||
const phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance(); | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('300-577-8989', 'US'); | ||
// Format number in the out-of-country format from US | ||
console.log(phoneUtil.formatOutOfCountryCallingNumber(number, 'US')); | ||
// => 1 (300) 577-8989 | ||
// Format number in the out-of-country format from JP | ||
console.log(phoneUtil.formatOutOfCountryCallingNumber(number, 'JP')); | ||
// => 010 1 300-577-8989 | ||
``` | ||
Using ECMAScript (ES): | ||
```js | ||
// Create an instance of PhoneNumberUtil | ||
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance(); | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('300-577-8989', 'US'); | ||
// Format number in the out-of-country format from US | ||
console.log(phoneUtil.formatOutOfCountryCallingNumber(number, 'US')); | ||
// => 1 (300) 577-8989 | ||
// Format number in the out-of-country format from JP | ||
console.log(phoneUtil.formatOutOfCountryCallingNumber(number, 'JP')); | ||
// => 010 1 300-577-8989 | ||
``` | ||
## 🦄 Credit and Inspiration | ||
@@ -150,0 +224,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1140980
224
5