Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

phone

Package Overview
Dependencies
Maintainers
1
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phone - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

146

lib/index.js

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

'use stricts';
var iso3166_data = [

@@ -34,3 +36,3 @@ // if no country is given, default to USA. DO NOT move this position

{alpha2: "AO", alpha3: "AGO", country_code: "244", country_name: "Angola", mobile_begin_with: ["9"], phone_number_lengths: [9]},
{alpha2: "AI", alpha3: "AIA", country_code: "1", country_name: "Anguilla", mobile_begin_with: ["5", "7"], phone_number_lengths: [7]},
{alpha2: "AI", alpha3: "AIA", country_code: "1", country_name: "Anguilla", mobile_begin_with: ["2645", "2647"], phone_number_lengths: [10]},
{alpha2: "AX", alpha3: "ALA", country_code: "358", country_name: "Åland Islands", mobile_begin_with: ["18"], phone_number_lengths: [6, 7, 8]},

@@ -43,6 +45,8 @@ {alpha2: "AL", alpha3: "ALB", country_code: "355", country_name: "Albania", mobile_begin_with: ["6"], phone_number_lengths: [8]},

{alpha2: "AM", alpha3: "ARM", country_code: "374", country_name: "Armenia", mobile_begin_with: ["5", "7", "9"], phone_number_lengths: [8]},
{alpha2: "AS", alpha3: "ASM", country_code: "1", country_name: "American Samoa", mobile_begin_with: ["733", "258"], phone_number_lengths: [7]},
// http://www.howtocallabroad.com/results.php?callfrom=united_states&callto=american_samoa
{alpha2: "AS", alpha3: "ASM", country_code: "1", country_name: "American Samoa", mobile_begin_with: ["684733", "684258"], phone_number_lengths: [10]},
//{alpha2: "AQ", alpha3: "ATA", country_code: "672", country_name: "Antarctica", mobile_begin_with: [], phone_number_lengths: []},
//{alpha2: "TF", alpha3: "ATF", country_code: "", country_name: "French Southern Territories", mobile_begin_with: [], phone_number_lengths: []},
{alpha2: "AG", alpha3: "ATG", country_code: "1", country_name: "Antigua and Barbuda", mobile_begin_with: ["4", "7"], phone_number_lengths: [7]},
// http://www.howtocallabroad.com/results.php?callfrom=united_states&callto=antigua_barbuda
{alpha2: "AG", alpha3: "ATG", country_code: "1", country_name: "Antigua and Barbuda", mobile_begin_with: ["2687"], phone_number_lengths: [10]},
{alpha2: "AU", alpha3: "AUS", country_code: "61", country_name: "Australia", mobile_begin_with: ["4"], phone_number_lengths: [9]},

@@ -58,3 +62,3 @@ {alpha2: "AT", alpha3: "AUT", country_code: "43", country_name: "Austria", mobile_begin_with: ["6"], phone_number_lengths: [10]},

{alpha2: "BH", alpha3: "BHR", country_code: "973", country_name: "Bahrain", mobile_begin_with: ["3"], phone_number_lengths: [8]},
{alpha2: "BS", alpha3: "BHS", country_code: "1", country_name: "Bahamas", mobile_begin_with: ["3", "4", "5", "6", "7"], phone_number_lengths: [7]},
{alpha2: "BS", alpha3: "BHS", country_code: "1", country_name: "Bahamas", mobile_begin_with: ["242"], phone_number_lengths: [10]},
{alpha2: "BA", alpha3: "BIH", country_code: "387", country_name: "Bosnia and Herzegovina", mobile_begin_with: ["6"], phone_number_lengths: [8]},

@@ -64,3 +68,4 @@ //{alpha2: "BL", alpha3: "BLM", country_code: "590", country_name: "Saint Barthélemy", mobile_begin_with: [], phone_number_lengths: []},

{alpha2: "BZ", alpha3: "BLZ", country_code: "501", country_name: "Belize", mobile_begin_with: ["6"], phone_number_lengths: [7]},
{alpha2: "BM", alpha3: "BMU", country_code: "1", country_name: "Bermuda", mobile_begin_with: ["3", "5", "7"], phone_number_lengths: [7]},
// http://www.howtocallabroad.com/results.php?callfrom=united_states&callto=bermuda
{alpha2: "BM", alpha3: "BMU", country_code: "1", country_name: "Bermuda", mobile_begin_with: ["4413", "4415", "4417"], phone_number_lengths: [10]},
{alpha2: "BO", alpha3: "BOL", country_code: "591", country_name: "Bolivia", mobile_begin_with: ["7"], phone_number_lengths: [8]},

@@ -72,3 +77,3 @@ {alpha2: "BR", alpha3: "BRA", country_code: "55", country_name: "Brazil", mobile_begin_with: [

], phone_number_lengths: [10, 11]},
{alpha2: "BB", alpha3: "BRB", country_code: "1", country_name: "Barbados", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "BB", alpha3: "BRB", country_code: "1", country_name: "Barbados", mobile_begin_with: [246], phone_number_lengths: [10]},
{alpha2: "BN", alpha3: "BRN", country_code: "673", country_name: "Brunei Darussalam", mobile_begin_with: ["7", "8"], phone_number_lengths: [7]},

@@ -107,3 +112,3 @@ {alpha2: "BT", alpha3: "BTN", country_code: "975", country_name: "Bhutan", mobile_begin_with: ["17"], phone_number_lengths: [8]},

{alpha2: "DJ", alpha3: "DJI", country_code: "253", country_name: "Djibouti", mobile_begin_with: ["77"], phone_number_lengths: [8]},
{alpha2: "DM", alpha3: "DMA", country_code: "1", country_name: "Dominica", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "DM", alpha3: "DMA", country_code: "1", country_name: "Dominica", mobile_begin_with: ["767"], phone_number_lengths: [10]},
{alpha2: "DK", alpha3: "DNK", country_code: "45", country_name: "Denmark", mobile_begin_with: ["2", "30", "31", "40", "41", "42", "50", "51", "52", "53", "60", "61", "71", "81", "91", "92", "93"], phone_number_lengths: [8]},

@@ -137,7 +142,7 @@ {alpha2: "DO", alpha3: "DOM", country_code: "1", country_name: "Dominican Republic", mobile_begin_with: ["809", "829", "849"], phone_number_lengths: [10]},

{alpha2: "GR", alpha3: "GRC", country_code: "30", country_name: "Greece", mobile_begin_with: ["6"], phone_number_lengths: [10]},
{alpha2: "GD", alpha3: "GRD", country_code: "1", country_name: "Grenada", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "GD", alpha3: "GRD", country_code: "1", country_name: "Grenada", mobile_begin_with: ["473"], phone_number_lengths: [10]},
{alpha2: "GL", alpha3: "GRL", country_code: "299", country_name: "Greenland", mobile_begin_with: ["4", "5"], phone_number_lengths: [6]},
{alpha2: "GT", alpha3: "GTM", country_code: "502", country_name: "Guatemala", mobile_begin_with: ["3", "4", "5"], phone_number_lengths: [8]},
{alpha2: "GF", alpha3: "GUF", country_code: "594", country_name: "French Guiana", mobile_begin_with: ["694"], phone_number_lengths: [9]},
{alpha2: "GU", alpha3: "GUM", country_code: "1", country_name: "Guam", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "GU", alpha3: "GUM", country_code: "1", country_name: "Guam", mobile_begin_with: ["671"], phone_number_lengths: [10]},
{alpha2: "GY", alpha3: "GUY", country_code: "592", country_name: "Guyana", mobile_begin_with: ["6"], phone_number_lengths: [7]},

@@ -160,3 +165,3 @@ {alpha2: "HK", alpha3: "HKG", country_code: "852", country_name: "Hong Kong", mobile_begin_with: ["5", "6", "9"], phone_number_lengths: [8]},

{alpha2: "IT", alpha3: "ITA", country_code: "39", country_name: "Italy", mobile_begin_with: ["3"], phone_number_lengths: [10]},
{alpha2: "JM", alpha3: "JAM", country_code: "1", country_name: "Jamaica", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "JM", alpha3: "JAM", country_code: "1", country_name: "Jamaica", mobile_begin_with: ["876"], phone_number_lengths: [10]},
//{alpha2: "JE", alpha3: "JEY", country_code: "44", country_name: "Jersey", mobile_begin_with: [], phone_number_lengths: []},

@@ -170,3 +175,3 @@ {alpha2: "JO", alpha3: "JOR", country_code: "962", country_name: "Jordan", mobile_begin_with: ["7"], phone_number_lengths: [9]},

{alpha2: "KI", alpha3: "KIR", country_code: "686", country_name: "Kiribati", mobile_begin_with: ["9", "30"], phone_number_lengths: [5]},
{alpha2: "KN", alpha3: "KNA", country_code: "1", country_name: "Saint Kitts And Nevis", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "KN", alpha3: "KNA", country_code: "1", country_name: "Saint Kitts And Nevis", mobile_begin_with: ["869"], phone_number_lengths: [10]},
{alpha2: "KR", alpha3: "KOR", country_code: "82", country_name: "Korea, Republic of", mobile_begin_with: ["1"], phone_number_lengths: [9, 10]},

@@ -178,3 +183,3 @@ {alpha2: "KW", alpha3: "KWT", country_code: "965", country_name: "Kuwait", mobile_begin_with: ["5", "6", "9"], phone_number_lengths: [8]},

{alpha2: "LY", alpha3: "LBY", country_code: "218", country_name: "Libyan Arab Jamahiriya", mobile_begin_with: ["9"], phone_number_lengths: [9]},
{alpha2: "LC", alpha3: "LCA", country_code: "1", country_name: "Saint Lucia", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "LC", alpha3: "LCA", country_code: "1", country_name: "Saint Lucia", mobile_begin_with: ["758"], phone_number_lengths: [10]},
{alpha2: "LI", alpha3: "LIE", country_code: "423", country_name: "Liechtenstein", mobile_begin_with: ["7"], phone_number_lengths: [7]},

@@ -201,6 +206,6 @@ {alpha2: "LK", alpha3: "LKA", country_code: "94", country_name: "Sri Lanka", mobile_begin_with: ["7"], phone_number_lengths: [9]},

{alpha2: "MN", alpha3: "MNG", country_code: "976", country_name: "Mongolia", mobile_begin_with: ["5", "8", "9"], phone_number_lengths: [8]},
{alpha2: "MP", alpha3: "MNP", country_code: "1", country_name: "Northern Mariana Islands", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "MP", alpha3: "MNP", country_code: "1", country_name: "Northern Mariana Islands", mobile_begin_with: ["670"], phone_number_lengths: [10]},
{alpha2: "MZ", alpha3: "MOZ", country_code: "258", country_name: "Mozambique", mobile_begin_with: ["8"], phone_number_lengths: [9]},
{alpha2: "MR", alpha3: "MRT", country_code: "222", country_name: "Mauritania", mobile_begin_with: [], phone_number_lengths: [8]},
{alpha2: "MS", alpha3: "MSR", country_code: "1", country_name: "Montserrat", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "MS", alpha3: "MSR", country_code: "1", country_name: "Montserrat", mobile_begin_with: ["664"], phone_number_lengths: [10]},
{alpha2: "MQ", alpha3: "MTQ", country_code: "596", country_name: "Martinique", mobile_begin_with: ["696"], phone_number_lengths: [9]},

@@ -232,3 +237,3 @@ {alpha2: "MU", alpha3: "MUS", country_code: "230", country_name: "Mauritius", mobile_begin_with: [], phone_number_lengths: [7]},

{alpha2: "PL", alpha3: "POL", country_code: "48", country_name: "Poland", mobile_begin_with: ["5", "6", "7", "8"], phone_number_lengths: [9]},
{alpha2: "PR", alpha3: "PRI", country_code: "1", country_name: "Puerto Rico", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "PR", alpha3: "PRI", country_code: "1", country_name: "Puerto Rico", mobile_begin_with: ["787", "939"], phone_number_lengths: [10]},
//{alpha2: "KP", alpha3: "PRK", country_code: "850", country_name: "Korea, Democratic People's Republic Of", mobile_begin_with: [], phone_number_lengths: []},

@@ -256,2 +261,3 @@ {alpha2: "PT", alpha3: "PRT", country_code: "351", country_name: "Portugal", mobile_begin_with: ["9"], phone_number_lengths: [9]},

{alpha2: "SO", alpha3: "SOM", country_code: "252", country_name: "Somalia", mobile_begin_with: ["9"], phone_number_lengths: [8]},
{alpha2: "SX", alpha3: "SXM", country_code: "1", country_name: "Sint Maarten", mobile_begin_with: ["721"], phone_number_lengths: [10]},
{alpha2: "PM", alpha3: "SPM", country_code: "508", country_name: "Saint Pierre And Miquelon", mobile_begin_with: ["55"], phone_number_lengths: [6]},

@@ -267,3 +273,4 @@ {alpha2: "RS", alpha3: "SRB", country_code: "381", country_name: "Serbia", mobile_begin_with: ["6"], phone_number_lengths: [8, 9]},

{alpha2: "SY", alpha3: "SYR", country_code: "963", country_name: "Syrian Arab Republic", mobile_begin_with: ["9"], phone_number_lengths: [9]},
{alpha2: "TC", alpha3: "TCA", country_code: "1", country_name: "Turks and Caicos Islands", mobile_begin_with: ["2", "3", "4"], phone_number_lengths: [7]},
// http://www.howtocallabroad.com/turks-caicos/
{alpha2: "TC", alpha3: "TCA", country_code: "1", country_name: "Turks and Caicos Islands", mobile_begin_with: ["6492", "6493", "6494"], phone_number_lengths: [10]},
{alpha2: "TD", alpha3: "TCD", country_code: "235", country_name: "Chad", mobile_begin_with: ["6", "7", "9"], phone_number_lengths: [8]},

@@ -277,3 +284,3 @@ {alpha2: "TG", alpha3: "TGO", country_code: "228", country_name: "Togo", mobile_begin_with: ["9"], phone_number_lengths: [8]},

{alpha2: "TO", alpha3: "TON", country_code: "676", country_name: "Tonga", mobile_begin_with: [], phone_number_lengths: [5]},
{alpha2: "TT", alpha3: "TTO", country_code: "1", country_name: "Trinidad and Tobago", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "TT", alpha3: "TTO", country_code: "1", country_name: "Trinidad and Tobago", mobile_begin_with: ["868"], phone_number_lengths: [10]},
{alpha2: "TN", alpha3: "TUN", country_code: "216", country_name: "Tunisia", mobile_begin_with: ["2", "9"], phone_number_lengths: [8]},

@@ -290,6 +297,6 @@ {alpha2: "TR", alpha3: "TUR", country_code: "90", country_name: "Turkey", mobile_begin_with: ["5"], phone_number_lengths: [10]},

//{alpha2: "VA", alpha3: "VAT", country_code: "39", country_name: "Holy See (Vatican City State)", mobile_begin_with: [], phone_number_lengths: []},
{alpha2: "VC", alpha3: "VCT", country_code: "1", country_name: "Saint Vincent And The Grenedines", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "VC", alpha3: "VCT", country_code: "1", country_name: "Saint Vincent And The Grenedines", mobile_begin_with: ["784"], phone_number_lengths: [10]},
{alpha2: "VE", alpha3: "VEN", country_code: "58", country_name: "Venezuela, Bolivarian Republic of", mobile_begin_with: ["4"], phone_number_lengths: [10]},
{alpha2: "VG", alpha3: "VGB", country_code: "1", country_name: "Virgin Islands, British", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "VI", alpha3: "VIR", country_code: "1", country_name: "Virgin Islands, U.S.", mobile_begin_with: [], phone_number_lengths: [7]},
{alpha2: "VG", alpha3: "VGB", country_code: "1", country_name: "Virgin Islands, British", mobile_begin_with: ["284"], phone_number_lengths: [10]},
{alpha2: "VI", alpha3: "VIR", country_code: "1", country_name: "Virgin Islands, U.S.", mobile_begin_with: ["340"], phone_number_lengths: [10]},
{alpha2: "VN", alpha3: "VNM", country_code: "84", country_name: "Viet Nam", mobile_begin_with: ["9", "1"], phone_number_lengths: [9, 10]},

@@ -307,4 +314,4 @@ {alpha2: "VU", alpha3: "VUT", country_code: "678", country_name: "Vanuatu", mobile_begin_with: ["5", "7"], phone_number_lengths: [7]},

// assign default to USA country first
var iso3166 = {},
i;
var iso3166 = {};
var upper_case_country = country.toUpperCase();

@@ -316,24 +323,30 @@ switch (country.length) {

case 2:
for (i in iso3166_data) {
if (country.toUpperCase() === iso3166_data[i].alpha2) {
iso3166 = iso3166_data[i];
break;
iso3166_data.every(function(iso3166_datum) {
if (upper_case_country === iso3166_datum.alpha2) {
iso3166 = iso3166_datum;
return false;
}
}
return true;
});
break;
case 3:
for (i in iso3166_data) {
if (country.toUpperCase() === iso3166_data[i].alpha3) {
iso3166 = iso3166_data[i];
break;
iso3166_data.every(function(iso3166_datum) {
if (upper_case_country === iso3166_datum.alpha3) {
iso3166 = iso3166_datum;
return false;
}
}
return true;
});
break;
default:
for (i in iso3166_data) {
if (country.toLowerCase() === iso3166_data[i].country_name.toLowerCase()) {
iso3166 = iso3166_data[i];
break;
iso3166_data.every(function(iso3166_datum) {
if (upper_case_country === iso3166_datum.country_name.toUpperCase()) {
iso3166 = iso3166_datum;
return false;
}
}
return true;
});
}

@@ -345,37 +358,44 @@

function get_iso3166_by_phone(phone) {
var regex;
for (var i in iso3166_data) {
regex = new RegExp('^' + iso3166_data[i].country_code);
var iso3166 = {};
for (var j in iso3166_data[i].phone_number_lengths) {
if (phone.match(regex) && phone.length === iso3166_data[i].country_code.length + iso3166_data[i].phone_number_lengths[j]) {
iso3166_data.every(function(iso3166_datum) {
var regex = new RegExp('^' + iso3166_datum.country_code);
return iso3166_datum.phone_number_lengths.every(function(phone_number_length) {
if (phone.match(regex) && phone.length === iso3166_datum.country_code.length + phone_number_length) {
// it match.. but may have more than one result.
// e.g. USA and Canada. need to check mobile_begin_with
return iso3166_datum.mobile_begin_with.every(function(mobile_begin_with) {
if (phone.match(new RegExp('^' + iso3166_datum.country_code + mobile_begin_with))) {
iso3166 = iso3166_datum;
return false;
}
for (var k in iso3166_data[i].mobile_begin_with) {
if (phone.match(new RegExp('^' + iso3166_data[i].country_code + iso3166_data[i].mobile_begin_with[k]))) {
return iso3166_data[i]
}
}
return true;
});
}
}
}
return {};
return true;
});
});
return iso3166;
}
function validate_phone_iso3166(phone, iso3166) {
phone = phone.replace(new RegExp('^' + iso3166.country_code), '');
for (var i in iso3166.phone_number_lengths) {
if (phone.length === iso3166.phone_number_lengths[i]) {
for (var j in iso3166.mobile_begin_with) {
if (phone.match(new RegExp('^' + iso3166.mobile_begin_with[j]))) {
return true;
}
}
}
if (!iso3166.phone_number_lengths) {
return false;
}
return false;
return iso3166.phone_number_lengths.some(function(phone_number_length) {
if (phone.length === phone_number_length) {
return iso3166.mobile_begin_with.some(function(mobile_begin_with) {
return phone.match(new RegExp('^' + mobile_begin_with));
});
}
return false;
});
}

@@ -438,3 +458,2 @@

}
}

@@ -446,3 +465,2 @@ } else {

iso3166 = get_iso3166_by_phone(phone);
} else {

@@ -452,3 +470,3 @@ // B: no country, no plus sign --> treat it as USA

// no plus sign, no country is given. then it must be USA
//iso3166 = iso3166_data[0]; already assign by the default value
// iso3166 = iso3166_data[0]; already assign by the default value
if (iso3166.phone_number_lengths.indexOf(phone.length) !== -1) {

@@ -458,4 +476,2 @@ phone = '1' + phone;

}
}

@@ -462,0 +478,0 @@

{
"name": "phone",
"version": "1.0.4",
"version": "1.0.5",
"description": "With a given country and phone number, validate and format the phone number to E.164 standard",

@@ -5,0 +5,0 @@ "main": "./lib/index",

@@ -120,2 +120,4 @@ ## What is node-phone?

## Change Log
* 1.0.5 Bug fix for [#31](https://github.com/AfterShip/node-phone/issues/31), allow [extend more easily](https://github.com/AfterShip/node-phone/issues/32)
* 1.0.4 Support more countries with mobile prefix

@@ -134,5 +136,9 @@

## TO DO in version 2.0
- Support detect both land line and mobile
- Support more lookup other than ISO3166-alpha2, alpha3, may also support mobile country code (MCC)
## License
MIT

@@ -199,2 +199,329 @@ var should = require('should'),

describe('Testing +1 but NOT in USA', function() {
describe('+1 340 United States Virgin Islands', function() {
var number = '+1 340 1234 567',
country = 'VIR',
result = ['+13401234567', 'VIR'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 670 Northern Mariana Islands', function() {
var number = '+1 670 1234 567',
country = 'MNP',
result = ['+16701234567', 'MNP'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 671 Guam', function() {
var number = '+1 671 1234 567',
country = 'GUM',
result = ['+16711234567', 'GUM'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 684 American Samoa', function() {
var number = '+1 684 1234 567',
country = 'ASM',
result = [];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 684 American Samoa', function() {
var number = '+1 684 2584 567',
country = 'ASM',
result = ['+16842584567', 'ASM'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 684 American Samoa', function() {
var number = '+1 684 7334 567',
country = 'ASM',
result = ['+16847334567', 'ASM'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 787 / 939 Puerto Rico', function() {
var number = '+1 787 1234 567',
country = 'PRI',
result = ['+17871234567', 'PRI'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 787 / 939 Puerto Rico', function() {
var number = '+1 939 1234 567',
country = 'PRI',
result = ['+19391234567', 'PRI'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 242 Bahamas', function() {
var number = '+1 242 1234 567',
country = 'BHS',
result = ['+12421234567', 'BHS'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 246 Barbados', function() {
var number = '+1 246 1234 567',
country = 'BRB',
result = ['+12461234567', 'BRB'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 264 Anguilla', function() {
var number = '+1 264 1234 567',
country = 'AIA',
result = [];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 264 Anguilla', function() {
var number = '+1 264 5234 567',
country = 'AIA',
result = ['+12645234567', 'AIA'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 264 Anguilla', function() {
var number = '+1 264 7234 567',
country = 'AIA',
result = ['+12647234567', 'AIA'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 268 Antigua and Barbuda', function() {
var number = '+1 268 1234 567',
country = 'ATG',
result = [];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 268 Antigua and Barbuda', function() {
var number = '+1 268 7234 567',
country = 'ATG',
result = ['+12687234567', 'ATG'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 284 British Virgin Islands', function() {
var number = '+1 284 1234 567',
country = 'VGB',
result = ['+12841234567', 'VGB'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 345 Cayman Islands', function() {
var number = '+1 345 1234 567',
country = 'CYM',
result = ['+13451234567', 'CYM'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 441 Bermuda', function() {
var number = '+1 441 1234 567',
country = 'BMU',
result = [];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 441 Bermuda', function() {
var number = '+1 441 3234 567',
country = 'BMU',
result = ['+14413234567', 'BMU'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 441 Bermuda', function() {
var number = '+1 441 5234 567',
country = 'BMU',
result = ['+14415234567', 'BMU'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 441 Bermuda', function() {
var number = '+1 441 7234 567',
country = 'BMU',
result = ['+14417234567', 'BMU'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 473 Grenada', function() {
var number = '+1 473 1234 567',
country = 'GRD',
result = ['+14731234567', 'GRD'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 649 Turks and Caicos Islands', function() {
var number = '+1 649 1234 567',
country = 'TCA',
result = [];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 649 Turks and Caicos Islands', function() {
var number = '+1 649 2234 567',
country = 'TCA',
result = ['+16492234567', 'TCA'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 664 Montserrat', function() {
var number = '+1 664 1234 567',
country = 'MSR',
result = ['+16641234567', 'MSR'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 721 Sint Maarten', function() {
var number = '+1 721 1234 567',
country = 'SXM',
result = ['+17211234567', 'SXM'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 758 Saint Lucia', function() {
var number = '+1 758 1234 567',
country = 'LCA',
result = ['+17581234567', 'LCA'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 767 Dominica', function() {
var number = '+1 767 1234 567',
country = 'DMA',
result = ['+17671234567', 'DMA'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 784 Saint Vincent and the Grenadines', function() {
var number = '+1 784 1234 567',
country = 'VCT',
result = ['+17841234567', 'VCT'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 809 / 829 / 849 Dominican Republic', function() {
var number = '+1 809 1234 567',
country = 'DOM',
result = ['+18091234567', 'DOM'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 809 / 829 / 849 Dominican Republic', function() {
var number = '+1 829 1234 567',
country = 'DOM',
result = ['+18291234567', 'DOM'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 809 / 829 / 849 Dominican Republic', function() {
var number = '+1 849 1234 567',
country = 'DOM',
result = ['+18491234567', 'DOM'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 868 Trinidad and Tobago', function() {
var number = '+1 868 1234 567',
country = 'TTO',
result = ['+18681234567', 'TTO'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 869 Saint Kitts and Nevis', function() {
var number = '+1 869 1234 567',
country = 'KNA',
result = ['+18691234567', 'KNA'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('+1 876 Jamaica', function() {
var number = '+1 876 1234 567',
country = 'JAM',
result = ['+18761234567', 'JAM'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
});
describe('Testing MEX Phone', function() {

@@ -406,2 +733,31 @@ // valid +phone, null

describe('Testing PRI Phone Quick Test', function() {
describe('Test 1', function() {
var number = '+1-787-672-9999',
country = 'PRI',
result = ['+17876729999', 'PRI'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('Test 2', function() {
var number = '17876729999',
country = 'PRI',
result = ['+17876729999', 'PRI'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
describe('Test 3', function() {
var number = '7876729999',
country = 'PRI',
result = ['+17876729999', 'PRI'];
it('returns ' + result, function() {
phone(number, country).should.eql(result);
});
});
});
// input --> output

@@ -408,0 +764,0 @@ // 89234567890, RUS --> +79234567890, RUS

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