libphonenumbers
Advanced tools
Comparing version 0.0.5 to 1.0.0
{ | ||
"name": "libphonenumbers", | ||
"version": "0.0.5", | ||
"version": "1.0.0", | ||
"description": "JavaScript port of Google's libphonenumber library for parsing, formatting, and validating international phone numbers in Node.js.", | ||
@@ -5,0 +5,0 @@ "author": "Bunlong <bunlong.van@gmail.com>", |
248
README.md
@@ -37,35 +37,35 @@ <p align="center"> | ||
* PhoneNumber | ||
* getCountryCode() | ||
* getCountryCodeSource() | ||
* getExtension() | ||
* getItalianLeadingZero() | ||
* getNationalNumber() | ||
* getRawInput() | ||
* [getCountryCode()](#-getcountrycode) | ||
* [getCountryCodeSource()](#-getcountrycodesource) | ||
* [getExtension()](#-getextension) | ||
* [getItalianLeadingZero()](#-getitalianleadingzero) | ||
* [getNationalNumber()](#-getnationalnumber) | ||
* [getRawInput()](#-getrawinput) | ||
* 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 ) | ||
* FIXED_LINE ( value is 0 ) | ||
* MOBILE ( value is 1 ) | ||
* FIXED_LINE_OR_MOBILE ( value is 2 ) | ||
* TOLL_FREE ( value is 3 ) | ||
* PREMIUM_RATE ( value is 4 ) | ||
* SHARED_COST ( value is 5 ) | ||
* VOIP ( value is 6 ) | ||
* PERSONAL_NUMBER ( value is 7 ) | ||
* PAGER ( value is 8 ) | ||
* UAN ( value is 9 ) | ||
* VOICEMAIL ( value is 10 ) | ||
* UNKNOWN ( value is -1 ) | ||
* PhoneNumberFormat | ||
* E164 ( value: 0 ) | ||
* INTERNATIONAL ( value: 1 ) | ||
* NATIONAL ( value: 2 ) | ||
* RFC3966: ( value: 3 ) | ||
* E164 ( value is 0 ) | ||
* INTERNATIONAL ( value is 1 ) | ||
* NATIONAL ( value is 2 ) | ||
* RFC3966: ( value is 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) | ||
* UNSPECIFIED ( value is 0) | ||
* FROM_NUMBER_WITH_PLUS_SIGN ( value is 1) | ||
* FROM_NUMBER_WITH_IDD ( value is 5) | ||
* FROM_NUMBER_WITHOUT_PLUS_SIGN ( value is 10) | ||
* FROM_DEFAULT_COUNTRY ( value is 20) | ||
@@ -522,2 +522,196 @@ ## ❌ Missing Features: | ||
### 🎀 PhoneNumber | ||
#### 📦 getCountryCode() | ||
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('202-456-2121', 'US'); | ||
// Get the phone's country code | ||
console.log(number.getCountryCode()); | ||
// => 1 | ||
``` | ||
Using ECMAScript (ES): | ||
```js | ||
import libphonenumbers from 'libphonenumbers'; | ||
// Create an instance of PhoneNumberUtil | ||
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance(); | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US'); | ||
// Get the phone's country code | ||
console.log(number.getCountryCode()); | ||
// => 1 | ||
``` | ||
#### 📦 getCountryCodeSource() | ||
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('202-456-2121', 'US'); | ||
// Get the phone's extension | ||
console.log(number.getCountryCodeSource()); | ||
// => FROM_DEFAULT_COUNTRY | ||
``` | ||
Using ECMAScript (ES): | ||
```js | ||
import libphonenumbers from 'libphonenumbers'; | ||
// Create an instance of PhoneNumberUtil | ||
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance(); | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US'); | ||
// Print the phone's extension | ||
console.log(number.getCountryCodeSource()); | ||
// => FROM_DEFAULT_COUNTRY | ||
``` | ||
#### 📦 getExtension() | ||
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('202-456-2121', 'US'); | ||
// Print the phone's extension. | ||
console.log(number.getExtension()); | ||
// => null | ||
``` | ||
Using ECMAScript (ES): | ||
```js | ||
import libphonenumbers from 'libphonenumbers'; | ||
// Create an instance of PhoneNumberUtil | ||
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance(); | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US'); | ||
// Print the phone's extension. | ||
console.log(number.getExtension()); | ||
// => null | ||
``` | ||
#### 📦 getItalianLeadingZero() | ||
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('202-456-2121', 'US'); | ||
// Get phone's italian leading zero | ||
console.log(number.getItalianLeadingZero()); | ||
// => null | ||
``` | ||
Using ECMAScript (ES): | ||
```js | ||
import libphonenumbers from 'libphonenumbers'; | ||
// Create an instance of PhoneNumberUtil | ||
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance(); | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US'); | ||
// Get phone's italian leading zero | ||
console.log(number.getItalianLeadingZero()); | ||
// => null | ||
``` | ||
#### 📦 getNationalNumber() | ||
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('202-456-2121', 'US'); | ||
// Get the phone's national number | ||
console.log(number.getNationalNumber()); | ||
// => 2024562121 | ||
``` | ||
Using ECMAScript (ES): | ||
```js | ||
import libphonenumbers from 'libphonenumbers'; | ||
// Create an instance of PhoneNumberUtil | ||
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance(); | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US'); | ||
// Get the phone's national number | ||
console.log(number.getNationalNumber()); | ||
// => 2024562121 | ||
``` | ||
#### 📦 getRawInput() | ||
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('202-456-2121', 'US'); | ||
// Get the phone's raw input | ||
console.log(number.getRawInput()); | ||
// => 202-456-2121 | ||
``` | ||
Using ECMAScript (ES): | ||
```js | ||
import libphonenumbers from 'libphonenumbers'; | ||
// Create an instance of PhoneNumberUtil | ||
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance(); | ||
// Parse number with US country code and keep raw input | ||
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US'); | ||
// Get the phone's raw input | ||
console.log(number.getRawInput()); | ||
// => 202-456-2121 | ||
``` | ||
## 🦄 Credit and Inspiration | ||
@@ -524,0 +718,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1154342
1
722