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.37 to 1.7.38

19

build/AsYouType.js

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

var VALID_FORMATTED_PHONE_NUMBER_PART_PATTERN = new RegExp('^' + VALID_FORMATTED_PHONE_NUMBER_PART + '$', 'i');
var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;

@@ -130,4 +131,7 @@ var AsYouType =

if (defaultCallingCode) {
if (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {
this.defaultCountry = '001';
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {
this.defaultCountry = '001';
}
}

@@ -994,4 +998,13 @@

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 phoneNumber = new _PhoneNumber["default"](this.country === '001' ? callingCode : this.country || callingCode, this.nationalNumberDigits, this.metadata.metadata);
var phoneNumber = new _PhoneNumber["default"](countryCode || callingCode, this.nationalNumberDigits, this.metadata.metadata);

@@ -998,0 +1011,0 @@ if (this.carrierCode) {

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

var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
describe('as you type', function () {

@@ -469,3 +470,3 @@ it('should use "national_prefix_formatting_rule"', function () {

});
it('should format non-geographical numbering plan phone numbers', function () {
it('should format non-geographic numbering plan phone numbers', function () {
var formatter = new AsYouType();

@@ -477,3 +478,9 @@ formatter.input('+').should.equal('+');

formatter.input('0').should.equal('+870');
formatter.country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.country.should.equal('001');
} else {
expect(formatter.country).to.be.undefined;
}
formatter.input('7').should.equal('+870 7');

@@ -488,10 +495,22 @@ formatter.input('7').should.equal('+870 77');

formatter.input('2').should.equal('+870 773 111 632');
formatter.getNumber().country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.getNumber().country.should.equal('001');
} else {
expect(formatter.country).to.be.undefined;
}
formatter.getNumber().countryCallingCode.should.equal('870');
});
it('should format non-geographical numbering plan phone numbers (default country calling code)', function () {
it('should format non-geographic numbering plan phone numbers (default country calling code)', function () {
var formatter = new AsYouType({
defaultCallingCode: '870'
});
formatter.country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.getNumber().country.should.equal('001');
} else {
expect(formatter.country).to.be.undefined;
}
formatter.input('7').should.equal('7');

@@ -506,7 +525,15 @@ formatter.input('7').should.equal('77');

formatter.input('2').should.equal('773 111 632');
formatter.getNumber().country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.getNumber().country.should.equal('001');
} else {
expect(formatter.country).to.be.undefined;
}
formatter.getNumber().countryCallingCode.should.equal('870');
});
it('should not format non-geographical numbering plan phone numbers (default country 001)', function () {
it('should not format non-geographic numbering plan phone numbers (default country 001)', function () {
var formatter = new AsYouType('001');
expect(formatter.defaultCountry).to.be.undefined;
expect(formatter.defaultCallingCode).to.be.undefined;
formatter.input('7').should.equal('7');

@@ -513,0 +540,0 @@ formatter.input('7').should.equal('77');

2

build/format.test.js

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

});
it('should format non-geographical numbering plan phone numbers', function () {
it('should format non-geographic numbering plan phone numbers', function () {
// https://github.com/catamphetamine/libphonenumber-js/issues/323

@@ -272,0 +272,0 @@ formatNumber('+870773111632', 'INTERNATIONAL').should.equal('+870 773 111 632');

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

} else {
// For non-geographical countries, Mexican and Chilean fixed line and
// For non-geographic countries, Mexican and Chilean fixed line and
// mobile numbers, we output international format for numbers that can be

@@ -94,0 +94,0 @@ // dialed internationally, as that always works.

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

// The rare case has been encountered where no fixedLine data is available
// (true for some non-geographical entities), so we just check mobile.
// (true for some non-geographic entities), so we just check mobile.
return checkNumberLengthForType(nationalNumber, 'MOBILE', metadata);

@@ -116,0 +116,0 @@ }

@@ -52,4 +52,11 @@ "use strict";

} else {
// There was a bug between `1.7.35` and `1.7.37` where "possible_lengths"
// were missing for "non-geographical" numbering plans.
// Just assume the number is possible in such cases:
// it's unlikely that anyone generated their custom metadata
// in that short period of time (one day).
// This code can be removed in some future major version update.
if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
// "Non-geographical entities" don't have `possibleLengths`.
// "Non-geographic entities" did't have `possibleLengths`
// due to a bug in metadata generation process.
return true;

@@ -56,0 +63,0 @@ } else {

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

var V3 = '1.2.0'; // Moved `001` country code to "nonGeographical" section of metadata.
var V3 = '1.2.0'; // Moved `001` country code to "nonGeographic" section of metadata.

@@ -61,6 +61,8 @@ var V4 = '1.7.35';

}, {
key: "nonGeographical",
value: function nonGeographical() {
if (this.v1 || this.v2 || this.v3) return;
return this.metadata.nonGeographical;
key: "nonGeographic",
value: function nonGeographic() {
if (this.v1 || this.v2 || this.v3) return; // `nonGeographical` was a typo.
// It's present in metadata generated from `1.7.35` to `1.7.37`.
return this.metadata.nonGeographic || this.metadata.nonGeographical;
}

@@ -79,4 +81,4 @@ }, {

if (this.nonGeographical()) {
if (this.nonGeographical()[callingCode]) {
if (this.nonGeographic()) {
if (this.nonGeographic()[callingCode]) {
return true;

@@ -96,6 +98,6 @@ }

value: function isNonGeographicCallingCode(callingCode) {
if (this.nonGeographical()) {
if (this.nonGeographical()[callingCode]) {
return true;
}
if (this.nonGeographic()) {
return this.nonGeographic()[callingCode] ? true : false;
} else {
return this.getCountryCodesForCallingCode(callingCode) ? false : true;
}

@@ -170,4 +172,4 @@ } // Deprecated.

if (this.nonGeographical()) {
var metadata = this.nonGeographical()[callingCode];
if (this.nonGeographic()) {
var metadata = this.nonGeographic()[callingCode];

@@ -174,0 +176,0 @@ if (metadata) {

@@ -52,3 +52,4 @@ "use strict";

var AFTER_PHONE_NUMBER_END_PATTERN = new RegExp('[^' + _constants.VALID_DIGITS + ']+$'); // `options`:
var AFTER_PHONE_NUMBER_END_PATTERN = new RegExp('[^' + _constants.VALID_DIGITS + ']+$');
var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false; // `options`:
// {

@@ -174,3 +175,3 @@ // country:

var valid = country && (0, _util.matchesEntirely)(nationalNumber, metadata.nationalNumberPattern()) ? true : false;
var valid = (options.extended ? metadata.hasSelectedNumberingPlan() : country) ? (0, _util.matchesEntirely)(nationalNumber, metadata.nationalNumberPattern()) : false;

@@ -186,3 +187,3 @@ if (!options.extended) {

valid: valid,
possible: valid ? true : options.extended === true && metadata.possibleLengths() && (0, _isPossibleNumber_.isPossibleNumber)(nationalNumber, countryCallingCode !== undefined, metadata),
possible: valid ? true : options.extended === true && metadata.possibleLengths() && (0, _isPossibleNumber_.isPossibleNumber)(nationalNumber, countryCallingCode !== undefined, metadata) ? true : false,
phone: nationalNumber,

@@ -316,4 +317,7 @@ ext: ext

function findCountryCode(callingCode, nationalPhoneNumber, metadata) {
if (metadata.isNonGeographicCallingCode(callingCode)) {
return '001';
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (metadata.isNonGeographicCallingCode(callingCode)) {
return '001';
}
} // Is always non-empty, because `callingCode` is always valid

@@ -440,3 +444,14 @@

metadata.selectNumberingPlan(defaultCountry, defaultCallingCode);
country = defaultCountry || (metadata.isNonGeographicCallingCode(defaultCallingCode) ? '001' : undefined);
if (defaultCountry) {
country = defaultCountry;
} else {
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (metadata.isNonGeographicCallingCode(defaultCallingCode)) {
country = '001';
}
}
}
countryCallingCode = defaultCallingCode || (0, _getCountryCallingCode["default"])(defaultCountry, metadata.metadata);

@@ -469,4 +484,8 @@ } else return {};

country = exactCountry;
/* istanbul ignore if */
if (country !== '001') {
if (exactCountry === '001') {// Can't happen with `USE_NON_GEOGRAPHIC_COUNTRY_CODE` being `false`.
// If `USE_NON_GEOGRAPHIC_COUNTRY_CODE` is set to `true` for some reason,
// then remove the "istanbul ignore if".
} else {
metadata.country(country);

@@ -473,0 +492,0 @@ }

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

var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
describe('parse', function () {

@@ -425,21 +426,21 @@ it('should not parse invalid phone numbers', function () {

});
it('should parse non-geographical numbering plan phone numbers', function () {
parseNumber('+870773111632').should.deep.equal({
it('should parse non-geographic numbering plan phone numbers', function () {
parseNumber('+870773111632').should.deep.equal(USE_NON_GEOGRAPHIC_COUNTRY_CODE ? {
country: '001',
phone: '773111632'
});
} : {});
});
it('should parse non-geographical numbering plan phone numbers (default country code)', function () {
it('should parse non-geographic numbering plan phone numbers (default country code)', function () {
parseNumber('773111632', {
defaultCallingCode: '870'
}).should.deep.equal({
}).should.deep.equal(USE_NON_GEOGRAPHIC_COUNTRY_CODE ? {
country: '001',
phone: '773111632'
});
} : {});
});
it('should parse non-geographical numbering plan phone numbers (extended)', function () {
it('should parse non-geographic numbering plan phone numbers (extended)', function () {
parseNumber('+870773111632', {
extended: true
}).should.deep.equal({
country: '001',
country: USE_NON_GEOGRAPHIC_COUNTRY_CODE ? '001' : undefined,
countryCallingCode: '870',

@@ -453,3 +454,3 @@ phone: '773111632',

});
it('should parse non-geographical numbering plan phone numbers (default country code) (extended)', function () {
it('should parse non-geographic numbering plan phone numbers (default country code) (extended)', function () {
parseNumber('773111632', {

@@ -459,3 +460,3 @@ defaultCallingCode: '870',

}).should.deep.equal({
country: '001',
country: USE_NON_GEOGRAPHIC_COUNTRY_CODE ? '001' : undefined,
countryCallingCode: '870',

@@ -476,3 +477,3 @@ phone: '773111632',

});
it('shouldn\'t set `country` when there\'s no `defaultCountry` and `defaultCallingCode` is not of a "non-geographical entity"', function () {
it('shouldn\'t set `country` when there\'s no `defaultCountry` and `defaultCallingCode` is not of a "non-geographic entity"', function () {
parseNumber('88005553535', {

@@ -479,0 +480,0 @@ defaultCallingCode: '7'

@@ -131,7 +131,3 @@ "use strict";

});
it('shouldn\'t throw when "possibleLengths" are missing on "non-geographical entities" metadata', function () {
var phoneNumber = parsePhoneNumber('+870773111632');
phoneNumber.isPossible().should.equal(true);
});
});
//# sourceMappingURL=parsePhoneNumber.test.js.map

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

var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
describe('parsePhoneNumberFromString', function () {

@@ -31,9 +32,15 @@ it('should parse phone numbers from string', function () {

});
it('should parse non-geographical numbering plan phone numbers (extended)', function () {
it('should parse non-geographic numbering plan phone numbers (extended)', function () {
var phoneNumber = parsePhoneNumberFromString('+870773111632');
phoneNumber.number.should.equal('+870773111632');
phoneNumber.country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
phoneNumber.country.should.equal('001');
} else {
expect(phoneNumber.country).to.be.undefined;
}
phoneNumber.countryCallingCode.should.equal('870');
});
it('should parse non-geographical numbering plan phone numbers (default country code) (extended)', function () {
it('should parse non-geographic numbering plan phone numbers (default country code) (extended)', function () {
var phoneNumber = parsePhoneNumberFromString('773111632', {

@@ -43,6 +50,18 @@ defaultCallingCode: '870'

phoneNumber.number.should.equal('+870773111632');
phoneNumber.country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
phoneNumber.country.should.equal('001');
} else {
expect(phoneNumber.country).to.be.undefined;
}
phoneNumber.countryCallingCode.should.equal('870');
});
it('should determine the possibility of non-geographic phone numbers', function () {
var phoneNumber = parsePhoneNumberFromString('+870773111632');
phoneNumber.isPossible().should.equal(true);
var phoneNumber2 = parsePhoneNumberFromString('+8707731116321');
phoneNumber2.isPossible().should.equal(false);
});
});
//# sourceMappingURL=parsePhoneNumberFromString.test.js.map

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

var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
var PhoneNumber =

@@ -40,3 +42,3 @@ /*#__PURE__*/

if (!countryCallingCode) {
throw new TypeError('`countryCallingCode` not passed');
throw new TypeError('`country` or `countryCallingCode` not passed');
}

@@ -58,4 +60,9 @@

countryCallingCode = _metadata.countryCallingCode();
} else if (_metadata.isNonGeographicCallingCode(countryCallingCode)) {
this.country = '001';
} else {
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (_metadata.isNonGeographicCallingCode(countryCallingCode)) {
this.country = '001';
}
}
}

@@ -84,2 +91,8 @@

}, {
key: "isNonGeographic",
value: function isNonGeographic() {
var metadata = new _metadata2["default"](this.metadata);
return metadata.isNonGeographicCallingCode(this.countryCallingCode);
}
}, {
key: "isEqual",

@@ -86,0 +99,0 @@ value: function isEqual(phoneNumber) {

@@ -38,3 +38,7 @@ "use strict";

});
it('should tell if a number is non-geographic', function () {
new _PhoneNumber["default"]('7', '8005553535', _metadata["default"]).isNonGeographic().should.equal(false);
new _PhoneNumber["default"]('870', '773111632', _metadata["default"]).isNonGeographic().should.equal(true);
});
});
//# sourceMappingURL=PhoneNumber.test.js.map

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

if (this.options.v2) {
var phoneNumber = new _PhoneNumber["default"](match.country === '001' ? match.countryCallingCode : match.country, match.phone, this.metadata);
var phoneNumber = new _PhoneNumber["default"](match.country || match.countryCallingCode, match.phone, this.metadata);

@@ -326,7 +326,8 @@ if (match.ext) {

endsAt: offset + candidate.length,
country: number.country,
phone: number.phone
};
if (result.country === '001') {
if (number.country && number.country !== '001') {
result.country = number.country;
} else {
result.countryCallingCode = number.countryCallingCode;

@@ -333,0 +334,0 @@ }

@@ -16,7 +16,7 @@ "use strict";

var nonGeographical = {};
var nonGeographic = {};
for (var _i2 = 0, _Object$keys2 = Object.keys(input.nonGeographical); _i2 < _Object$keys2.length; _i2++) {
for (var _i2 = 0, _Object$keys2 = Object.keys(input.nonGeographic); _i2 < _Object$keys2.length; _i2++) {
var callingCode = _Object$keys2[_i2];
nonGeographical[callingCode] = compressNumberingPlan(input.nonGeographical[callingCode]);
nonGeographic[callingCode] = compressNumberingPlan(input.nonGeographic[callingCode]);
}

@@ -28,3 +28,3 @@

countries: countries,
nonGeographical: nonGeographical
nonGeographic: nonGeographic
};

@@ -31,0 +31,0 @@ }

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

var countries = {};
var nonGeographical = {};
var nonGeographic = {};

@@ -397,3 +397,5 @@ var _loop2 = function _loop2() {

if (country_code === '001') {
nonGeographical[country.phone_code] = country;
nonGeographic[country.phone_code] = country; // Populate numbering plan possible lengths.
populateNumberingPlanPossibleLengths(country);
} else {

@@ -508,5 +510,5 @@ // Add this country's metadata

visited_countries[_country_code] = true; // Populate possible lengths
visited_countries[_country_code] = true; // Populate numbering plan possible lengths.
populate_possible_lengths(countries[_country_code]);
populateNumberingPlanPossibleLengths(countries[_country_code]);

@@ -590,3 +592,3 @@ if (countries[_country_code].possible_lengths.length === 0) {

country_calling_codes: country_calling_code_to_countries,
nonGeographical: nonGeographical
nonGeographic: nonGeographic
};

@@ -731,4 +733,10 @@ });

};
/**
* Sets `metadata.possible_lengths` to a combination of `possible_length`s
* of all types present in the numbering plan metadata.
* @param {object} metadata
*/
function populate_possible_lengths(metadata) {
function populateNumberingPlanPossibleLengths(metadata) {
var types = metadata.types;

@@ -735,0 +743,0 @@ var possible_lengths = new Set();

@@ -9,4 +9,7 @@ "use strict";

// Checks whether the entire input sequence can be matched
// against the regular expression.
/**
* Checks whether the entire input sequence can be matched
* against the regular expression.
* @return {boolean}
*/
function matchesEntirely(text, regular_expression) {

@@ -13,0 +16,0 @@ // If assigning the `''` default value is moved to the arguments above,

@@ -56,6 +56,13 @@ <!-- (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.38 / 04.02.2020
===================
* Removed the `"001"` country code ("Non-Geographic Entity"): now in case of "non-geographic" phone numbers their `country` is just `undefined`. Instead, `PhoneNumber` class has an `.isNonGeographic()` method.
* Fixed "non-geographic" numbers `.isPossible() === false` bug.
1.7.35 / 03.02.2020
===================
* Fixed "Non-Geographical Entities" (`001` country code).
* Fixed "Non-Geographic Entities" (`001` country code).

@@ -62,0 +69,0 @@ 1.7.32 / 03.02.2020

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

var VALID_FORMATTED_PHONE_NUMBER_PART_PATTERN = new RegExp('^' + VALID_FORMATTED_PHONE_NUMBER_PART + '$', 'i');
var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;

@@ -116,4 +117,7 @@ var AsYouType =

if (defaultCallingCode) {
if (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {
this.defaultCountry = '001';
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {
this.defaultCountry = '001';
}
}

@@ -980,4 +984,13 @@

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 phoneNumber = new PhoneNumber(this.country === '001' ? callingCode : this.country || callingCode, this.nationalNumberDigits, this.metadata.metadata);
var phoneNumber = new PhoneNumber(countryCode || callingCode, this.nationalNumberDigits, this.metadata.metadata);

@@ -984,0 +997,0 @@ if (this.carrierCode) {

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

var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
describe('as you type', function () {

@@ -462,3 +463,3 @@ it('should use "national_prefix_formatting_rule"', function () {

});
it('should format non-geographical numbering plan phone numbers', function () {
it('should format non-geographic numbering plan phone numbers', function () {
var formatter = new AsYouType();

@@ -470,3 +471,9 @@ formatter.input('+').should.equal('+');

formatter.input('0').should.equal('+870');
formatter.country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.country.should.equal('001');
} else {
expect(formatter.country).to.be.undefined;
}
formatter.input('7').should.equal('+870 7');

@@ -481,10 +488,22 @@ formatter.input('7').should.equal('+870 77');

formatter.input('2').should.equal('+870 773 111 632');
formatter.getNumber().country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.getNumber().country.should.equal('001');
} else {
expect(formatter.country).to.be.undefined;
}
formatter.getNumber().countryCallingCode.should.equal('870');
});
it('should format non-geographical numbering plan phone numbers (default country calling code)', function () {
it('should format non-geographic numbering plan phone numbers (default country calling code)', function () {
var formatter = new AsYouType({
defaultCallingCode: '870'
});
formatter.country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.getNumber().country.should.equal('001');
} else {
expect(formatter.country).to.be.undefined;
}
formatter.input('7').should.equal('7');

@@ -499,7 +518,15 @@ formatter.input('7').should.equal('77');

formatter.input('2').should.equal('773 111 632');
formatter.getNumber().country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.getNumber().country.should.equal('001');
} else {
expect(formatter.country).to.be.undefined;
}
formatter.getNumber().countryCallingCode.should.equal('870');
});
it('should not format non-geographical numbering plan phone numbers (default country 001)', function () {
it('should not format non-geographic numbering plan phone numbers (default country 001)', function () {
var formatter = new AsYouType('001');
expect(formatter.defaultCountry).to.be.undefined;
expect(formatter.defaultCallingCode).to.be.undefined;
formatter.input('7').should.equal('7');

@@ -506,0 +533,0 @@ formatter.input('7').should.equal('77');

@@ -263,3 +263,3 @@ import metadata from '../metadata.min.json';

});
it('should format non-geographical numbering plan phone numbers', function () {
it('should format non-geographic numbering plan phone numbers', function () {
// https://github.com/catamphetamine/libphonenumber-js/issues/323

@@ -266,0 +266,0 @@ formatNumber('+870773111632', 'INTERNATIONAL').should.equal('+870 773 111 632');

@@ -76,3 +76,3 @@ // This function is copy-pasted from

} else {
// For non-geographical countries, Mexican and Chilean fixed line and
// For non-geographic countries, Mexican and Chilean fixed line and
// mobile numbers, we output international format for numbers that can be

@@ -79,0 +79,0 @@ // dialed internationally, as that always works.

@@ -98,3 +98,3 @@ import Metadata from './metadata';

// The rare case has been encountered where no fixedLine data is available
// (true for some non-geographical entities), so we just check mobile.
// (true for some non-geographic entities), so we just check mobile.
return checkNumberLengthForType(nationalNumber, 'MOBILE', metadata);

@@ -101,0 +101,0 @@ }

@@ -40,4 +40,11 @@ import Metadata from './metadata';

} else {
// There was a bug between `1.7.35` and `1.7.37` where "possible_lengths"
// were missing for "non-geographical" numbering plans.
// Just assume the number is possible in such cases:
// it's unlikely that anyone generated their custom metadata
// in that short period of time (one day).
// This code can be removed in some future major version update.
if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
// "Non-geographical entities" don't have `possibleLengths`.
// "Non-geographic entities" did't have `possibleLengths`
// due to a bug in metadata generation process.
return true;

@@ -44,0 +51,0 @@ } else {

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

var V3 = '1.2.0'; // Moved `001` country code to "nonGeographical" section of metadata.
var V3 = '1.2.0'; // Moved `001` country code to "nonGeographic" section of metadata.

@@ -47,6 +47,8 @@ var V4 = '1.7.35';

}, {
key: "nonGeographical",
value: function nonGeographical() {
if (this.v1 || this.v2 || this.v3) return;
return this.metadata.nonGeographical;
key: "nonGeographic",
value: function nonGeographic() {
if (this.v1 || this.v2 || this.v3) return; // `nonGeographical` was a typo.
// It's present in metadata generated from `1.7.35` to `1.7.37`.
return this.metadata.nonGeographic || this.metadata.nonGeographical;
}

@@ -65,4 +67,4 @@ }, {

if (this.nonGeographical()) {
if (this.nonGeographical()[callingCode]) {
if (this.nonGeographic()) {
if (this.nonGeographic()[callingCode]) {
return true;

@@ -82,6 +84,6 @@ }

value: function isNonGeographicCallingCode(callingCode) {
if (this.nonGeographical()) {
if (this.nonGeographical()[callingCode]) {
return true;
}
if (this.nonGeographic()) {
return this.nonGeographic()[callingCode] ? true : false;
} else {
return this.getCountryCodesForCallingCode(callingCode) ? false : true;
}

@@ -156,4 +158,4 @@ } // Deprecated.

if (this.nonGeographical()) {
var metadata = this.nonGeographical()[callingCode];
if (this.nonGeographic()) {
var metadata = this.nonGeographic()[callingCode];

@@ -160,0 +162,0 @@ if (metadata) {

@@ -24,3 +24,4 @@ // This is a port of Google Android `libphonenumber`'s

var AFTER_PHONE_NUMBER_END_PATTERN = new RegExp('[^' + VALID_DIGITS + ']+$'); // `options`:
var AFTER_PHONE_NUMBER_END_PATTERN = new RegExp('[^' + VALID_DIGITS + ']+$');
var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false; // `options`:
// {

@@ -146,3 +147,3 @@ // country:

var valid = country && matchesEntirely(nationalNumber, metadata.nationalNumberPattern()) ? true : false;
var valid = (options.extended ? metadata.hasSelectedNumberingPlan() : country) ? matchesEntirely(nationalNumber, metadata.nationalNumberPattern()) : false;

@@ -158,3 +159,3 @@ if (!options.extended) {

valid: valid,
possible: valid ? true : options.extended === true && metadata.possibleLengths() && isPossibleNumber(nationalNumber, countryCallingCode !== undefined, metadata),
possible: valid ? true : options.extended === true && metadata.possibleLengths() && isPossibleNumber(nationalNumber, countryCallingCode !== undefined, metadata) ? true : false,
phone: nationalNumber,

@@ -285,4 +286,7 @@ ext: ext

export function findCountryCode(callingCode, nationalPhoneNumber, metadata) {
if (metadata.isNonGeographicCallingCode(callingCode)) {
return '001';
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (metadata.isNonGeographicCallingCode(callingCode)) {
return '001';
}
} // Is always non-empty, because `callingCode` is always valid

@@ -408,3 +412,14 @@

metadata.selectNumberingPlan(defaultCountry, defaultCallingCode);
country = defaultCountry || (metadata.isNonGeographicCallingCode(defaultCallingCode) ? '001' : undefined);
if (defaultCountry) {
country = defaultCountry;
} else {
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (metadata.isNonGeographicCallingCode(defaultCallingCode)) {
country = '001';
}
}
}
countryCallingCode = defaultCallingCode || getCountryCallingCode(defaultCountry, metadata.metadata);

@@ -437,4 +452,8 @@ } else return {};

country = exactCountry;
/* istanbul ignore if */
if (country !== '001') {
if (exactCountry === '001') {// Can't happen with `USE_NON_GEOGRAPHIC_COUNTRY_CODE` being `false`.
// If `USE_NON_GEOGRAPHIC_COUNTRY_CODE` is set to `true` for some reason,
// then remove the "istanbul ignore if".
} else {
metadata.country(country);

@@ -441,0 +460,0 @@ }

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

var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
describe('parse', function () {

@@ -419,21 +420,21 @@ it('should not parse invalid phone numbers', function () {

});
it('should parse non-geographical numbering plan phone numbers', function () {
parseNumber('+870773111632').should.deep.equal({
it('should parse non-geographic numbering plan phone numbers', function () {
parseNumber('+870773111632').should.deep.equal(USE_NON_GEOGRAPHIC_COUNTRY_CODE ? {
country: '001',
phone: '773111632'
});
} : {});
});
it('should parse non-geographical numbering plan phone numbers (default country code)', function () {
it('should parse non-geographic numbering plan phone numbers (default country code)', function () {
parseNumber('773111632', {
defaultCallingCode: '870'
}).should.deep.equal({
}).should.deep.equal(USE_NON_GEOGRAPHIC_COUNTRY_CODE ? {
country: '001',
phone: '773111632'
});
} : {});
});
it('should parse non-geographical numbering plan phone numbers (extended)', function () {
it('should parse non-geographic numbering plan phone numbers (extended)', function () {
parseNumber('+870773111632', {
extended: true
}).should.deep.equal({
country: '001',
country: USE_NON_GEOGRAPHIC_COUNTRY_CODE ? '001' : undefined,
countryCallingCode: '870',

@@ -447,3 +448,3 @@ phone: '773111632',

});
it('should parse non-geographical numbering plan phone numbers (default country code) (extended)', function () {
it('should parse non-geographic numbering plan phone numbers (default country code) (extended)', function () {
parseNumber('773111632', {

@@ -453,3 +454,3 @@ defaultCallingCode: '870',

}).should.deep.equal({
country: '001',
country: USE_NON_GEOGRAPHIC_COUNTRY_CODE ? '001' : undefined,
countryCallingCode: '870',

@@ -470,3 +471,3 @@ phone: '773111632',

});
it('shouldn\'t set `country` when there\'s no `defaultCountry` and `defaultCallingCode` is not of a "non-geographical entity"', function () {
it('shouldn\'t set `country` when there\'s no `defaultCountry` and `defaultCallingCode` is not of a "non-geographic entity"', function () {
parseNumber('88005553535', {

@@ -473,0 +474,0 @@ defaultCallingCode: '7'

@@ -125,7 +125,3 @@ import _parsePhoneNumber from './parsePhoneNumber';

});
it('shouldn\'t throw when "possibleLengths" are missing on "non-geographical entities" metadata', function () {
var phoneNumber = parsePhoneNumber('+870773111632');
phoneNumber.isPossible().should.equal(true);
});
});
//# sourceMappingURL=parsePhoneNumber.test.js.map

@@ -13,2 +13,3 @@ import _parsePhoneNumberFromString from './parsePhoneNumberFromString';

var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
describe('parsePhoneNumberFromString', function () {

@@ -26,9 +27,15 @@ it('should parse phone numbers from string', function () {

});
it('should parse non-geographical numbering plan phone numbers (extended)', function () {
it('should parse non-geographic numbering plan phone numbers (extended)', function () {
var phoneNumber = parsePhoneNumberFromString('+870773111632');
phoneNumber.number.should.equal('+870773111632');
phoneNumber.country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
phoneNumber.country.should.equal('001');
} else {
expect(phoneNumber.country).to.be.undefined;
}
phoneNumber.countryCallingCode.should.equal('870');
});
it('should parse non-geographical numbering plan phone numbers (default country code) (extended)', function () {
it('should parse non-geographic numbering plan phone numbers (default country code) (extended)', function () {
var phoneNumber = parsePhoneNumberFromString('773111632', {

@@ -38,6 +45,18 @@ defaultCallingCode: '870'

phoneNumber.number.should.equal('+870773111632');
phoneNumber.country.should.equal('001');
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
phoneNumber.country.should.equal('001');
} else {
expect(phoneNumber.country).to.be.undefined;
}
phoneNumber.countryCallingCode.should.equal('870');
});
it('should determine the possibility of non-geographic phone numbers', function () {
var phoneNumber = parsePhoneNumberFromString('+870773111632');
phoneNumber.isPossible().should.equal(true);
var phoneNumber2 = parsePhoneNumberFromString('+8707731116321');
phoneNumber2.isPossible().should.equal(false);
});
});
//# sourceMappingURL=parsePhoneNumberFromString.test.js.map

@@ -17,2 +17,3 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

import formatNumber from './format_';
var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;

@@ -26,3 +27,3 @@ var PhoneNumber =

if (!countryCallingCode) {
throw new TypeError('`countryCallingCode` not passed');
throw new TypeError('`country` or `countryCallingCode` not passed');
}

@@ -44,4 +45,9 @@

countryCallingCode = _metadata.countryCallingCode();
} else if (_metadata.isNonGeographicCallingCode(countryCallingCode)) {
this.country = '001';
} else {
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (_metadata.isNonGeographicCallingCode(countryCallingCode)) {
this.country = '001';
}
}
}

@@ -70,2 +76,8 @@

}, {
key: "isNonGeographic",
value: function isNonGeographic() {
var metadata = new Metadata(this.metadata);
return metadata.isNonGeographicCallingCode(this.countryCallingCode);
}
}, {
key: "isEqual",

@@ -72,0 +84,0 @@ value: function isEqual(phoneNumber) {

@@ -32,3 +32,7 @@ import metadata from '../metadata.min';

});
it('should tell if a number is non-geographic', function () {
new PhoneNumber('7', '8005553535', metadata).isNonGeographic().should.equal(false);
new PhoneNumber('870', '773111632', metadata).isNonGeographic().should.equal(true);
});
});
//# sourceMappingURL=PhoneNumber.test.js.map

@@ -207,3 +207,3 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

if (this.options.v2) {
var phoneNumber = new PhoneNumber(match.country === '001' ? match.countryCallingCode : match.country, match.phone, this.metadata);
var phoneNumber = new PhoneNumber(match.country || match.countryCallingCode, match.phone, this.metadata);

@@ -309,7 +309,8 @@ if (match.ext) {

endsAt: offset + candidate.length,
country: number.country,
phone: number.phone
};
if (result.country === '001') {
if (number.country && number.country !== '001') {
result.country = number.country;
} else {
result.countryCallingCode = number.countryCallingCode;

@@ -316,0 +317,0 @@ }

@@ -9,7 +9,7 @@ export default function compress(input) {

var nonGeographical = {};
var nonGeographic = {};
for (var _i2 = 0, _Object$keys2 = Object.keys(input.nonGeographical); _i2 < _Object$keys2.length; _i2++) {
for (var _i2 = 0, _Object$keys2 = Object.keys(input.nonGeographic); _i2 < _Object$keys2.length; _i2++) {
var callingCode = _Object$keys2[_i2];
nonGeographical[callingCode] = compressNumberingPlan(input.nonGeographical[callingCode]);
nonGeographic[callingCode] = compressNumberingPlan(input.nonGeographic[callingCode]);
}

@@ -21,3 +21,3 @@

countries: countries,
nonGeographical: nonGeographical
nonGeographic: nonGeographic
};

@@ -24,0 +24,0 @@ }

@@ -175,3 +175,3 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

var countries = {};
var nonGeographical = {};
var nonGeographic = {};

@@ -388,3 +388,5 @@ var _loop2 = function _loop2() {

if (country_code === '001') {
nonGeographical[country.phone_code] = country;
nonGeographic[country.phone_code] = country; // Populate numbering plan possible lengths.
populateNumberingPlanPossibleLengths(country);
} else {

@@ -499,5 +501,5 @@ // Add this country's metadata

visited_countries[_country_code] = true; // Populate possible lengths
visited_countries[_country_code] = true; // Populate numbering plan possible lengths.
populate_possible_lengths(countries[_country_code]);
populateNumberingPlanPossibleLengths(countries[_country_code]);

@@ -581,3 +583,3 @@ if (countries[_country_code].possible_lengths.length === 0) {

country_calling_codes: country_calling_code_to_countries,
nonGeographical: nonGeographical
nonGeographic: nonGeographic
};

@@ -721,4 +723,10 @@ });

};
/**
* Sets `metadata.possible_lengths` to a combination of `possible_length`s
* of all types present in the numbering plan metadata.
* @param {object} metadata
*/
function populate_possible_lengths(metadata) {
function populateNumberingPlanPossibleLengths(metadata) {
var types = metadata.types;

@@ -725,0 +733,0 @@ var possible_lengths = new Set();

@@ -1,3 +0,6 @@

// Checks whether the entire input sequence can be matched
// against the regular expression.
/**
* Checks whether the entire input sequence can be matched
* against the regular expression.
* @return {boolean}
*/
export function matchesEntirely(text, regular_expression) {

@@ -4,0 +7,0 @@ // If assigning the `''` default value is moved to the arguments above,

@@ -11,3 +11,3 @@ # Metadata

Contains metadata for each country.
`countries` — Contains metadata for each country.

@@ -72,6 +72,17 @@ ### `phone_code`

#### `pattern`
A regular expression for a national (significant) number matching the type.
#### `possible_lengths`
Possible lengths of a national (significant) number matching the type. Is always present.
### `examples`
Phone number examples for each one of the phone number `types`.
Phone number examples for each of the phone number `types`.
### `possible_lengths`
Possible lengths of a national (significant) number for this numbering plan. This property is a combination of `possible_lengths` of all `types`. Is always present.
### `formats`

@@ -109,2 +120,8 @@

"Leading digits" patterns are used in `AsYouType` formatter to choose a format suitable for the phone number being input: if a phone number's "leading digits" match those of a format, then that format is used to format the phone number being input. Each subsequent leading digits pattern in `leading_digits_patterns` array requires one more leading digit.
"Leading digits" patterns are used in `AsYouType` formatter to choose a format suitable for the phone number being input: if a phone number's "leading digits" match those of a format, then that format is used to format the phone number being input. Each subsequent leading digits pattern in `leading_digits_patterns` array requires one more leading digit.
## Non-geographic
There're [calling codes](https://github.com/catamphetamine/libphonenumber-js#non-geographic) that don't correspond to any country. For example, "Global Mobile Satellite System" (`+881`). Such phone numbering systems are called "non-geographic entities" in Google's code. These "non-geographic entitites" reside in their own `nonGeographic` property, analogous to the `countries` property. `nonGeographic` is an object with keys being calling codes of the corresponding "non-geographic entities", and values being same as the values of the `countries` property.
"Non-geographic" numbering plans don't have [`possible_lengths`](#possible-lengths).
{
"name": "libphonenumber-js",
"version": "1.7.37",
"version": "1.7.38",
"description": "A simpler (and smaller) rewrite of Google Android's popular libphonenumber library",

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

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

const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
export default class AsYouType {

@@ -133,4 +135,7 @@ // Not setting `options` to a constructor argument

if (defaultCallingCode) {
if (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {
this.defaultCountry = '001'
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {
this.defaultCountry = '001'
}
}

@@ -935,5 +940,12 @@ this.defaultCallingCode = defaultCallingCode

}
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
const phoneNumber = new PhoneNumber(
this.country === '001' ? callingCode : this.country || callingCode,
countryCode || callingCode,
this.nationalNumberDigits,

@@ -940,0 +952,0 @@ this.metadata.metadata

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

const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
describe('as you type', () => {

@@ -568,3 +570,3 @@ it('should use "national_prefix_formatting_rule"', () => {

it('should format non-geographical numbering plan phone numbers', () => {
it('should format non-geographic numbering plan phone numbers', () => {
const formatter = new AsYouType()

@@ -576,3 +578,7 @@ formatter.input('+').should.equal('+')

formatter.input('0').should.equal('+870')
formatter.country.should.equal('001')
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.country.should.equal('001')
} else {
expect(formatter.country).to.be.undefined
}
formatter.input('7').should.equal('+870 7')

@@ -587,9 +593,17 @@ formatter.input('7').should.equal('+870 77')

formatter.input('2').should.equal('+870 773 111 632')
formatter.getNumber().country.should.equal('001')
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.getNumber().country.should.equal('001')
} else {
expect(formatter.country).to.be.undefined
}
formatter.getNumber().countryCallingCode.should.equal('870')
})
it('should format non-geographical numbering plan phone numbers (default country calling code)', () => {
it('should format non-geographic numbering plan phone numbers (default country calling code)', () => {
const formatter = new AsYouType({ defaultCallingCode: '870' })
formatter.country.should.equal('001')
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.getNumber().country.should.equal('001')
} else {
expect(formatter.country).to.be.undefined
}
formatter.input('7').should.equal('7')

@@ -604,8 +618,14 @@ formatter.input('7').should.equal('77')

formatter.input('2').should.equal('773 111 632')
formatter.getNumber().country.should.equal('001')
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
formatter.getNumber().country.should.equal('001')
} else {
expect(formatter.country).to.be.undefined
}
formatter.getNumber().countryCallingCode.should.equal('870')
})
it('should not format non-geographical numbering plan phone numbers (default country 001)', () => {
it('should not format non-geographic numbering plan phone numbers (default country 001)', () => {
const formatter = new AsYouType('001')
expect(formatter.defaultCountry).to.be.undefined
expect(formatter.defaultCallingCode).to.be.undefined
formatter.input('7').should.equal('7')

@@ -612,0 +632,0 @@ formatter.input('7').should.equal('77')

@@ -226,3 +226,3 @@ import metadata from '../metadata.min.json'

it('should format non-geographical numbering plan phone numbers', () => {
it('should format non-geographic numbering plan phone numbers', () => {
// https://github.com/catamphetamine/libphonenumber-js/issues/323

@@ -229,0 +229,0 @@ formatNumber('+870773111632', 'INTERNATIONAL').should.equal('+870 773 111 632')

@@ -108,3 +108,3 @@ // This function is copy-pasted from

{
// For non-geographical countries, Mexican and Chilean fixed line and
// For non-geographic countries, Mexican and Chilean fixed line and
// mobile numbers, we output international format for numbers that can be

@@ -111,0 +111,0 @@ // dialed internationally, as that always works.

@@ -131,3 +131,3 @@ import Metadata from './metadata'

// The rare case has been encountered where no fixedLine data is available
// (true for some non-geographical entities), so we just check mobile.
// (true for some non-geographic entities), so we just check mobile.
return checkNumberLengthForType(nationalNumber, 'MOBILE', metadata)

@@ -134,0 +134,0 @@ }

@@ -38,4 +38,11 @@ import Metadata from './metadata'

} else {
// There was a bug between `1.7.35` and `1.7.37` where "possible_lengths"
// were missing for "non-geographical" numbering plans.
// Just assume the number is possible in such cases:
// it's unlikely that anyone generated their custom metadata
// in that short period of time (one day).
// This code can be removed in some future major version update.
if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
// "Non-geographical entities" don't have `possibleLengths`.
// "Non-geographic entities" did't have `possibleLengths`
// due to a bug in metadata generation process.
return true

@@ -42,0 +49,0 @@ } else {

@@ -10,3 +10,3 @@ import compare from './tools/semver-compare'

// Moved `001` country code to "nonGeographical" section of metadata.
// Moved `001` country code to "nonGeographic" section of metadata.
const V4 = '1.7.35'

@@ -34,5 +34,7 @@

nonGeographical() {
nonGeographic() {
if (this.v1 || this.v2 || this.v3) return
return this.metadata.nonGeographical
// `nonGeographical` was a typo.
// It's present in metadata generated from `1.7.35` to `1.7.37`.
return this.metadata.nonGeographic || this.metadata.nonGeographical
}

@@ -48,4 +50,4 @@

}
if (this.nonGeographical()) {
if (this.nonGeographical()[callingCode]) {
if (this.nonGeographic()) {
if (this.nonGeographic()[callingCode]) {
return true

@@ -63,6 +65,6 @@ }

isNonGeographicCallingCode(callingCode) {
if (this.nonGeographical()) {
if (this.nonGeographical()[callingCode]) {
return true
}
if (this.nonGeographic()) {
return this.nonGeographic()[callingCode] ? true : false
} else {
return this.getCountryCodesForCallingCode(callingCode) ? false : true
}

@@ -124,4 +126,4 @@ }

}
if (this.nonGeographical()) {
const metadata = this.nonGeographical()[callingCode]
if (this.nonGeographic()) {
const metadata = this.nonGeographic()[callingCode]
if (metadata) {

@@ -128,0 +130,0 @@ return metadata

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

const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
// `options`:

@@ -159,3 +161,5 @@ // {

// even for those ones which are part of the "NANPA" group.
const valid = country && matchesEntirely(nationalNumber, metadata.nationalNumberPattern()) ? true : false
const valid = (options.extended ? metadata.hasSelectedNumberingPlan() : country) ?
matchesEntirely(nationalNumber, metadata.nationalNumberPattern()) :
false

@@ -171,3 +175,7 @@ if (!options.extended) {

valid,
possible: valid ? true : (options.extended === true) && metadata.possibleLengths() && isPossibleNumber(nationalNumber, countryCallingCode !== undefined, metadata),
possible: valid ? true : (
options.extended === true &&
metadata.possibleLengths() &&
isPossibleNumber(nationalNumber, countryCallingCode !== undefined, metadata) ? true : false
),
phone: nationalNumber,

@@ -298,4 +306,7 @@ ext

export function findCountryCode(callingCode, nationalPhoneNumber, metadata) {
if (metadata.isNonGeographicCallingCode(callingCode)) {
return '001'
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (metadata.isNonGeographicCallingCode(callingCode)) {
return '001'
}
}

@@ -401,3 +412,12 @@ // Is always non-empty, because `callingCode` is always valid

metadata.selectNumberingPlan(defaultCountry, defaultCallingCode)
country = defaultCountry || (metadata.isNonGeographicCallingCode(defaultCallingCode) ? '001' : undefined)
if (defaultCountry) {
country = defaultCountry
} else {
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (metadata.isNonGeographicCallingCode(defaultCallingCode)) {
country = '001'
}
}
}
countryCallingCode = defaultCallingCode || getCountryCallingCode(defaultCountry, metadata.metadata)

@@ -426,3 +446,8 @@ }

country = exactCountry
if (country !== '001') {
/* istanbul ignore if */
if (exactCountry === '001') {
// Can't happen with `USE_NON_GEOGRAPHIC_COUNTRY_CODE` being `false`.
// If `USE_NON_GEOGRAPHIC_COUNTRY_CODE` is set to `true` for some reason,
// then remove the "istanbul ignore if".
} else {
metadata.country(country)

@@ -429,0 +454,0 @@ }

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

const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
describe('parse', () => {

@@ -379,19 +381,27 @@ it('should not parse invalid phone numbers', () => {

it('should parse non-geographical numbering plan phone numbers', () => {
parseNumber('+870773111632').should.deep.equal({
country: '001',
phone: '773111632'
})
it('should parse non-geographic numbering plan phone numbers', () => {
parseNumber('+870773111632').should.deep.equal(
USE_NON_GEOGRAPHIC_COUNTRY_CODE ?
{
country: '001',
phone: '773111632'
} :
{}
)
})
it('should parse non-geographical numbering plan phone numbers (default country code)', () => {
parseNumber('773111632', { defaultCallingCode: '870' }).should.deep.equal({
country: '001',
phone: '773111632'
})
it('should parse non-geographic numbering plan phone numbers (default country code)', () => {
parseNumber('773111632', { defaultCallingCode: '870' }).should.deep.equal(
USE_NON_GEOGRAPHIC_COUNTRY_CODE ?
{
country: '001',
phone: '773111632'
} :
{}
)
})
it('should parse non-geographical numbering plan phone numbers (extended)', () => {
it('should parse non-geographic numbering plan phone numbers (extended)', () => {
parseNumber('+870773111632', { extended: true }).should.deep.equal({
country: '001',
country: USE_NON_GEOGRAPHIC_COUNTRY_CODE ? '001' : undefined,
countryCallingCode: '870',

@@ -406,5 +416,5 @@ phone: '773111632',

it('should parse non-geographical numbering plan phone numbers (default country code) (extended)', () => {
it('should parse non-geographic numbering plan phone numbers (default country code) (extended)', () => {
parseNumber('773111632', { defaultCallingCode: '870', extended: true }).should.deep.equal({
country: '001',
country: USE_NON_GEOGRAPHIC_COUNTRY_CODE ? '001' : undefined,
countryCallingCode: '870',

@@ -424,3 +434,3 @@ phone: '773111632',

it('shouldn\'t set `country` when there\'s no `defaultCountry` and `defaultCallingCode` is not of a "non-geographical entity"', () => {
it('shouldn\'t set `country` when there\'s no `defaultCountry` and `defaultCallingCode` is not of a "non-geographic entity"', () => {
parseNumber('88005553535', { defaultCallingCode: '7' }).should.deep.equal({

@@ -427,0 +437,0 @@ country: 'RU',

@@ -110,7 +110,2 @@ import _parsePhoneNumber from './parsePhoneNumber'

})
it('shouldn\'t throw when "possibleLengths" are missing on "non-geographical entities" metadata', () => {
const phoneNumber = parsePhoneNumber('+870773111632')
phoneNumber.isPossible().should.equal(true)
})
})

@@ -9,2 +9,4 @@ import _parsePhoneNumberFromString from './parsePhoneNumberFromString'

const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
describe('parsePhoneNumberFromString', () => {

@@ -26,15 +28,30 @@ it('should parse phone numbers from string', () => {

it('should parse non-geographical numbering plan phone numbers (extended)', () => {
it('should parse non-geographic numbering plan phone numbers (extended)', () => {
const phoneNumber = parsePhoneNumberFromString('+870773111632')
phoneNumber.number.should.equal('+870773111632')
phoneNumber.country.should.equal('001')
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
phoneNumber.country.should.equal('001')
} else {
expect(phoneNumber.country).to.be.undefined
}
phoneNumber.countryCallingCode.should.equal('870')
})
it('should parse non-geographical numbering plan phone numbers (default country code) (extended)', () => {
it('should parse non-geographic numbering plan phone numbers (default country code) (extended)', () => {
const phoneNumber = parsePhoneNumberFromString('773111632', { defaultCallingCode: '870' })
phoneNumber.number.should.equal('+870773111632')
phoneNumber.country.should.equal('001')
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
phoneNumber.country.should.equal('001')
} else {
expect(phoneNumber.country).to.be.undefined
}
phoneNumber.countryCallingCode.should.equal('870')
})
it('should determine the possibility of non-geographic phone numbers', () => {
const phoneNumber = parsePhoneNumberFromString('+870773111632')
phoneNumber.isPossible().should.equal(true)
const phoneNumber2 = parsePhoneNumberFromString('+8707731116321')
phoneNumber2.isPossible().should.equal(false)
})
})

@@ -8,6 +8,8 @@ import Metadata from './metadata'

const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
export default class PhoneNumber {
constructor(countryCallingCode, nationalNumber, metadata) {
if (!countryCallingCode) {
throw new TypeError('`countryCallingCode` not passed')
throw new TypeError('`country` or `countryCallingCode` not passed')
}

@@ -24,4 +26,9 @@ if (!nationalNumber) {

countryCallingCode = _metadata.countryCallingCode()
} else if (_metadata.isNonGeographicCallingCode(countryCallingCode)) {
this.country = '001'
} else {
/* istanbul ignore if */
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
if (_metadata.isNonGeographicCallingCode(countryCallingCode)) {
this.country = '001'
}
}
}

@@ -42,2 +49,7 @@ this.countryCallingCode = countryCallingCode

isNonGeographic() {
const metadata = new Metadata(this.metadata)
return metadata.isNonGeographicCallingCode(this.countryCallingCode)
}
isEqual(phoneNumber) {

@@ -44,0 +56,0 @@ return this.number === phoneNumber.number && this.ext === phoneNumber.ext

@@ -31,2 +31,7 @@ import metadata from '../metadata.min'

})
it('should tell if a number is non-geographic', () => {
new PhoneNumber('7', '8005553535', metadata).isNonGeographic().should.equal(false)
new PhoneNumber('870', '773111632', metadata).isNonGeographic().should.equal(true)
})
})

@@ -237,3 +237,3 @@ /**

const phoneNumber = new PhoneNumber(
match.country === '001' ? match.countryCallingCode : match.country,
match.country || match.countryCallingCode,
match.phone,

@@ -348,9 +348,10 @@ this.metadata

const result = {
startsAt : offset,
endsAt : offset + candidate.length,
country : number.country,
phone : number.phone
startsAt: offset,
endsAt: offset + candidate.length,
phone: number.phone
}
if (result.country === '001') {
if (number.country && number.country !== '001') {
result.country = number.country
} else {
result.countryCallingCode = number.countryCallingCode

@@ -357,0 +358,0 @@ }

@@ -6,5 +6,5 @@ export default function compress(input) {

}
const nonGeographical = {}
for (const callingCode of Object.keys(input.nonGeographical)) {
nonGeographical[callingCode] = compressNumberingPlan(input.nonGeographical[callingCode])
const nonGeographic = {}
for (const callingCode of Object.keys(input.nonGeographic)) {
nonGeographic[callingCode] = compressNumberingPlan(input.nonGeographic[callingCode])
}

@@ -15,3 +15,3 @@ return {

countries,
nonGeographical
nonGeographic
}

@@ -18,0 +18,0 @@ }

@@ -175,3 +175,3 @@ import { parseString } from 'xml2js'

const countries = {}
const nonGeographical = {}
const nonGeographic = {}

@@ -386,3 +386,5 @@ for (const territory of xml.phoneNumberMetadata.territories[0].territory)

if (country_code === '001') {
nonGeographical[country.phone_code] = country
nonGeographic[country.phone_code] = country
// Populate numbering plan possible lengths.
populateNumberingPlanPossibleLengths(country)
} else {

@@ -477,4 +479,4 @@ // Add this country's metadata

// Populate possible lengths
populate_possible_lengths(countries[country_code])
// Populate numbering plan possible lengths.
populateNumberingPlanPossibleLengths(countries[country_code])

@@ -556,3 +558,3 @@ if (countries[country_code].possible_lengths.length === 0) {

country_calling_codes: country_calling_code_to_countries,
nonGeographical
nonGeographic
}

@@ -691,3 +693,8 @@ })

function populate_possible_lengths(metadata)
/**
* Sets `metadata.possible_lengths` to a combination of `possible_length`s
* of all types present in the numbering plan metadata.
* @param {object} metadata
*/
function populateNumberingPlanPossibleLengths(metadata)
{

@@ -694,0 +701,0 @@ const types = metadata.types

@@ -1,3 +0,6 @@

// Checks whether the entire input sequence can be matched
// against the regular expression.
/**
* Checks whether the entire input sequence can be matched
* against the regular expression.
* @return {boolean}
*/
export function matchesEntirely(text, regular_expression) {

@@ -4,0 +7,0 @@ // If assigning the `''` default value is moved to the arguments above,

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