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.4.6 to 1.4.7

76

build/AsYouType.js

@@ -224,3 +224,3 @@ 'use strict';

// (and leading digits matching state)
this.matching_formats = this.available_formats;
this.matching_formats = undefined;
this.reset_format();

@@ -230,3 +230,8 @@ }

if (!this.should_format()) {
// if (!this.should_format())
// {
// return this.format_as_non_formatted_number()
// }
if (!this.national_number) {
return this.format_as_non_formatted_number();

@@ -251,3 +256,3 @@ }

// then just fall back to the raw phone number.
return this.parsed_input;
return this.format_as_non_formatted_number();
}

@@ -257,15 +262,5 @@ }, {

value: function format_as_non_formatted_number() {
// Strip national prefix for incorrectly inputted international phones.
if (this.is_international() && this.countryCallingCode) {
if (this.national_number) {
// For convenience, the public `.template` property
// contains the whole international number
// if the phone number being input is international:
// 'x' for the '+' sign, 'x'es for the country phone code,
// a spacebar and then the template for the national number digits.
this.template = DIGIT_PLACEHOLDER + repeat(DIGIT_PLACEHOLDER, this.countryCallingCode.length) + ' ' + repeat(DIGIT_PLACEHOLDER, this.national_number.length);
return '+' + this.countryCallingCode + ' ' + this.national_number;
}
return '+' + this.countryCallingCode;
return '+' + this.countryCallingCode + this.national_number;
}

@@ -302,7 +297,2 @@

if (formatted_number) {
// if (this.country)
// {
// this.valid = true
// }
return formatted_number;

@@ -387,3 +377,3 @@ }

this.available_formats = [];
this.matching_formats = this.available_formats;
this.matching_formats = undefined;
}

@@ -418,3 +408,3 @@ }

this.matching_formats = this.available_formats;
this.matching_formats = undefined;
}

@@ -426,9 +416,15 @@ }, {

// "leading digits" pattern list starts with
// one of a maximum length of 3 digits,
// and then with each additional digit
// a more precise "leading digits" pattern is specified.
// "leading digits" pattern list starts with a
// "leading digits" pattern fitting a maximum of 3 leading digits.
// So, after a user inputs 3 digits of a national (significant) phone number
// this national (significant) number can already be formatted.
// The next "leading digits" pattern is for 4 leading digits max,
// and the "leading digits" pattern after it is for 5 leading digits max, etc.
// This implementation is different from Google's
// in that it searches for a fitting format
// even if the user has entered less than
// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.
// Because some leading digits patterns already match for a single first digit.
var index_of_leading_digits_pattern = leading_digits.length - MIN_LEADING_DIGITS_LENGTH;
if (index_of_leading_digits_pattern < 0) {

@@ -438,11 +434,18 @@ index_of_leading_digits_pattern = 0;

this.matching_formats = this.matching_formats.filter(function (format) {
var leading_digits_pattern_count = format.leadingDigitsPatterns().length;
// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are available
// then format matching starts narrowing down the list of possible formats
// (only previously matched formats are considered for next digits).
var available_formats = this.had_enough_leading_digits && this.matching_formats || this.available_formats;
this.had_enough_leading_digits = this.should_format();
// Keep everything that isn't restricted by leading digits.
if (leading_digits_pattern_count === 0) {
this.matching_formats = available_formats.filter(function (format) {
var leading_digits_patterns_count = format.leadingDigitsPatterns().length;
// If this format is not restricted to a certain
// leading digits pattern then it fits.
if (leading_digits_patterns_count === 0) {
return true;
}
var leading_digits_pattern_index = Math.min(index_of_leading_digits_pattern, leading_digits_pattern_count - 1);
var leading_digits_pattern_index = Math.min(index_of_leading_digits_pattern, leading_digits_patterns_count - 1);
var leading_digits_pattern = format.leadingDigitsPatterns()[leading_digits_pattern_index];

@@ -477,6 +480,9 @@

//
// Google could have provided leading digits patterns starting
// with a single digit but they chose not to (for whatever reasons).
// Presumably the limitation of "3 digits min"
// is imposed to exclude false matches,
// e.g. when there are two different formats
// each one fitting one or two leading digits being input.
// But for this case I would propose a specific `if/else` condition.
//
return this.national_number >= MIN_LEADING_DIGITS_LENGTH;
return this.national_number.length >= MIN_LEADING_DIGITS_LENGTH;
}

@@ -483,0 +489,0 @@

@@ -249,3 +249,3 @@ 'use strict';

if (typeof arg_2 !== 'string') {
throw new Error('Format type argument not passed for `format()`');
throw new Error('`format` argument not passed to `formatNumber(number, format)`');
}

@@ -252,0 +252,0 @@

@@ -207,3 +207,3 @@ 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; }; }();

// (and leading digits matching state)
this.matching_formats = this.available_formats;
this.matching_formats = undefined;
this.reset_format();

@@ -213,3 +213,8 @@ }

if (!this.should_format()) {
// if (!this.should_format())
// {
// return this.format_as_non_formatted_number()
// }
if (!this.national_number) {
return this.format_as_non_formatted_number();

@@ -234,3 +239,3 @@ }

// then just fall back to the raw phone number.
return this.parsed_input;
return this.format_as_non_formatted_number();
}

@@ -240,15 +245,5 @@ }, {

value: function format_as_non_formatted_number() {
// Strip national prefix for incorrectly inputted international phones.
if (this.is_international() && this.countryCallingCode) {
if (this.national_number) {
// For convenience, the public `.template` property
// contains the whole international number
// if the phone number being input is international:
// 'x' for the '+' sign, 'x'es for the country phone code,
// a spacebar and then the template for the national number digits.
this.template = DIGIT_PLACEHOLDER + repeat(DIGIT_PLACEHOLDER, this.countryCallingCode.length) + ' ' + repeat(DIGIT_PLACEHOLDER, this.national_number.length);
return '+' + this.countryCallingCode + ' ' + this.national_number;
}
return '+' + this.countryCallingCode;
return '+' + this.countryCallingCode + this.national_number;
}

@@ -285,7 +280,2 @@

if (formatted_number) {
// if (this.country)
// {
// this.valid = true
// }
return formatted_number;

@@ -370,3 +360,3 @@ }

this.available_formats = [];
this.matching_formats = this.available_formats;
this.matching_formats = undefined;
}

@@ -401,3 +391,3 @@ }

this.matching_formats = this.available_formats;
this.matching_formats = undefined;
}

@@ -409,9 +399,15 @@ }, {

// "leading digits" pattern list starts with
// one of a maximum length of 3 digits,
// and then with each additional digit
// a more precise "leading digits" pattern is specified.
// "leading digits" pattern list starts with a
// "leading digits" pattern fitting a maximum of 3 leading digits.
// So, after a user inputs 3 digits of a national (significant) phone number
// this national (significant) number can already be formatted.
// The next "leading digits" pattern is for 4 leading digits max,
// and the "leading digits" pattern after it is for 5 leading digits max, etc.
// This implementation is different from Google's
// in that it searches for a fitting format
// even if the user has entered less than
// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.
// Because some leading digits patterns already match for a single first digit.
var index_of_leading_digits_pattern = leading_digits.length - MIN_LEADING_DIGITS_LENGTH;
if (index_of_leading_digits_pattern < 0) {

@@ -421,11 +417,18 @@ index_of_leading_digits_pattern = 0;

this.matching_formats = this.matching_formats.filter(function (format) {
var leading_digits_pattern_count = format.leadingDigitsPatterns().length;
// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are available
// then format matching starts narrowing down the list of possible formats
// (only previously matched formats are considered for next digits).
var available_formats = this.had_enough_leading_digits && this.matching_formats || this.available_formats;
this.had_enough_leading_digits = this.should_format();
// Keep everything that isn't restricted by leading digits.
if (leading_digits_pattern_count === 0) {
this.matching_formats = available_formats.filter(function (format) {
var leading_digits_patterns_count = format.leadingDigitsPatterns().length;
// If this format is not restricted to a certain
// leading digits pattern then it fits.
if (leading_digits_patterns_count === 0) {
return true;
}
var leading_digits_pattern_index = Math.min(index_of_leading_digits_pattern, leading_digits_pattern_count - 1);
var leading_digits_pattern_index = Math.min(index_of_leading_digits_pattern, leading_digits_patterns_count - 1);
var leading_digits_pattern = format.leadingDigitsPatterns()[leading_digits_pattern_index];

@@ -460,6 +463,9 @@

//
// Google could have provided leading digits patterns starting
// with a single digit but they chose not to (for whatever reasons).
// Presumably the limitation of "3 digits min"
// is imposed to exclude false matches,
// e.g. when there are two different formats
// each one fitting one or two leading digits being input.
// But for this case I would propose a specific `if/else` condition.
//
return this.national_number >= MIN_LEADING_DIGITS_LENGTH;
return this.national_number.length >= MIN_LEADING_DIGITS_LENGTH;
}

@@ -466,0 +472,0 @@

@@ -234,3 +234,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

if (typeof arg_2 !== 'string') {
throw new Error('Format type argument not passed for `format()`');
throw new Error('`format` argument not passed to `formatNumber(number, format)`');
}

@@ -237,0 +237,0 @@

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

{"AC":"40123","AD":"312345","AE":"501234567","AF":"701234567","AG":"2684641234","AI":"2642351234","AL":"662123456","AM":"77123456","AO":"923123456","AR":"91123456789","AS":"6847331234","AT":"664123456","AU":"412345678","AW":"5601234","AX":"412345678","AZ":"401234567","BA":"61123456","BB":"2462501234","BD":"1812345678","BE":"470123456","BF":"70123456","BG":"48123456","BH":"36001234","BI":"79561234","BJ":"90011234","BL":"690001234","BM":"4413701234","BN":"7123456","BO":"71234567","BQ":"3181234","BR":"11961234567","BS":"2423591234","BT":"17123456","BW":"71123456","BY":"294911911","BZ":"6221234","CA":"2042345678","CC":"412345678","CD":"991234567","CF":"70012345","CG":"061234567","CH":"781234567","CI":"01234567","CK":"71234","CL":"961234567","CM":"671234567","CN":"13123456789","CO":"3211234567","CR":"83123456","CU":"51234567","CV":"9911234","CW":"95181234","CX":"412345678","CY":"96123456","CZ":"601123456","DE":"15123456789","DJ":"77831001","DK":"20123456","DM":"7672251234","DO":"8092345678","DZ":"551234567","EC":"991234567","EE":"51234567","EG":"1001234567","EH":"650123456","ER":"7123456","ES":"612345678","ET":"911234567","FI":"412345678","FJ":"7012345","FK":"51234","FM":"3501234","FO":"211234","FR":"612345678","GA":"06031234","GB":"7400123456","GD":"4734031234","GE":"555123456","GF":"694201234","GG":"7781123456","GH":"231234567","GI":"57123456","GL":"221234","GM":"3012345","GN":"601123456","GP":"690001234","GQ":"222123456","GR":"6912345678","GT":"51234567","GU":"6713001234","GW":"955012345","GY":"6091234","HK":"51234567","HN":"91234567","HR":"921234567","HT":"34101234","HU":"201234567","ID":"812345678","IE":"850123456","IL":"502345678","IM":"7924123456","IN":"8123456789","IO":"3801234","IQ":"7912345678","IR":"9123456789","IS":"6111234","IT":"3123456789","JE":"7797712345","JM":"8762101234","JO":"790123456","JP":"9012345678","KE":"712123456","KG":"700123456","KH":"91234567","KI":"72001234","KM":"3212345","KN":"8697652917","KP":"1921234567","KR":"1000000000","KW":"50012345","KY":"3453231234","KZ":"7710009998","LA":"2023123456","LB":"71123456","LC":"7582845678","LI":"660234567","LK":"712345678","LR":"770123456","LS":"50123456","LT":"61234567","LU":"628123456","LV":"21234567","LY":"912345678","MA":"650123456","MC":"612345678","MD":"62112345","ME":"67622901","MF":"690001234","MG":"321234567","MH":"2351234","MK":"72345678","ML":"65012345","MM":"92123456","MN":"88123456","MO":"66123456","MP":"6702345678","MQ":"696201234","MR":"22123456","MS":"6644923456","MT":"96961234","MU":"52512345","MV":"7712345","MW":"991234567","MX":"12221234567","MY":"123456789","MZ":"821234567","NA":"811234567","NC":"751234","NE":"93123456","NF":"381234","NG":"8021234567","NI":"81234567","NL":"612345678","NO":"40612345","NP":"9841234567","NR":"5551234","NU":"8884012","NZ":"211234567","OM":"92123456","PA":"61234567","PE":"912345678","PF":"87123456","PG":"70123456","PH":"9051234567","PK":"3012345678","PL":"512345678","PM":"551234","PR":"7872345678","PS":"599123456","PT":"912345678","PW":"6201234","PY":"961456789","QA":"33123456","RE":"692123456","RO":"712034567","RS":"601234567","RU":"9123456789","RW":"720123456","SA":"512345678","SB":"7421234","SC":"2510123","SD":"911231234","SE":"701234567","SG":"81234567","SH":"51234","SI":"31234567","SJ":"41234567","SK":"912123456","SL":"25123456","SM":"66661212","SN":"701234567","SO":"71123456","SR":"7412345","SS":"977123456","ST":"9812345","SV":"70123456","SX":"7215205678","SY":"944567890","SZ":"76123456","TA":"8999","TC":"6492311234","TD":"63012345","TG":"90112345","TH":"812345678","TJ":"917123456","TK":"7290","TL":"77212345","TM":"66123456","TN":"20123456","TO":"7715123","TR":"5012345678","TT":"8682911234","TV":"901234","TW":"912345678","TZ":"621234567","UA":"391234567","UG":"712345678","US":"2015550123","UY":"94231234","UZ":"912345678","VA":"3123456789","VC":"7844301234","VE":"4121234567","VG":"2843001234","VI":"3406421234","VN":"912345678","VU":"5912345","WF":"501234","WS":"7212345","XK":"43201234","YE":"712345678","YT":"639012345","ZA":"711234567","ZM":"955123456","ZW":"712345678"}
{"AC":"40123","AD":"312345","AE":"501234567","AF":"701234567","AG":"2684641234","AI":"2642351234","AL":"662123456","AM":"77123456","AO":"923123456","AR":"91123456789","AS":"6847331234","AT":"664123456","AU":"412345678","AW":"5601234","AX":"412345678","AZ":"401234567","BA":"61123456","BB":"2462501234","BD":"1812345678","BE":"470123456","BF":"70123456","BG":"48123456","BH":"36001234","BI":"79561234","BJ":"90011234","BL":"690001234","BM":"4413701234","BN":"7123456","BO":"71234567","BQ":"3181234","BR":"11961234567","BS":"2423591234","BT":"17123456","BW":"71123456","BY":"294911911","BZ":"6221234","CA":"2042345678","CC":"412345678","CD":"991234567","CF":"70012345","CG":"061234567","CH":"781234567","CI":"01234567","CK":"71234","CL":"961234567","CM":"671234567","CN":"13123456789","CO":"3211234567","CR":"83123456","CU":"51234567","CV":"9911234","CW":"95181234","CX":"412345678","CY":"96123456","CZ":"601123456","DE":"15123456789","DJ":"77831001","DK":"32123456","DM":"7672251234","DO":"8092345678","DZ":"551234567","EC":"991234567","EE":"51234567","EG":"1001234567","EH":"650123456","ER":"7123456","ES":"612345678","ET":"911234567","FI":"412345678","FJ":"7012345","FK":"51234","FM":"3501234","FO":"211234","FR":"612345678","GA":"06031234","GB":"7400123456","GD":"4734031234","GE":"555123456","GF":"694201234","GG":"7781123456","GH":"231234567","GI":"57123456","GL":"221234","GM":"3012345","GN":"601123456","GP":"690001234","GQ":"222123456","GR":"6912345678","GT":"51234567","GU":"6713001234","GW":"955012345","GY":"6091234","HK":"51234567","HN":"91234567","HR":"921234567","HT":"34101234","HU":"201234567","ID":"812345678","IE":"850123456","IL":"502345678","IM":"7924123456","IN":"8123456789","IO":"3801234","IQ":"7912345678","IR":"9123456789","IS":"6111234","IT":"3123456789","JE":"7797712345","JM":"8762101234","JO":"790123456","JP":"9012345678","KE":"712123456","KG":"700123456","KH":"91234567","KI":"72001234","KM":"3212345","KN":"8697652917","KP":"1921234567","KR":"1000000000","KW":"50012345","KY":"3453231234","KZ":"7710009998","LA":"2023123456","LB":"71123456","LC":"7582845678","LI":"660234567","LK":"712345678","LR":"770123456","LS":"50123456","LT":"61234567","LU":"628123456","LV":"21234567","LY":"912345678","MA":"650123456","MC":"612345678","MD":"62112345","ME":"67622901","MF":"690001234","MG":"321234567","MH":"2351234","MK":"72345678","ML":"65012345","MM":"92123456","MN":"88123456","MO":"66123456","MP":"6702345678","MQ":"696201234","MR":"22123456","MS":"6644923456","MT":"96961234","MU":"52512345","MV":"7712345","MW":"991234567","MX":"12221234567","MY":"123456789","MZ":"821234567","NA":"811234567","NC":"751234","NE":"93123456","NF":"381234","NG":"8021234567","NI":"81234567","NL":"612345678","NO":"40612345","NP":"9841234567","NR":"5551234","NU":"8884012","NZ":"211234567","OM":"92123456","PA":"61234567","PE":"912345678","PF":"87123456","PG":"70123456","PH":"9051234567","PK":"3012345678","PL":"512345678","PM":"551234","PR":"7872345678","PS":"599123456","PT":"912345678","PW":"6201234","PY":"961456789","QA":"33123456","RE":"692123456","RO":"712034567","RS":"601234567","RU":"9123456789","RW":"720123456","SA":"512345678","SB":"7421234","SC":"2510123","SD":"911231234","SE":"701234567","SG":"81234567","SH":"51234","SI":"31234567","SJ":"41234567","SK":"912123456","SL":"25123456","SM":"66661212","SN":"701234567","SO":"71123456","SR":"7412345","SS":"977123456","ST":"9812345","SV":"70123456","SX":"7215205678","SY":"944567890","SZ":"76123456","TA":"8999","TC":"6492311234","TD":"63012345","TG":"90112345","TH":"812345678","TJ":"917123456","TK":"7290","TL":"77212345","TM":"66123456","TN":"20123456","TO":"7715123","TR":"5012345678","TT":"8682911234","TV":"901234","TW":"912345678","TZ":"621234567","UA":"391234567","UG":"712345678","US":"2015550123","UY":"94231234","UZ":"912345678","VA":"3123456789","VC":"7844301234","VE":"4121234567","VG":"2843001234","VI":"3406421234","VN":"912345678","VU":"5912345","WF":"501234","WS":"7212345","XK":"43201234","YE":"712345678","YT":"639012345","ZA":"711234567","ZM":"955123456","ZW":"712345678"}
{
"name": "libphonenumber-js",
"version": "1.4.6",
"version": "1.4.7",
"description": "A simpler (and smaller) rewrite of Google Android's popular libphonenumber library",

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

@@ -338,3 +338,3 @@ # libphonenumber-js

asYouType.getNationalNumber() === '2'
asYouType.getTemplate() === undefined // Not enough digits yet.
asYouType.getTemplate() === 'x'

@@ -599,3 +599,2 @@ asYouType.input('1') === '21'

```html
<!-- `libphonenumber-js` (is used internally by `react-phone-number-input`). -->
<script src="https://unpkg.com/libphonenumber-js/bundle/libphonenumber-js.min.js"></script>

@@ -602,0 +601,0 @@

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 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