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.7.43 to 1.7.44

45

build/AsYouType.js

@@ -25,2 +25,4 @@ "use strict";

var _IDD = require("./IDD");
var _getNumberType_ = require("./getNumberType_");

@@ -92,3 +94,3 @@

var MIN_LEADING_DIGITS_LENGTH = 3;
var VALID_FORMATTED_PHONE_NUMBER_PART = '[' + _constants.PLUS_CHARS + ']{0,1}' + '[' + _constants.VALID_PUNCTUATION + _constants.VALID_DIGITS + ']*';
var VALID_FORMATTED_PHONE_NUMBER_PART = '[' + _constants.VALID_PUNCTUATION + _constants.VALID_DIGITS + ']*';
var VALID_FORMATTED_PHONE_NUMBER_PART_PATTERN = new RegExp('^' + VALID_FORMATTED_PHONE_NUMBER_PART + '$', 'i');

@@ -151,2 +153,3 @@ var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;

this.international = undefined;
this.internationalPrefix = undefined;
this.countryCallingCode = undefined;

@@ -224,3 +227,3 @@ this.digits = '';

if (this.digits) {// If an out of position `+` is detected
if (this.digits || this.isInternational()) {// If an out of position `+` is detected
// (or a second `+`) then just ignore it.

@@ -253,3 +256,20 @@ } else {

value: function inputDigits(nextDigits) {
// Append phone number digits.
// Some users input their phone number in "out-of-country"
// dialing format instead of using the leading `+`.
// https://github.com/catamphetamine/libphonenumber-js/issues/185
// Detect such numbers.
if (!this.digits) {
var numberWithoutIDD = (0, _IDD.stripIDDPrefix)(nextDigits, this.defaultCountry, this.defaultCallingCode, this.metadata.metadata);
if (numberWithoutIDD && numberWithoutIDD !== nextDigits) {
// If an IDD prefix was stripped then
// convert the number to international one
// for subsequent parsing.
this.internationalPrefix = nextDigits.slice(0, nextDigits.length - numberWithoutIDD.length);
nextDigits = numberWithoutIDD;
this.startInternationalNumber();
}
} // Append phone number digits.
this.digits += nextDigits; // Try to format the parsed input

@@ -652,2 +672,7 @@

}
}
}, {
key: "getInternationalPrefix",
value: function getInternationalPrefix(options) {
return this.internationalPrefix ? options && options.spacing === false ? this.internationalPrefix : this.internationalPrefix + ' ' : '+';
} // Prepends `+CountryCode ` in case of an international phone number

@@ -659,11 +684,13 @@

if (this.isInternational()) {
var prefix = this.getInternationalPrefix();
if (!this.countryCallingCode) {
return "+".concat(this.digits);
return "".concat(prefix).concat(this.digits);
}
if (!formattedNationalNumber) {
return "+".concat(this.countryCallingCode);
return "".concat(prefix).concat(this.countryCallingCode);
}
return "+".concat(this.countryCallingCode, " ").concat(formattedNationalNumber);
return "".concat(prefix).concat(this.countryCallingCode, " ").concat(formattedNationalNumber);
}

@@ -780,3 +807,3 @@

if (this.isInternational()) {
this.template = DIGIT_PLACEHOLDER + repeat(DIGIT_PLACEHOLDER, this.countryCallingCode.length) + ' ' + template;
this.template = this.getInternationalPrefix().replace(/[\d\+]/g, DIGIT_PLACEHOLDER) + repeat(DIGIT_PLACEHOLDER, this.countryCallingCode.length) + ' ' + template;
}

@@ -1053,3 +1080,5 @@

while (i < (this.international ? 1 : 0) + this.digits.length) {
while (i < (this.isInternational() ? this.getInternationalPrefix({
spacing: false
}).length : 0) + this.digits.length) {
index = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1);

@@ -1056,0 +1085,0 @@ i++;

@@ -577,2 +577,13 @@ "use strict";

});
it('should work with out-of-country dialing prefix (like 00)', function () {
var formatter = new AsYouType('DE');
formatter.input('00498911196611').should.equal('00 49 89 11196611');
formatter.country.should.equal('DE');
formatter.template.should.equal('xx xx xx xxxxxxxx');
formatter.populatedNationalNumberTemplate.should.equal('89 11196611');
formatter.getTemplate().should.equal('xx xx xx xxxxxxxx');
formatter.getNumber().country.should.equal('DE');
formatter.getNumber().nationalNumber.should.equal('8911196611');
formatter.getNumber().number.should.equal('+498911196611');
});
it('shouldn\'t choose a format when there\'re too many digits for any of them', function () {

@@ -579,0 +590,0 @@ var formatter = new AsYouType('RU');

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

import { FIRST_GROUP_PATTERN, formatNationalNumberUsingFormat, applyInternationalSeparatorStyle } from './format_';
import { stripIDDPrefix } from './IDD';
import { checkNumberLengthForType } from './getNumberType_';

@@ -78,3 +79,3 @@ import parseDigits from './parseDigits'; // Used in phone number format template creation.

var MIN_LEADING_DIGITS_LENGTH = 3;
var VALID_FORMATTED_PHONE_NUMBER_PART = '[' + PLUS_CHARS + ']{0,1}' + '[' + VALID_PUNCTUATION + VALID_DIGITS + ']*';
var VALID_FORMATTED_PHONE_NUMBER_PART = '[' + VALID_PUNCTUATION + VALID_DIGITS + ']*';
var VALID_FORMATTED_PHONE_NUMBER_PART_PATTERN = new RegExp('^' + VALID_FORMATTED_PHONE_NUMBER_PART + '$', 'i');

@@ -137,2 +138,3 @@ var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;

this.international = undefined;
this.internationalPrefix = undefined;
this.countryCallingCode = undefined;

@@ -210,3 +212,3 @@ this.digits = '';

if (this.digits) {// If an out of position `+` is detected
if (this.digits || this.isInternational()) {// If an out of position `+` is detected
// (or a second `+`) then just ignore it.

@@ -239,3 +241,20 @@ } else {

value: function inputDigits(nextDigits) {
// Append phone number digits.
// Some users input their phone number in "out-of-country"
// dialing format instead of using the leading `+`.
// https://github.com/catamphetamine/libphonenumber-js/issues/185
// Detect such numbers.
if (!this.digits) {
var numberWithoutIDD = stripIDDPrefix(nextDigits, this.defaultCountry, this.defaultCallingCode, this.metadata.metadata);
if (numberWithoutIDD && numberWithoutIDD !== nextDigits) {
// If an IDD prefix was stripped then
// convert the number to international one
// for subsequent parsing.
this.internationalPrefix = nextDigits.slice(0, nextDigits.length - numberWithoutIDD.length);
nextDigits = numberWithoutIDD;
this.startInternationalNumber();
}
} // Append phone number digits.
this.digits += nextDigits; // Try to format the parsed input

@@ -638,2 +657,7 @@

}
}
}, {
key: "getInternationalPrefix",
value: function getInternationalPrefix(options) {
return this.internationalPrefix ? options && options.spacing === false ? this.internationalPrefix : this.internationalPrefix + ' ' : '+';
} // Prepends `+CountryCode ` in case of an international phone number

@@ -645,11 +669,13 @@

if (this.isInternational()) {
var prefix = this.getInternationalPrefix();
if (!this.countryCallingCode) {
return "+".concat(this.digits);
return "".concat(prefix).concat(this.digits);
}
if (!formattedNationalNumber) {
return "+".concat(this.countryCallingCode);
return "".concat(prefix).concat(this.countryCallingCode);
}
return "+".concat(this.countryCallingCode, " ").concat(formattedNationalNumber);
return "".concat(prefix).concat(this.countryCallingCode, " ").concat(formattedNationalNumber);
}

@@ -766,3 +792,3 @@

if (this.isInternational()) {
this.template = DIGIT_PLACEHOLDER + repeat(DIGIT_PLACEHOLDER, this.countryCallingCode.length) + ' ' + template;
this.template = this.getInternationalPrefix().replace(/[\d\+]/g, DIGIT_PLACEHOLDER) + repeat(DIGIT_PLACEHOLDER, this.countryCallingCode.length) + ' ' + template;
}

@@ -1039,3 +1065,5 @@

while (i < (this.international ? 1 : 0) + this.digits.length) {
while (i < (this.isInternational() ? this.getInternationalPrefix({
spacing: false
}).length : 0) + this.digits.length) {
index = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1);

@@ -1042,0 +1070,0 @@ i++;

@@ -570,2 +570,13 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

});
it('should work with out-of-country dialing prefix (like 00)', function () {
var formatter = new AsYouType('DE');
formatter.input('00498911196611').should.equal('00 49 89 11196611');
formatter.country.should.equal('DE');
formatter.template.should.equal('xx xx xx xxxxxxxx');
formatter.populatedNationalNumberTemplate.should.equal('89 11196611');
formatter.getTemplate().should.equal('xx xx xx xxxxxxxx');
formatter.getNumber().country.should.equal('DE');
formatter.getNumber().nationalNumber.should.equal('8911196611');
formatter.getNumber().number.should.equal('+498911196611');
});
it('shouldn\'t choose a format when there\'re too many digits for any of them', function () {

@@ -572,0 +583,0 @@ var formatter = new AsYouType('RU');

2

package.json
{
"name": "libphonenumber-js",
"version": "1.7.43",
"version": "1.7.44",
"description": "A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript",

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

@@ -38,2 +38,4 @@ // This is an enhanced port of Google Android `libphonenumber`'s

import { stripIDDPrefix } from './IDD'
import { checkNumberLengthForType } from './getNumberType_'

@@ -99,3 +101,2 @@

const VALID_FORMATTED_PHONE_NUMBER_PART =
'[' + PLUS_CHARS + ']{0,1}' +
'[' +

@@ -153,2 +154,3 @@ VALID_PUNCTUATION +

this.international = undefined
this.internationalPrefix = undefined
this.countryCallingCode = undefined

@@ -219,3 +221,3 @@ this.digits = ''

extractedNumber = extractedNumber.slice('+'.length)
if (this.digits) {
if (this.digits || this.isInternational()) {
// If an out of position `+` is detected

@@ -245,2 +247,22 @@ // (or a second `+`) then just ignore it.

inputDigits(nextDigits) {
// Some users input their phone number in "out-of-country"
// dialing format instead of using the leading `+`.
// https://github.com/catamphetamine/libphonenumber-js/issues/185
// Detect such numbers.
if (!this.digits) {
const numberWithoutIDD = stripIDDPrefix(
nextDigits,
this.defaultCountry,
this.defaultCallingCode,
this.metadata.metadata
)
if (numberWithoutIDD && numberWithoutIDD !== nextDigits) {
// If an IDD prefix was stripped then
// convert the number to international one
// for subsequent parsing.
this.internationalPrefix = nextDigits.slice(0, nextDigits.length - numberWithoutIDD.length)
nextDigits = numberWithoutIDD
this.startInternationalNumber()
}
}
// Append phone number digits.

@@ -612,12 +634,19 @@ this.digits += nextDigits

getInternationalPrefix(options) {
return this.internationalPrefix ? (
options && options.spacing === false ? this.internationalPrefix : this.internationalPrefix + ' '
) : '+'
}
// Prepends `+CountryCode ` in case of an international phone number
getFullNumber(formattedNationalNumber) {
if (this.isInternational()) {
const prefix = this.getInternationalPrefix()
if (!this.countryCallingCode) {
return `+${this.digits}`
return `${prefix}${this.digits}`
}
if (!formattedNationalNumber) {
return `+${this.countryCallingCode}`
return `${prefix}${this.countryCallingCode}`
}
return `+${this.countryCallingCode} ${formattedNationalNumber}`
return `${prefix}${this.countryCallingCode} ${formattedNationalNumber}`
}

@@ -730,3 +759,4 @@ return formattedNationalNumber

if (this.isInternational()) {
this.template = DIGIT_PLACEHOLDER +
this.template =
this.getInternationalPrefix().replace(/[\d\+]/g, DIGIT_PLACEHOLDER) +
repeat(DIGIT_PLACEHOLDER, this.countryCallingCode.length) +

@@ -999,3 +1029,3 @@ ' ' +

let i = 0
while (i < (this.international ? 1 : 0) + this.digits.length) {
while (i < (this.isInternational() ? this.getInternationalPrefix({ spacing: false }).length : 0) + this.digits.length) {
index = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)

@@ -1002,0 +1032,0 @@ i++

@@ -673,2 +673,14 @@ import metadata from '../metadata.min.json'

it('should work with out-of-country dialing prefix (like 00)', () => {
const formatter = new AsYouType('DE')
formatter.input('00498911196611').should.equal('00 49 89 11196611')
formatter.country.should.equal('DE')
formatter.template.should.equal('xx xx xx xxxxxxxx')
formatter.populatedNationalNumberTemplate.should.equal('89 11196611')
formatter.getTemplate().should.equal('xx xx xx xxxxxxxx')
formatter.getNumber().country.should.equal('DE')
formatter.getNumber().nationalNumber.should.equal('8911196611')
formatter.getNumber().number.should.equal('+498911196611')
})
it('shouldn\'t choose a format when there\'re too many digits for any of them', () => {

@@ -675,0 +687,0 @@ const formatter = new AsYouType('RU')

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 too big to display

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

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