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.49 to 1.7.50

120

build/AsYouType.js

@@ -152,3 +152,3 @@ "use strict";

this.formattedOutput = '';
this.international = undefined;
this.international = false;
this.internationalPrefix = undefined;

@@ -164,2 +164,61 @@ this.countryCallingCode = undefined;

}, {
key: "resetFormat",
value: function resetFormat() {
this.chosenFormat = undefined;
this.template = undefined;
this.populatedNationalNumberTemplate = undefined;
this.populatedNationalNumberTemplatePosition = -1;
}
/**
* Returns `true` if the phone number is being input in international format.
* In other words, returns `true` if and only if the parsed phone number starts with a `"+"`.
* @return {boolean}
*/
}, {
key: "isInternational",
value: function isInternational() {
return this.international;
}
/**
* Returns the "country calling code" part of the phone number.
* Returns `undefined` if the number is not being input in international format.
* Returns "country calling code" for "non-geographic" phone numbering plans too.
* @return {string} [countryCallingCode]
*/
}, {
key: "getCountryCallingCode",
value: function getCountryCallingCode() {
return this.countryCallingCode;
}
/**
* Returns a two-letter country code of the phone number.
* Returns `undefined` for "non-geographic" phone numbering plans.
* Returns `undefined` if no phone number has been input yet.
* @return {string} [country]
*/
}, {
key: "getCountry",
value: function getCountry() {
// If no digits have been input yet,
// then `this.country` is the `defaultCountry`.
// Won't return the `defaultCountry` in such case.
if (!this.digits) {
return;
}
var countryCode = this.country;
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (this.country === '001') {
countryCode = undefined;
}
}
return countryCode;
}
}, {
key: "setCountry",

@@ -178,10 +237,2 @@ value: function setCountry(country, callingCode) {

}
}, {
key: "resetFormat",
value: function resetFormat() {
this.chosenFormat = undefined;
this.template = undefined;
this.populatedNationalNumberTemplate = undefined;
this.populatedNationalNumberTemplatePosition = -1;
}
/**

@@ -950,7 +1001,2 @@ * Inputs "next" phone number characters.

}, {
key: "isInternational",
value: function isInternational() {
return this.international;
}
}, {
key: "getFormatFormat",

@@ -996,12 +1042,4 @@ value: function getFormatFormat(format) {

var countryCode = this.country;
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (this.country === '001') {
countryCode = undefined;
}
}
var callingCode = this.countryCallingCode || this.defaultCallingCode;
var countryCode = this.getCountry();
var callingCode = this.getCountryCallingCode() || this.defaultCallingCode;
var nationalNumber = this.nationalNumberDigits;

@@ -1039,2 +1077,36 @@ var carrierCode = this.carrierCode; // When an international number without a leading `+` has been autocorrected,

/**
* Returns `true` if the phone number is "possible".
* Is just a shortcut for `PhoneNumber.isPossible()`.
* @return {boolean}
*/
}, {
key: "isPossible",
value: function isPossible() {
var phoneNumber = this.getNumber();
if (!phoneNumber) {
return false;
}
return phoneNumber.isPossible();
}
/**
* Returns `true` if the phone number is "valid".
* Is just a shortcut for `PhoneNumber.isValid()`.
* @return {boolean}
*/
}, {
key: "isValid",
value: function isValid() {
var phoneNumber = this.getNumber();
if (!phoneNumber) {
return false;
}
return phoneNumber.isValid();
}
/**
* @deprecated

@@ -1041,0 +1113,0 @@ * This method is used in `react-phone-number-input/source/input-control.js`

78

build/AsYouType.test.js

@@ -650,3 +650,2 @@ "use strict";

});
756789;
it('should repeat string N times', function () {

@@ -657,2 +656,79 @@ (0, _AsYouType.repeat)('a', 0).should.equal('');

});
it('should return if the number is possible', function () {
// National. Russia.
var formatter = new AsYouType('RU');
formatter.isPossible().should.equal(false);
formatter.input('8');
formatter.isPossible().should.equal(false);
formatter.input('8005553535');
formatter.isPossible().should.equal(true);
formatter.input('5');
formatter.isPossible().should.equal(false);
});
it('should return if the number is valid', function () {
// National. Russia.
var formatter = new AsYouType('RU');
formatter.isValid().should.equal(false);
formatter.input('88005553535');
formatter.isValid().should.equal(true);
formatter.input('5');
formatter.isValid().should.equal(false);
});
it('should return if the number is international', function () {
// National. Russia.
var formatter = new AsYouType('RU');
formatter.isInternational().should.equal(false);
formatter.input('88005553535');
formatter.isInternational().should.equal(false); // International. Russia.
var formatterInt = new AsYouType();
formatterInt.isInternational().should.equal(false);
formatterInt.input('+');
formatterInt.isInternational().should.equal(true);
formatterInt.input('78005553535');
formatterInt.isInternational().should.equal(true);
});
it('should return country calling code part of the number', function () {
// National. Russia.
var formatter = new AsYouType('RU');
expect(formatter.getCountryCallingCode()).to.be.undefined;
formatter.input('88005553535');
expect(formatter.getCountryCallingCode()).to.be.undefined; // International. Russia.
var formatterInt = new AsYouType();
expect(formatterInt.getCountryCallingCode()).to.be.undefined;
formatterInt.input('+');
expect(formatterInt.getCountryCallingCode()).to.be.undefined;
formatterInt.input('7');
expect(formatterInt.getCountryCallingCode()).to.equal('7');
formatterInt.input('8005553535');
expect(formatterInt.getCountryCallingCode()).to.equal('7');
});
it('should return the country of the number', function () {
// National. Russia.
var formatter = new AsYouType('RU');
expect(formatter.getCountry()).to.be.undefined;
formatter.input('8');
expect(formatter.getCountry()).to.equal('RU');
formatter.input('8005553535');
expect(formatter.getCountry()).to.equal('RU'); // International. Austria.
var formatterInt = new AsYouType();
expect(formatterInt.getCountry()).to.be.undefined;
formatterInt.input('+');
expect(formatterInt.getCountry()).to.be.undefined;
formatterInt.input('43');
expect(formatterInt.getCountry()).to.equal('AT'); // International. USA.
var formatterIntRu = new AsYouType();
expect(formatterIntRu.getCountry()).to.be.undefined;
formatterIntRu.input('+');
expect(formatterIntRu.getCountry()).to.be.undefined;
formatterIntRu.input('1');
expect(formatterIntRu.getCountry()).to.be.undefined;
formatterIntRu.input('2133734253');
expect(formatterIntRu.getCountry()).to.equal('US');
formatterIntRu.input('1');
expect(formatterIntRu.getCountry()).to.be.undefined;
});
});

@@ -659,0 +735,0 @@

@@ -56,2 +56,46 @@ <!-- (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.7.50 / 05.04.2020
===================
* [Added](https://github.com/catamphetamine/libphonenumber-js/issues/388#issuecomment-609036293) some utility functions to `AsYouType`:
```js
/**
* Returns `true` if the phone number is being input in international format.
* In other words, returns `true` if and only if the parsed phone number starts with a `"+"`.
* @return {boolean}
*/
isInternational()
/**
* Returns the "country calling code" part of the phone number.
* Returns `undefined` if the number is not being input in international format.
* Returns "country calling code" for "non-geographic" phone numbering plans too.
* @return {string} [countryCallingCode]
*/
getCountryCallingCode()
/**
* Returns a two-letter country code of the phone number.
* Returns `undefined` for "non-geographic" phone numbering plans.
* Returns `undefined` if no phone number has been input yet.
* @return {string} [country]
*/
getCountry()
/**
* Returns `true` if the phone number is "possible".
* Is just a shortcut for `PhoneNumber.isPossible()`.
* @return {boolean}
*/
isPossible()
/**
* Returns `true` if the phone number is "valid".
* Is just a shortcut for `PhoneNumber.isValid()`.
* @return {boolean}
*/
isValid()
```
1.7.38 / 04.02.2020

@@ -58,0 +102,0 @@ ===================

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

this.formattedOutput = '';
this.international = undefined;
this.international = false;
this.internationalPrefix = undefined;

@@ -149,2 +149,61 @@ this.countryCallingCode = undefined;

}, {
key: "resetFormat",
value: function resetFormat() {
this.chosenFormat = undefined;
this.template = undefined;
this.populatedNationalNumberTemplate = undefined;
this.populatedNationalNumberTemplatePosition = -1;
}
/**
* Returns `true` if the phone number is being input in international format.
* In other words, returns `true` if and only if the parsed phone number starts with a `"+"`.
* @return {boolean}
*/
}, {
key: "isInternational",
value: function isInternational() {
return this.international;
}
/**
* Returns the "country calling code" part of the phone number.
* Returns `undefined` if the number is not being input in international format.
* Returns "country calling code" for "non-geographic" phone numbering plans too.
* @return {string} [countryCallingCode]
*/
}, {
key: "getCountryCallingCode",
value: function getCountryCallingCode() {
return this.countryCallingCode;
}
/**
* Returns a two-letter country code of the phone number.
* Returns `undefined` for "non-geographic" phone numbering plans.
* Returns `undefined` if no phone number has been input yet.
* @return {string} [country]
*/
}, {
key: "getCountry",
value: function getCountry() {
// If no digits have been input yet,
// then `this.country` is the `defaultCountry`.
// Won't return the `defaultCountry` in such case.
if (!this.digits) {
return;
}
var countryCode = this.country;
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (this.country === '001') {
countryCode = undefined;
}
}
return countryCode;
}
}, {
key: "setCountry",

@@ -163,10 +222,2 @@ value: function setCountry(country, callingCode) {

}
}, {
key: "resetFormat",
value: function resetFormat() {
this.chosenFormat = undefined;
this.template = undefined;
this.populatedNationalNumberTemplate = undefined;
this.populatedNationalNumberTemplatePosition = -1;
}
/**

@@ -935,7 +986,2 @@ * Inputs "next" phone number characters.

}, {
key: "isInternational",
value: function isInternational() {
return this.international;
}
}, {
key: "getFormatFormat",

@@ -981,12 +1027,4 @@ value: function getFormatFormat(format) {

var countryCode = this.country;
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (this.country === '001') {
countryCode = undefined;
}
}
var callingCode = this.countryCallingCode || this.defaultCallingCode;
var countryCode = this.getCountry();
var callingCode = this.getCountryCallingCode() || this.defaultCallingCode;
var nationalNumber = this.nationalNumberDigits;

@@ -1024,2 +1062,36 @@ var carrierCode = this.carrierCode; // When an international number without a leading `+` has been autocorrected,

/**
* Returns `true` if the phone number is "possible".
* Is just a shortcut for `PhoneNumber.isPossible()`.
* @return {boolean}
*/
}, {
key: "isPossible",
value: function isPossible() {
var phoneNumber = this.getNumber();
if (!phoneNumber) {
return false;
}
return phoneNumber.isPossible();
}
/**
* Returns `true` if the phone number is "valid".
* Is just a shortcut for `PhoneNumber.isValid()`.
* @return {boolean}
*/
}, {
key: "isValid",
value: function isValid() {
var phoneNumber = this.getNumber();
if (!phoneNumber) {
return false;
}
return phoneNumber.isValid();
}
/**
* @deprecated

@@ -1026,0 +1098,0 @@ * This method is used in `react-phone-number-input/source/input-control.js`

@@ -643,3 +643,2 @@ 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); }

});
756789;
it('should repeat string N times', function () {

@@ -650,2 +649,79 @@ repeat('a', 0).should.equal('');

});
it('should return if the number is possible', function () {
// National. Russia.
var formatter = new AsYouType('RU');
formatter.isPossible().should.equal(false);
formatter.input('8');
formatter.isPossible().should.equal(false);
formatter.input('8005553535');
formatter.isPossible().should.equal(true);
formatter.input('5');
formatter.isPossible().should.equal(false);
});
it('should return if the number is valid', function () {
// National. Russia.
var formatter = new AsYouType('RU');
formatter.isValid().should.equal(false);
formatter.input('88005553535');
formatter.isValid().should.equal(true);
formatter.input('5');
formatter.isValid().should.equal(false);
});
it('should return if the number is international', function () {
// National. Russia.
var formatter = new AsYouType('RU');
formatter.isInternational().should.equal(false);
formatter.input('88005553535');
formatter.isInternational().should.equal(false); // International. Russia.
var formatterInt = new AsYouType();
formatterInt.isInternational().should.equal(false);
formatterInt.input('+');
formatterInt.isInternational().should.equal(true);
formatterInt.input('78005553535');
formatterInt.isInternational().should.equal(true);
});
it('should return country calling code part of the number', function () {
// National. Russia.
var formatter = new AsYouType('RU');
expect(formatter.getCountryCallingCode()).to.be.undefined;
formatter.input('88005553535');
expect(formatter.getCountryCallingCode()).to.be.undefined; // International. Russia.
var formatterInt = new AsYouType();
expect(formatterInt.getCountryCallingCode()).to.be.undefined;
formatterInt.input('+');
expect(formatterInt.getCountryCallingCode()).to.be.undefined;
formatterInt.input('7');
expect(formatterInt.getCountryCallingCode()).to.equal('7');
formatterInt.input('8005553535');
expect(formatterInt.getCountryCallingCode()).to.equal('7');
});
it('should return the country of the number', function () {
// National. Russia.
var formatter = new AsYouType('RU');
expect(formatter.getCountry()).to.be.undefined;
formatter.input('8');
expect(formatter.getCountry()).to.equal('RU');
formatter.input('8005553535');
expect(formatter.getCountry()).to.equal('RU'); // International. Austria.
var formatterInt = new AsYouType();
expect(formatterInt.getCountry()).to.be.undefined;
formatterInt.input('+');
expect(formatterInt.getCountry()).to.be.undefined;
formatterInt.input('43');
expect(formatterInt.getCountry()).to.equal('AT'); // International. USA.
var formatterIntRu = new AsYouType();
expect(formatterIntRu.getCountry()).to.be.undefined;
formatterIntRu.input('+');
expect(formatterIntRu.getCountry()).to.be.undefined;
formatterIntRu.input('1');
expect(formatterIntRu.getCountry()).to.be.undefined;
formatterIntRu.input('2133734253');
expect(formatterIntRu.getCountry()).to.equal('US');
formatterIntRu.input('1');
expect(formatterIntRu.getCountry()).to.be.undefined;
});
});

@@ -652,0 +728,0 @@

{
"name": "libphonenumber-js",
"version": "1.7.49",
"version": "1.7.50",
"description": "A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript",

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

@@ -173,3 +173,3 @@ // This is an enhanced port of Google Android `libphonenumber`'s

this.formattedOutput = ''
this.international = undefined
this.international = false
this.internationalPrefix = undefined

@@ -185,2 +185,51 @@ this.countryCallingCode = undefined

resetFormat() {
this.chosenFormat = undefined
this.template = undefined
this.populatedNationalNumberTemplate = undefined
this.populatedNationalNumberTemplatePosition = -1
}
/**
* Returns `true` if the phone number is being input in international format.
* In other words, returns `true` if and only if the parsed phone number starts with a `"+"`.
* @return {boolean}
*/
isInternational() {
return this.international
}
/**
* Returns the "country calling code" part of the phone number.
* Returns `undefined` if the number is not being input in international format.
* Returns "country calling code" for "non-geographic" phone numbering plans too.
* @return {string} [countryCallingCode]
*/
getCountryCallingCode() {
return this.countryCallingCode
}
/**
* Returns a two-letter country code of the phone number.
* Returns `undefined` for "non-geographic" phone numbering plans.
* Returns `undefined` if no phone number has been input yet.
* @return {string} [country]
*/
getCountry() {
// If no digits have been input yet,
// then `this.country` is the `defaultCountry`.
// Won't return the `defaultCountry` in such case.
if (!this.digits) {
return
}
let countryCode = this.country
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (this.country === '001') {
countryCode = undefined
}
}
return countryCode
}
setCountry(country, callingCode) {

@@ -197,9 +246,2 @@ this.country = country

resetFormat() {
this.chosenFormat = undefined
this.template = undefined
this.populatedNationalNumberTemplate = undefined
this.populatedNationalNumberTemplatePosition = -1
}
/**

@@ -924,6 +966,2 @@ * Inputs "next" phone number characters.

isInternational() {
return this.international
}
getFormatFormat(format) {

@@ -966,10 +1004,4 @@ if (this.isInternational()) {

}
let countryCode = this.country
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (this.country === '001') {
countryCode = undefined
}
}
const callingCode = this.countryCallingCode || this.defaultCallingCode
let countryCode = this.getCountry()
const callingCode = this.getCountryCallingCode() || this.defaultCallingCode
let nationalNumber = this.nationalNumberDigits

@@ -1017,2 +1049,28 @@ let carrierCode = this.carrierCode

/**
* Returns `true` if the phone number is "possible".
* Is just a shortcut for `PhoneNumber.isPossible()`.
* @return {boolean}
*/
isPossible() {
const phoneNumber = this.getNumber()
if (!phoneNumber) {
return false
}
return phoneNumber.isPossible()
}
/**
* Returns `true` if the phone number is "valid".
* Is just a shortcut for `PhoneNumber.isValid()`.
* @return {boolean}
*/
isValid() {
const phoneNumber = this.getNumber()
if (!phoneNumber) {
return false
}
return phoneNumber.isValid()
}
/**
* @deprecated

@@ -1019,0 +1077,0 @@ * This method is used in `react-phone-number-input/source/input-control.js`

@@ -751,4 +751,2 @@ import metadata from '../metadata.min.json'

756789
it('should repeat string N times', () => {

@@ -759,2 +757,84 @@ repeat('a', 0).should.equal('')

})
it('should return if the number is possible', () => {
// National. Russia.
const formatter = new AsYouType('RU')
formatter.isPossible().should.equal(false)
formatter.input('8')
formatter.isPossible().should.equal(false)
formatter.input('8005553535')
formatter.isPossible().should.equal(true)
formatter.input('5')
formatter.isPossible().should.equal(false)
})
it('should return if the number is valid', () => {
// National. Russia.
const formatter = new AsYouType('RU')
formatter.isValid().should.equal(false)
formatter.input('88005553535')
formatter.isValid().should.equal(true)
formatter.input('5')
formatter.isValid().should.equal(false)
})
it('should return if the number is international', () => {
// National. Russia.
const formatter = new AsYouType('RU')
formatter.isInternational().should.equal(false)
formatter.input('88005553535')
formatter.isInternational().should.equal(false)
// International. Russia.
const formatterInt = new AsYouType()
formatterInt.isInternational().should.equal(false)
formatterInt.input('+')
formatterInt.isInternational().should.equal(true)
formatterInt.input('78005553535')
formatterInt.isInternational().should.equal(true)
})
it('should return country calling code part of the number', () => {
// National. Russia.
const formatter = new AsYouType('RU')
expect(formatter.getCountryCallingCode()).to.be.undefined
formatter.input('88005553535')
expect(formatter.getCountryCallingCode()).to.be.undefined
// International. Russia.
const formatterInt = new AsYouType()
expect(formatterInt.getCountryCallingCode()).to.be.undefined
formatterInt.input('+')
expect(formatterInt.getCountryCallingCode()).to.be.undefined
formatterInt.input('7')
expect(formatterInt.getCountryCallingCode()).to.equal('7')
formatterInt.input('8005553535')
expect(formatterInt.getCountryCallingCode()).to.equal('7')
})
it('should return the country of the number', () => {
// National. Russia.
const formatter = new AsYouType('RU')
expect(formatter.getCountry()).to.be.undefined
formatter.input('8')
expect(formatter.getCountry()).to.equal('RU')
formatter.input('8005553535')
expect(formatter.getCountry()).to.equal('RU')
// International. Austria.
const formatterInt = new AsYouType()
expect(formatterInt.getCountry()).to.be.undefined
formatterInt.input('+')
expect(formatterInt.getCountry()).to.be.undefined
formatterInt.input('43')
expect(formatterInt.getCountry()).to.equal('AT')
// International. USA.
const formatterIntRu = new AsYouType()
expect(formatterIntRu.getCountry()).to.be.undefined
formatterIntRu.input('+')
expect(formatterIntRu.getCountry()).to.be.undefined
formatterIntRu.input('1')
expect(formatterIntRu.getCountry()).to.be.undefined
formatterIntRu.input('2133734253')
expect(formatterIntRu.getCountry()).to.equal('US')
formatterIntRu.input('1')
expect(formatterIntRu.getCountry()).to.be.undefined
})
})

@@ -761,0 +841,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 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

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