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 0.4.3 to 0.4.4

86

build/get number type.js

@@ -47,42 +47,14 @@ 'use strict';

// The following is copy-pasted from the original function:
// https://github.com/googlei18n/libphonenumber/blob/3ea547d4fbaa2d0b67588904dfa5d3f2557c27ff/javascript/i18n/phonenumbers/phonenumberutil.js#L2835
// Is this national number even valid for this country
if (!is_of_type(national_number, (0, _metadata.get_national_number_pattern)(country_metadata))) {
return;
return; // 'UNKNOWN'
}
if (is_of_type(national_number, (0, _metadata.get_type_mobile)(country_metadata))) {
// Because duplicate regular expressions are removed
// to reduce metadata size, if there's no "fixed line" pattern
// then it means it was removed due to being a duplicate of some other pattern.
//
// Also, many times fixed line phone number regular expressions
// are the same as mobile phone number regular expressions,
// so in these cases there's no differentiation between them.
//
// (no such country in the metadata, therefore no unit test for this `if`)
/* istanbul ignore if */
if (!(0, _metadata.get_type_fixed_line)(country_metadata) || (0, _metadata.get_type_fixed_line)(country_metadata) === (0, _metadata.get_type_mobile)(country_metadata)) {
return 'FIXED_LINE_OR_MOBILE';
}
return 'MOBILE';
if (is_of_type(national_number, (0, _metadata.get_type_premium_rate)(country_metadata))) {
return 'PREMIUM_RATE';
}
// Is it fixed line number
if (is_of_type(national_number, (0, _metadata.get_type_fixed_line)(country_metadata))) {
// Because duplicate regular expressions are removed
// to reduce metadata size, if there's no "mobile" pattern
// then it means it was removed due to being a duplicate of some other pattern.
//
// Also, many times fixed line phone number regular expressions
// are the same as mobile phone number regular expressions,
// so in these cases there's no differentiation between them.
//
if (!(0, _metadata.get_type_mobile)(country_metadata) || (0, _metadata.get_type_mobile)(country_metadata) === (0, _metadata.get_type_fixed_line)(country_metadata)) {
return 'FIXED_LINE_OR_MOBILE';
}
return 'FIXED_LINE';
}
if (is_of_type(national_number, (0, _metadata.get_type_toll_free)(country_metadata))) {

@@ -92,6 +64,12 @@ return 'TOLL_FREE';

if (is_of_type(national_number, (0, _metadata.get_type_premium_rate)(country_metadata))) {
return 'PREMIUM_RATE';
/* istanbul ignore if */
if (is_of_type(national_number, (0, _metadata.get_type_shared_cost)(country_metadata))) {
return 'SHARED_COST';
}
/* istanbul ignore if */
if (is_of_type(national_number, (0, _metadata.get_type_voip)(country_metadata))) {
return 'VOIP';
}
if (is_of_type(national_number, (0, _metadata.get_type_personal_number)(country_metadata))) {

@@ -102,4 +80,4 @@ return 'PERSONAL_NUMBER';

/* istanbul ignore if */
if (is_of_type(national_number, (0, _metadata.get_type_voice_mail)(country_metadata))) {
return 'VOICEMAIL';
if (is_of_type(national_number, (0, _metadata.get_type_pager)(country_metadata))) {
return 'PAGER';
}

@@ -113,15 +91,31 @@

/* istanbul ignore if */
if (is_of_type(national_number, (0, _metadata.get_type_pager)(country_metadata))) {
return 'PAGER';
if (is_of_type(national_number, (0, _metadata.get_type_voice_mail)(country_metadata))) {
return 'VOICEMAIL';
}
/* istanbul ignore if */
if (is_of_type(national_number, (0, _metadata.get_type_voip)(country_metadata))) {
return 'VOIP';
// Is it fixed line number
if (is_of_type(national_number, (0, _metadata.get_type_fixed_line)(country_metadata))) {
// Because duplicate regular expressions are removed
// to reduce metadata size, if there's no "mobile" pattern
// then it means it was removed due to being a duplicate of some other pattern.
//
if (!(0, _metadata.get_type_mobile)(country_metadata)) {
return 'FIXED_LINE_OR_MOBILE';
}
// Check if the number happens to qualify as both fixed line and mobile.
// (no such country in the minimal metadata set)
/* istanbul ignore if */
if (is_of_type(national_number, (0, _metadata.get_type_mobile)(country_metadata))) {
return 'FIXED_LINE_OR_MOBILE';
}
return 'FIXED_LINE';
}
/* istanbul ignore if */
if (is_of_type(national_number, (0, _metadata.get_type_shared_cost)(country_metadata))) {
return 'SHARED_COST';
if (is_of_type(national_number, (0, _metadata.get_type_mobile)(country_metadata))) {
return 'MOBILE';
}
// return 'UNKNOWN'
}

@@ -128,0 +122,0 @@

@@ -386,3 +386,2 @@ 'use strict';

// If this type has just been removed due to redundancy
if (!types[type]) {

@@ -393,4 +392,4 @@ return 'continue';

// Remove redundant types
// (having the same regular expressions as this one)
(0, _keys2.default)(types).filter(function (key) {
// (other types having the same regular expressions as this one)
phone_number_types.filter(function (key) {
return key !== type && types[key] === types[type];

@@ -402,3 +401,3 @@ }).forEach(function (key) {

for (var _iterator6 = (0, _getIterator3.default)((0, _keys2.default)(types)), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
for (var _iterator6 = (0, _getIterator3.default)(phone_number_types), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
var _ret3 = _loop3();

@@ -473,15 +472,4 @@

// Replaces $NP with national prefix and $FG with the first group ($1)
function national_prefix_formatting_rule(rule, national_prefix) {
if (!rule) {
return;
}
var phone_number_types = ['premium_rate', 'toll_free', 'shared_cost', 'voip', 'personal_number', 'pager', 'uan', 'voice_mail', 'fixed_line', 'mobile'];
// Replace $NP with national prefix and $FG with the first group ($1)
return rule.replace('$NP', national_prefix).replace('$FG', '$1');
}
// Gets phone type pattern
// Excessive fields from "PhoneNumberMetadata.xml"

@@ -549,2 +537,15 @@ // aren't included to reduce code complexity and size:

//
// Replaces $NP with national prefix and $FG with the first group ($1)
function national_prefix_formatting_rule(rule, national_prefix) {
if (!rule) {
return;
}
// Replace $NP with national prefix and $FG with the first group ($1)
return rule.replace('$NP', national_prefix).replace('$FG', '$1');
}
// Gets phone type pattern
function phone_type_pattern(territory, type) {

@@ -551,0 +552,0 @@ return territory[type] ? territory[type][0].nationalNumberPattern[0].replace(/\s/g, '') : undefined;

@@ -34,42 +34,14 @@ import parse, { is_viable_phone_number } from './parse';

// The following is copy-pasted from the original function:
// https://github.com/googlei18n/libphonenumber/blob/3ea547d4fbaa2d0b67588904dfa5d3f2557c27ff/javascript/i18n/phonenumbers/phonenumberutil.js#L2835
// Is this national number even valid for this country
if (!is_of_type(national_number, get_national_number_pattern(country_metadata))) {
return;
return; // 'UNKNOWN'
}
if (is_of_type(national_number, get_type_mobile(country_metadata))) {
// Because duplicate regular expressions are removed
// to reduce metadata size, if there's no "fixed line" pattern
// then it means it was removed due to being a duplicate of some other pattern.
//
// Also, many times fixed line phone number regular expressions
// are the same as mobile phone number regular expressions,
// so in these cases there's no differentiation between them.
//
// (no such country in the metadata, therefore no unit test for this `if`)
/* istanbul ignore if */
if (!get_type_fixed_line(country_metadata) || get_type_fixed_line(country_metadata) === get_type_mobile(country_metadata)) {
return 'FIXED_LINE_OR_MOBILE';
}
return 'MOBILE';
if (is_of_type(national_number, get_type_premium_rate(country_metadata))) {
return 'PREMIUM_RATE';
}
// Is it fixed line number
if (is_of_type(national_number, get_type_fixed_line(country_metadata))) {
// Because duplicate regular expressions are removed
// to reduce metadata size, if there's no "mobile" pattern
// then it means it was removed due to being a duplicate of some other pattern.
//
// Also, many times fixed line phone number regular expressions
// are the same as mobile phone number regular expressions,
// so in these cases there's no differentiation between them.
//
if (!get_type_mobile(country_metadata) || get_type_mobile(country_metadata) === get_type_fixed_line(country_metadata)) {
return 'FIXED_LINE_OR_MOBILE';
}
return 'FIXED_LINE';
}
if (is_of_type(national_number, get_type_toll_free(country_metadata))) {

@@ -79,6 +51,12 @@ return 'TOLL_FREE';

if (is_of_type(national_number, get_type_premium_rate(country_metadata))) {
return 'PREMIUM_RATE';
/* istanbul ignore if */
if (is_of_type(national_number, get_type_shared_cost(country_metadata))) {
return 'SHARED_COST';
}
/* istanbul ignore if */
if (is_of_type(national_number, get_type_voip(country_metadata))) {
return 'VOIP';
}
if (is_of_type(national_number, get_type_personal_number(country_metadata))) {

@@ -89,4 +67,4 @@ return 'PERSONAL_NUMBER';

/* istanbul ignore if */
if (is_of_type(national_number, get_type_voice_mail(country_metadata))) {
return 'VOICEMAIL';
if (is_of_type(national_number, get_type_pager(country_metadata))) {
return 'PAGER';
}

@@ -100,15 +78,31 @@

/* istanbul ignore if */
if (is_of_type(national_number, get_type_pager(country_metadata))) {
return 'PAGER';
if (is_of_type(national_number, get_type_voice_mail(country_metadata))) {
return 'VOICEMAIL';
}
/* istanbul ignore if */
if (is_of_type(national_number, get_type_voip(country_metadata))) {
return 'VOIP';
// Is it fixed line number
if (is_of_type(national_number, get_type_fixed_line(country_metadata))) {
// Because duplicate regular expressions are removed
// to reduce metadata size, if there's no "mobile" pattern
// then it means it was removed due to being a duplicate of some other pattern.
//
if (!get_type_mobile(country_metadata)) {
return 'FIXED_LINE_OR_MOBILE';
}
// Check if the number happens to qualify as both fixed line and mobile.
// (no such country in the minimal metadata set)
/* istanbul ignore if */
if (is_of_type(national_number, get_type_mobile(country_metadata))) {
return 'FIXED_LINE_OR_MOBILE';
}
return 'FIXED_LINE';
}
/* istanbul ignore if */
if (is_of_type(national_number, get_type_shared_cost(country_metadata))) {
return 'SHARED_COST';
if (is_of_type(national_number, get_type_mobile(country_metadata))) {
return 'MOBILE';
}
// return 'UNKNOWN'
}

@@ -115,0 +109,0 @@

@@ -8,2 +8,4 @@ import _Object$keys from 'babel-runtime/core-js/object/keys';

var phone_number_types = ['premium_rate', 'toll_free', 'shared_cost', 'voip', 'personal_number', 'pager', 'uan', 'voice_mail', 'fixed_line', 'mobile'];
// Excessive fields from "PhoneNumberMetadata.xml"

@@ -442,3 +444,2 @@ // aren't included to reduce code complexity and size:

// If this type has just been removed due to redundancy
if (!types[type]) {

@@ -449,4 +450,4 @@ return 'continue';

// Remove redundant types
// (having the same regular expressions as this one)
_Object$keys(types).filter(function (key) {
// (other types having the same regular expressions as this one)
phone_number_types.filter(function (key) {
return key !== type && types[key] === types[type];

@@ -458,3 +459,3 @@ }).forEach(function (key) {

for (var _iterator6 = _getIterator(_Object$keys(types)), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
for (var _iterator6 = _getIterator(phone_number_types), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
var _ret3 = _loop3();

@@ -461,0 +462,0 @@

{
"name": "libphonenumber-js",
"version": "0.4.3",
"version": "0.4.4",
"description": "A simpler (and smaller) rewrite of Google Android's popular libphonenumber library",

@@ -31,3 +31,2 @@ "main": "index.common.js",

"scripts": {
"libphonenumber-metadata": "libphonenumber-generate-metadata metadata.min.json --countries ID --extended",
"metadata:pull-request": "babel-node runnable/metadata-pull-request",

@@ -34,0 +33,0 @@ "metadata:branch": "babel-node runnable/metadata-branch",

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

First, add metadata generation script to your project's `package.json`
First, add metadata generation script to **your project's** `package.json`

@@ -235,0 +235,0 @@ ```js

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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