Socket
Socket
Sign inDemoInstall

libphonenumber-js

Package Overview
Dependencies
Maintainers
1
Versions
392
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libphonenumber-js - npm Package Compare versions

Comparing version 1.6.0 to 1.6.1

24

build/AsYouType.js

@@ -23,2 +23,6 @@ 'use strict';

var _PhoneNumber = require('./PhoneNumber');
var _PhoneNumber2 = _interopRequireDefault(_PhoneNumber);
var _common = require('./common');

@@ -344,2 +348,3 @@

this.national_number = '';
this.carrierCode = '';

@@ -605,4 +610,9 @@ this.reset_countriness();

var _strip_national_prefi = (0, _parse.strip_national_prefix_and_carrier_code)(this.national_number, this.metadata),
potential_national_number = _strip_national_prefi.number;
potential_national_number = _strip_national_prefi.number,
carrierCode = _strip_national_prefi.carrierCode;
if (carrierCode) {
this.carrierCode = carrierCode;
}
// We require that the NSN remaining after stripping the national prefix and

@@ -612,4 +622,2 @@ // carrier code be long enough to be a possible length for the region.

// a valid short number.
if (!this.metadata.possibleLengths() || this.is_possible_number(this.national_number) && !this.is_possible_number(potential_national_number)) {

@@ -916,2 +924,12 @@ // Verify the parsed national (significant) number for this country

}, {
key: 'getNumber',
value: function getNumber() {
var phoneNumber = new _PhoneNumber2.default(this.country || this.countryCallingCode, this.national_number, this.metadata.metadata);
if (this.carrierCode) {
phoneNumber.carrierCode = this.carrierCode;
}
// Phone number extensions are not supported by "As You Type" formatter.
return phoneNumber;
}
}, {
key: 'getNationalNumber',

@@ -918,0 +936,0 @@ value: function getNationalNumber() {

6

build/tools/generate.js

@@ -336,9 +336,9 @@ 'use strict';

} else {
if (_country.formats) {
if (_country.formats !== undefined) {
throw new Error('Country "' + _country_code + '" is supposed to inherit formats from "' + main_country_for_region_code + '" but has its own formats defined.');
}
if (_country.nationalPrefixFormattingRule) {
if (_country.nationalPrefixFormattingRule !== undefined) {
throw new Error('Country "' + _country_code + '" is supposed to inherit "nationalPrefixFormattingRule" from "' + main_country_for_region_code + '" but has its own "nationalPrefixFormattingRule" defined.');
}
if (_country.nationalPrefixIsOptionalWhenFormatting) {
if (_country.nationalPrefixIsOptionalWhenFormatting !== undefined) {
throw new Error('Country "' + _country_code + '" is supposed to inherit "nationalPrefixIsOptionalWhenFormatting" from "' + main_country_for_region_code + '" but has its own "nationalPrefixIsOptionalWhenFormatting" defined.');

@@ -345,0 +345,0 @@ }

@@ -8,6 +8,2 @@ 'use strict';

var _parse = require('./parse');
var _parse2 = _interopRequireDefault(_parse);
var _getNumberType = require('./getNumberType');

@@ -14,0 +10,0 @@

@@ -47,5 +47,10 @@ <!-- (breaking change) `parseNumber()` is now `extended: true` by default (and the `extended` flag is no longer supported) meaning that by default it will parse all even remotely hypothetical phone numbers (this was decided to be the primary use case for this function, and it's how Google's libphonenumber does it). Pass `strict: true` flag for the old "only parse valid numbers" behaviour. -->

1.6.0 / 16.10.2018
1.6.1 / 18.10.2018
==================
* Added `.getNumber()` method to `AsYouType` formatter instance. Returns a `PhoneNumber`.
1.6.0 / 17.10.2018
==================
* Added `parsePhoneNumber()` function and `PhoneNumber` class.

@@ -52,0 +57,0 @@

@@ -12,2 +12,4 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

import PhoneNumber from './PhoneNumber';
import { matches_entirely, VALID_DIGITS, VALID_PUNCTUATION, PLUS_CHARS, extractCountryCallingCode } from './common';

@@ -327,2 +329,3 @@

this.national_number = '';
this.carrierCode = '';

@@ -588,4 +591,9 @@ this.reset_countriness();

var _strip_national_prefi = strip_national_prefix_and_carrier_code(this.national_number, this.metadata),
potential_national_number = _strip_national_prefi.number;
potential_national_number = _strip_national_prefi.number,
carrierCode = _strip_national_prefi.carrierCode;
if (carrierCode) {
this.carrierCode = carrierCode;
}
// We require that the NSN remaining after stripping the national prefix and

@@ -595,4 +603,2 @@ // carrier code be long enough to be a possible length for the region.

// a valid short number.
if (!this.metadata.possibleLengths() || this.is_possible_number(this.national_number) && !this.is_possible_number(potential_national_number)) {

@@ -899,2 +905,12 @@ // Verify the parsed national (significant) number for this country

}, {
key: 'getNumber',
value: function getNumber() {
var phoneNumber = new PhoneNumber(this.country || this.countryCallingCode, this.national_number, this.metadata.metadata);
if (this.carrierCode) {
phoneNumber.carrierCode = this.carrierCode;
}
// Phone number extensions are not supported by "As You Type" formatter.
return phoneNumber;
}
}, {
key: 'getNationalNumber',

@@ -901,0 +917,0 @@ value: function getNationalNumber() {

@@ -467,9 +467,9 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

} else {
if (_country.formats) {
if (_country.formats !== undefined) {
throw new Error('Country "' + _country_code + '" is supposed to inherit formats from "' + main_country_for_region_code + '" but has its own formats defined.');
}
if (_country.nationalPrefixFormattingRule) {
if (_country.nationalPrefixFormattingRule !== undefined) {
throw new Error('Country "' + _country_code + '" is supposed to inherit "nationalPrefixFormattingRule" from "' + main_country_for_region_code + '" but has its own "nationalPrefixFormattingRule" defined.');
}
if (_country.nationalPrefixIsOptionalWhenFormatting) {
if (_country.nationalPrefixIsOptionalWhenFormatting !== undefined) {
throw new Error('Country "' + _country_code + '" is supposed to inherit "nationalPrefixIsOptionalWhenFormatting" from "' + main_country_for_region_code + '" but has its own "nationalPrefixIsOptionalWhenFormatting" defined.');

@@ -476,0 +476,0 @@ }

@@ -1,2 +0,1 @@

import parse, { is_viable_phone_number } from './parse';
import get_number_type, { sort_out_arguments } from './getNumberType';

@@ -3,0 +2,0 @@ import { matches_entirely } from './common';

@@ -11,9 +11,9 @@ export type CountryCode = '001' | 'AC' | 'AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AO' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' | 'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FK' | 'FM' | 'FO' | 'FR' | 'GA' | 'GB' | 'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' | 'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GT' | 'GU' | 'GW' | 'GY' | 'HK' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MH' | 'MK' | 'ML' | 'MM' | 'MN' | 'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PR' | 'PS' | 'PT' | 'PW' | 'PY' | 'QA' | 'RE' | 'RO' | 'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' | 'SX' | 'SY' | 'SZ' | 'TA' | 'TC' | 'TD' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'XK' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW';

export class PhoneNumber {
constructor(countryCallingCode: CountryCallingCode | country: CountryCode, nationalNumber: NationalNumber, metadata: object);
countryCallingCode: CountryCallingCode,
country?: CountryCode,
nationalNumber: NationalNumber,
number: string,
carrierCode?: string,
ext?: Extension,
constructor(countryCallingCodeOrCountry: CountryCallingCode | CountryCode, nationalNumber: NationalNumber, metadata: object);
countryCallingCode: CountryCallingCode;
country?: CountryCode;
nationalNumber: NationalNumber;
number: string;
carrierCode?: string;
ext?: Extension;
isPossible(): boolean;

@@ -110,4 +110,5 @@ isValid(): boolean;

country: CountryCode;
getNumber(): PhoneNumber;
getNationalNumber(): string;
template: string;
}
}
{
"name": "libphonenumber-js",
"version": "1.6.0",
"version": "1.6.1",
"description": "A simpler (and smaller) rewrite of Google Android's popular libphonenumber library",

@@ -5,0 +5,0 @@ "main": "index.common.js",

@@ -17,7 +17,9 @@ # libphonenumber-js

One part of me was curious about how all this phone number parsing and formatting machinery worked, and another part of me was curious if there was a way to reduce those 530 kilobytes to something more reasonable while also getting rid of all the unnecessary bulk and rewriting it all in pure javascript. The resulting library does everything a modern web application needs while maintaining a much smaller size of about 110 kilobytes.
<!--
One part of me was curious about how all this phone number parsing and formatting machinery worked, and another part of me was curious if there was a way to reduce those 530 kilobytes to something more reasonable while also getting rid of all the unnecessary bulk and rewriting it all in pure javascript. The resulting library does everything a modern web application needs while maintaining a much smaller size of about 130 kilobytes.
-->
## Difference from Google's `libphonenumber`
* Much smaller footprint: 110 kilobytes (30 kB code + 80 kB sufficient metadata) vs the original Google's 530 kilobytes (330 kB code + 200 kB full metadata).
* Much smaller footprint: 130 kilobytes (55 kB code + 75 kB sufficient metadata) vs the original Google's 530 kilobytes (330 kB code + 200 kB full metadata).
* Can search for phone numbers in text (Google's autogenerated javascript port can't).

@@ -205,5 +207,5 @@ * Doesn't parse alphabetic phone numbers like `1-800-GOT-MILK`.

### parsePhoneNumber(text, [defaultCountry])
### parsePhoneNumber(string, [defaultCountry])
Parses `text` extracting a phone number from it.
Parses `string` extracting a phone number from it.

@@ -237,5 +239,5 @@ ```js

* `nationalNumber` — The [national (significant) number](#national-significant-number). Example: `"2133734253"`.
* `country` — The [country code](#country-code). Will be `undefined` when no `country` could be derived from the phone number. For example, when several countries have the same `countryCallingCode` and the `nationalNumber` doesn't look like it belongs to any of them. Example: `"US"`.
* `country` — The [country code](#country-code). Example: `"US"`. Will be `undefined` when no `country` could be derived from the phone number. For example, when several countries have the same `countryCallingCode` and the `nationalNumber` doesn't look like it belongs to any of them.
* `ext` — The [phone number extension](https://en.wikipedia.org/wiki/Extension_(telephone)), if any. Example: `"1234"`.
* `carrierCode` — The ["carrier code"](https://www.voip-info.org/carrier-identification-codes/), if any. "Carrier codes" are only used in Colombia and Brazil and only when dialing within those countries from a mobile phone to a fixed line number. Example: `"15"`.
* `carrierCode` — The ["carrier code"](https://www.voip-info.org/carrier-identification-codes/), if any. Example: `"15"`. "Carrier codes" are only used in Colombia and Brazil and only when dialing within those countries from a mobile phone to a fixed line number.

@@ -527,4 +529,5 @@ `PhoneNumber` class instance provides the following methods:

* `country` — Phone number [country](#country-code).
* `getNationalNumber()` — Returns the national (significant) number part of the phone number.
_(new API)_
* `getNumber()` — Returns the [`PhoneNumber`](#phonenumber).
* `getTemplate()` — Returns the template used to format the output (or `undefined`). Digits (and the `+` sign, if present) are denoted by `x`-es.

@@ -538,2 +541,40 @@

asYouType.input('2') === '2'
asYouType.getNumber().number === '+12'
asYouType.getTemplate() === 'x'
asYouType.input('1') === '21'
asYouType.getNumber().number === '+121'
asYouType.getTemplate() === 'xx'
asYouType.input('3') === '(213)'
asYouType.getNumber().number === '+1213'
asYouType.getTemplate() === '(xxx)'
asYouType.input('3734253') === '(213) 373-4253'
asYouType.getNumber().number === '+12133734253'
asYouType.getTemplate() === '(xxx) xxx-xxxx'
// International phone number input example.
const asYouType = new AsYouType()
asYouType.input('+1-213-373-4253') === '+1 213 373 4253'
asYouType.getNumber().country === 'US'
asYouType.getNumber().number === '+12133734253'
asYouType.getTemplate() === 'xx xxx xxx xxxx'
```
<details>
<summary>Legacy API</summary>
The formatter instance also provides the following legacy API getters:
* `country` — Phone number [country](#country-code). Will return `undefined` if the country couldn't be derived from the number.
* `getNationalNumber()` — Returns the national (significant) number part of the phone number.
```js
// National phone number input example.
const asYouType = new AsYouType('US')
asYouType.input('2') === '2'
asYouType.getNationalNumber() === '2'

@@ -562,3 +603,6 @@ asYouType.getTemplate() === 'x'

```
</details>
####
"As You Type" formatter was created by Google as part of their Android OS and therefore only works for numerical keyboard input, i.e. it can only accept digits (and a `+` sign in the start of an international number). When used on desktops where a user can input all kinds of punctuation (spaces, dashes, parens, etc) it simply ignores everything except digits (and a `+` sign in the start of an international number).

@@ -788,3 +832,3 @@

## getExampleNumber(country, examples)
### getExampleNumber(country, examples)

@@ -791,0 +835,0 @@ Returns an instance of [`PhoneNumber`](#phonenumber) class.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc