Comparing version 0.0.3 to 0.0.4
@@ -59,3 +59,6 @@ /** | ||
{"alpha2": "CF", "alpha3": "CAF", "country_code": "236", "phone_number_lengths": [8], "validation_begin_with": ["7"]}, | ||
{"alpha2": "CA", "alpha3": "CAN", "country_code": "1", "phone_number_lengths": [10], "validation_begin_with": []}, | ||
{"alpha2": "CA", "alpha3": "CAN", "country_code": "1", "phone_number_lengths": [10], | ||
"validation_begin_with": ["204", "226", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", | ||
"418", "431", "437", "438", "450", "506", "514", "519", "579", "581", "587", "604", "613", "639", "647", | ||
"672", "705", "709", "742", "778", "780", "807", "819", "825", "867", "873", "902", "905"]}, | ||
{"alpha2": "CC", "alpha3": "CCK", "country_code": "61", "phone_number_lengths": [], "validation_begin_with": []}, | ||
@@ -99,2 +102,3 @@ {"alpha2": "CH", "alpha3": "CHE", "country_code": "41", "phone_number_lengths": [9], "validation_begin_with": ["7"]}, | ||
{"alpha2": "GA", "alpha3": "GAB", "country_code": "241", "phone_number_lengths": [8], "validation_begin_with": ["05", "06", "07"]}, | ||
//http://www.area-codes.org.uk/ http://www.area-codes.org.uk/07-mobile-codes.php | ||
{"alpha2": "GB", "alpha3": "GBR", "country_code": "44", "phone_number_lengths": [10], "validation_begin_with": ["7"]}, | ||
@@ -253,3 +257,26 @@ {"alpha2": "GE", "alpha3": "GEO", "country_code": "995", "phone_number_lengths": [9], "validation_begin_with": ["5", "7"]}, | ||
{"alpha2": "UY", "alpha3": "URY", "country_code": "598", "phone_number_lengths": [8], "validation_begin_with": ["9"]}, | ||
{"alpha2": "US", "alpha3": "USA", "country_code": "1", "phone_number_lengths": [10], "validation_begin_with": []}, | ||
// http://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#900.E2.80.93999 | ||
{"alpha2": "US", "alpha3": "USA", "country_code": "1", "phone_number_lengths": [10], | ||
"validation_begin_with": ["201", "202", "203", "205", "206", "207", "208", "209", "210", "212", "213", "214", | ||
"215", "216", "217", "218", "219", "224", "225", "227", "228", "229", "231", "234", "239", "240", "248", | ||
"251", "252", "253", "254", "256", "260", "262", "267", "269", "270", "272", "274", "276", "281", "283", | ||
"301", "302", "303", "304", "305", "307", "308", "309", "310", "312", "313", "314", "315", "316", "317", | ||
"318", "319", "320", "321", "323", "325", "327", "330", "331", "334", "336", "337", "339", "341", "346", | ||
"347", "351", "352", "360", "361", "364", "369", "380", "385", "386", "401", "402", "404", "405", "406", | ||
"407", "408", "409", "410", "412", "413", "414", "415", "417", "419", "423", "424", "425", "430", "432", | ||
"434", "435", "440", "442", "443", "445", "447", "458", "464", "469", "470", "475", "478", "479", "480", | ||
"484", "501", "502", "503", "504", "505", "507", "508", "509", "510", "512", "513", "515", "516", "517", | ||
"518", "520", "530", "531", "534", "539", "540", "541", "551", "557", "559", "561", "562", "563", "564", | ||
"567", "570", "571", "573", "574", "575", "580", "582", "585", "586", "601", "602", "603", "605", "606", | ||
"607", "608", "609", "610", "612", "614", "615", "616", "617", "618", "619", "620", "623", "626", "627", | ||
"628", "630", "631", "636", "641", "646", "650", "651", "657", "659", "660", "661", "662", "667", "669", | ||
"678", "679", "681", "682", "689", "701", "702", "703", "704", "706", "707", "708", "712", "713", "714", | ||
"715", "716", "717", "718", "719", "720", "724", "725", "727", "730", "731", "732", "734", "737", "740", | ||
"747", "754", "757", "760", "762", "763", "764", "765", "769", "770", "772", "773", "774", "775", "779", | ||
"781", "785", "786", "801", "802", "803", "804", "805", "806", "808", "810", "812", "813", "814", "815", | ||
"816", "817", "818", "828", "830", "831", "832", "835", "843", "845", "847", "848", "850", "856", "857", | ||
"858", "859", "860", "862", "863", "864", "865", "870", "872", "878", "901", "903", "904", "906", "907", | ||
"908", "909", "910", "912", "913", "914", "915", "916", "917", "918", "919", "920", "925", "928", "929", | ||
"931", "935", "936", "937", "938", "940", "941", "947", "949", "951", "952", "954", "956", "959", "970", | ||
"971", "972", "973", "975", "978", "979", "980", "984", "985", "989"]}, | ||
{"alpha2": "UZ", "alpha3": "UZB", "country_code": "998", "phone_number_lengths": [9], "validation_begin_with": ["9"]}, | ||
@@ -256,0 +283,0 @@ {"alpha2": "VA", "alpha3": "VAT", "country_code": "39", "phone_number_lengths": [], "validation_begin_with": []}, |
{ | ||
"name": "phone", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"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", |
## What is node-phone? | ||
`node-phone` is used to normalize the phone number into a E.164 format. | ||
`node-phone` is used to normalize the `mobile` phone number into a E.164 format. | ||
@@ -28,6 +28,14 @@ The common problem is user normally input the phone number in this way: | ||
No: If the phone number start with `+` sign, even you pass the country. | ||
`phone` will simply remove all non digit and return `+XXXXXXXX` to you. | ||
2. Why do you make this? | ||
`phone` will simply remove all non digit and return `+XXXXXXXX` to you. | ||
2. Why some of the number is valid, but return null? | ||
This npm is used to validate a mobile phone number for sending the SMS. | ||
So, we try to match all possible rule, such as area code, number prefix, etc. to test if it is a mobile phone number. | ||
However, some countries, like USA, we can only check if it is a valid `AREA CODE`, there is no mobile phone prefix. | ||
For UK, we know that mobile phone number is always start with `7`, in this case, this npm will be more helpful. | ||
3. Why do you make this? | ||
Because we need to normalize the phone number for SMS notification for mobile phone only. | ||
@@ -45,3 +53,3 @@ | ||
``` | ||
var phone = require('phone`); | ||
var phone = require('phone'); | ||
@@ -58,4 +66,23 @@ phone('(817) 569-8900', ''); // return +18175698900 | ||
## Test | ||
``` | ||
npm test | ||
`` | ||
## Help | ||
We try to google for many results, but none of package can fit our need. | ||
If you know that our rule is wrong, or can add more validation to make this npm more accurate. | ||
Please open an issue and let us know. | ||
## Change Log | ||
* 0.0.4 Added US, CA area code to make it more accurate. | ||
## License | ||
MIT | ||
@@ -29,8 +29,16 @@ var should = require('should'), | ||
describe("phone('22-6569-8900', '')", function() { | ||
it('returns +', function() { | ||
var result = phone('22-6569-8900', ''); | ||
result.should.eql('+12265698900'); | ||
// as 226 is NOT a valid USA code | ||
it('returns null', function() { | ||
var result = (phone('22-6569-8900', '') == null); | ||
result.should.eql(true); | ||
}); | ||
}); | ||
describe("phone('22-5569-8900', '')", function() { | ||
it('returns +12255698900', function() { | ||
var result = phone('22-5569-8900', ''); | ||
result.should.eql('+12255698900'); | ||
}); | ||
}); | ||
describe("phone('+1 (817) 569-8900', 'uniTed States')", function() { | ||
@@ -114,1 +122,35 @@ it('returns +18175698900', function() { | ||
describe('Testing UK Phone', function() { | ||
// return null, as `790` is NOT the USA area code | ||
describe("phone('07902687632', '')", function() { | ||
it('returns null', function() { | ||
var result = (phone('07902687632', '') == null); | ||
result.should.eql(true); | ||
}); | ||
}); | ||
describe("phone('07902687632', null)", function() { | ||
it('returns null', function() { | ||
var result = (phone('07902687632', '') == null); | ||
result.should.eql(true); | ||
}); | ||
}); | ||
describe("phone('07902687632', 'GBR')", function() { | ||
it('returns +447902687632', function() { | ||
var result = phone('07902687632', 'GBR'); | ||
result.should.eql('+447902687632'); | ||
}); | ||
}); | ||
describe("phone('06902687632', 'GBR')", function() { | ||
it('returns null', function() { | ||
var result = (phone('06902687632', 'GBR') === null); | ||
// because the UK mobile must start with 7 | ||
result.should.eql(true); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56674
795
86