awesome-phonenumber
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"author": "Gustaf Räntilä <g.rantila@gmail.com>", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -68,3 +68,26 @@ 'use strict'; | ||
function extractRegionCode( phoneNumber ) | ||
{ | ||
if ( phoneNumber.charAt( 0 ) !== '+' || phoneNumber.length < 5 ) | ||
return null; | ||
var firstOne = phoneNumber.substr( 1, 1 ); | ||
var firstTwo = phoneNumber.substr( 1, 2 ); | ||
var firstThree = phoneNumber.substr( 1, 3 ); | ||
var regionCode; | ||
regionCode = PhoneNumber.getRegionCodeForCountryCode( firstOne ); | ||
if ( regionCode !== 'ZZ' ) | ||
return regionCode; | ||
regionCode = PhoneNumber.getRegionCodeForCountryCode( firstTwo ); | ||
if ( regionCode !== 'ZZ' ) | ||
return regionCode; | ||
regionCode = PhoneNumber.getRegionCodeForCountryCode( firstThree ); | ||
if ( regionCode !== 'ZZ' ) | ||
return regionCode; | ||
} | ||
/** | ||
@@ -97,2 +120,18 @@ * The PhoneNumber class. | ||
if ( !isInternal ) | ||
{ | ||
if ( regionCode && ( phoneNumber.charAt( 0 ) === '+' ) ) | ||
{ | ||
// Ensure region code is valid | ||
var cc = PhoneNumber.getCountryCodeForRegionCode( regionCode ); | ||
if ( phoneNumber.substr( 1, cc.length ) !== cc ) | ||
// Wrong region code, let's fix it | ||
regionCode = null; | ||
} | ||
if ( !regionCode ) | ||
// Guess region code | ||
regionCode = extractRegionCode( phoneNumber ); | ||
} | ||
this._json = { | ||
@@ -150,3 +189,6 @@ 'number' : { }, | ||
{ | ||
return phoneUtil.getRegionCodeForCountryCode( countryCode ); | ||
var regionCode = phoneUtil.getRegionCodeForCountryCode( countryCode ); | ||
if ( regionCode.substr( 0, 2 ) === '00' ) | ||
return PhoneNumber.getRegionCodeForCountryCode( regionCode.substr( 2 ) ); | ||
return regionCode; | ||
} | ||
@@ -153,0 +195,0 @@ |
Sorry, the diff of this file is too big to display
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
258042
1411