libphonenumber-js
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -265,2 +265,4 @@ 'use strict'; | ||
// For some phone number formats national prefix | ||
// If the previously chosen phone number format | ||
@@ -453,14 +455,20 @@ // didn't match the next (current) digit being input | ||
if (!matcher.test(this.national_number)) { | ||
// If the national prefix is optional | ||
// then also try to format the phone number | ||
// without the national prefix being extracted. | ||
if (this.national_prefix && (0, _metadata.get_format_national_prefix_is_optional_when_formatting)(format, this.country_metadata)) { | ||
if (!matcher.test(this.national_prefix + this.national_number)) { | ||
continue; | ||
} | ||
// This national prefix extra handling has been | ||
// done already in `extract_national_prefix()`. | ||
// | ||
// // If the national prefix is optional | ||
// // then also try to format the phone number | ||
// // without the national prefix being extracted. | ||
// if (this.national_prefix | ||
// && get_format_national_prefix_is_optional_when_formatting(format, this.country_metadata)) | ||
// { | ||
// if (!matcher.test(this.national_prefix + this.national_number)) | ||
// { | ||
// continue | ||
// } | ||
// | ||
// this.national_number = this.national_prefix + this.national_number | ||
// this.national_prefix = '' | ||
// } | ||
this.national_number = this.national_prefix + this.national_number; | ||
this.national_prefix = ''; | ||
} | ||
continue; | ||
@@ -559,21 +567,9 @@ } | ||
var national_prefix_for_parsing = (0, _metadata.get_national_prefix_for_parsing)(this.country_metadata); | ||
var national_number = (0, _parse.strip_national_prefix)(this.national_number, this.country_metadata); | ||
if (!national_prefix_for_parsing) { | ||
return; | ||
if (national_number !== this.national_number) { | ||
this.national_prefix = this.national_number.slice(0, this.national_number.length - national_number.length); | ||
this.national_number = national_number; | ||
} | ||
var matches = this.national_number.match(new RegExp('^(?:' + national_prefix_for_parsing + ')')); | ||
// Since some national prefix patterns are entirely optional, check that a | ||
// national prefix could actually be extracted. | ||
if (!matches || !matches[0]) { | ||
return; | ||
} | ||
var national_number_starts_at = matches[0].length; | ||
this.national_prefix = this.national_number.slice(0, national_number_starts_at); | ||
this.national_number = this.national_number.slice(national_number_starts_at); | ||
return this.national_prefix; | ||
@@ -580,0 +576,0 @@ } |
@@ -512,4 +512,2 @@ 'use strict'; | ||
var national_prefix_transform_rule = (0, _metadata.get_national_prefix_transform_rule)(country_metadata); | ||
var national_significant_number = void 0; | ||
@@ -520,2 +518,3 @@ | ||
var any_groups_were_captured = national_prefix_matcher[national_prefix_matcher.length - 1]; | ||
var national_prefix_transform_rule = (0, _metadata.get_national_prefix_transform_rule)(country_metadata); | ||
@@ -535,4 +534,8 @@ // If the national number tranformation is needed then do it | ||
// If the original number was viable, and the resultant number is not, | ||
// then prefer the original phone number. | ||
// If the original number (before stripping national prefix) was viable, | ||
// and the resultant number is not, then prefer the original phone number. | ||
// This is because for some countries (e.g. Russia) the same digit could be both | ||
// a national prefix and a leading digit of a valid national phone number, | ||
// like `8` is the national prefix for Russia and both | ||
// `8 800 555 35 35` and `800 555 35 35` are valid numbers. | ||
if ((0, _common.matches_entirely)(number, national_number_rule) && !(0, _common.matches_entirely)(national_significant_number, national_number_rule)) { | ||
@@ -539,0 +542,0 @@ return number; |
@@ -11,3 +11,3 @@ import _getIterator from 'babel-runtime/core-js/get-iterator'; | ||
import { VALID_PUNCTUATION, PLUS_SIGN, PLUS_CHARS, VALID_DIGITS, extract_formatted_phone_number, parse_phone_number, parse_phone_number_and_country_phone_code, find_country_code } from './parse'; | ||
import { VALID_PUNCTUATION, PLUS_SIGN, PLUS_CHARS, VALID_DIGITS, extract_formatted_phone_number, parse_phone_number, parse_phone_number_and_country_phone_code, find_country_code, strip_national_prefix } from './parse'; | ||
@@ -244,2 +244,4 @@ import { FIRST_GROUP_PATTERN, format_national_number_using_format, local_to_international_style } from './format'; | ||
// For some phone number formats national prefix | ||
// If the previously chosen phone number format | ||
@@ -432,14 +434,20 @@ // didn't match the next (current) digit being input | ||
if (!matcher.test(this.national_number)) { | ||
// If the national prefix is optional | ||
// then also try to format the phone number | ||
// without the national prefix being extracted. | ||
if (this.national_prefix && get_format_national_prefix_is_optional_when_formatting(format, this.country_metadata)) { | ||
if (!matcher.test(this.national_prefix + this.national_number)) { | ||
continue; | ||
} | ||
// This national prefix extra handling has been | ||
// done already in `extract_national_prefix()`. | ||
// | ||
// // If the national prefix is optional | ||
// // then also try to format the phone number | ||
// // without the national prefix being extracted. | ||
// if (this.national_prefix | ||
// && get_format_national_prefix_is_optional_when_formatting(format, this.country_metadata)) | ||
// { | ||
// if (!matcher.test(this.national_prefix + this.national_number)) | ||
// { | ||
// continue | ||
// } | ||
// | ||
// this.national_number = this.national_prefix + this.national_number | ||
// this.national_prefix = '' | ||
// } | ||
this.national_number = this.national_prefix + this.national_number; | ||
this.national_prefix = ''; | ||
} | ||
continue; | ||
@@ -538,21 +546,9 @@ } | ||
var national_prefix_for_parsing = get_national_prefix_for_parsing(this.country_metadata); | ||
var national_number = strip_national_prefix(this.national_number, this.country_metadata); | ||
if (!national_prefix_for_parsing) { | ||
return; | ||
if (national_number !== this.national_number) { | ||
this.national_prefix = this.national_number.slice(0, this.national_number.length - national_number.length); | ||
this.national_number = national_number; | ||
} | ||
var matches = this.national_number.match(new RegExp('^(?:' + national_prefix_for_parsing + ')')); | ||
// Since some national prefix patterns are entirely optional, check that a | ||
// national prefix could actually be extracted. | ||
if (!matches || !matches[0]) { | ||
return; | ||
} | ||
var national_number_starts_at = matches[0].length; | ||
this.national_prefix = this.national_number.slice(0, national_number_starts_at); | ||
this.national_number = this.national_number.slice(national_number_starts_at); | ||
return this.national_prefix; | ||
@@ -559,0 +555,0 @@ } |
@@ -484,4 +484,2 @@ import _getIterator from 'babel-runtime/core-js/get-iterator'; | ||
var national_prefix_transform_rule = get_national_prefix_transform_rule(country_metadata); | ||
var national_significant_number = void 0; | ||
@@ -492,2 +490,3 @@ | ||
var any_groups_were_captured = national_prefix_matcher[national_prefix_matcher.length - 1]; | ||
var national_prefix_transform_rule = get_national_prefix_transform_rule(country_metadata); | ||
@@ -507,4 +506,8 @@ // If the national number tranformation is needed then do it | ||
// If the original number was viable, and the resultant number is not, | ||
// then prefer the original phone number. | ||
// If the original number (before stripping national prefix) was viable, | ||
// and the resultant number is not, then prefer the original phone number. | ||
// This is because for some countries (e.g. Russia) the same digit could be both | ||
// a national prefix and a leading digit of a valid national phone number, | ||
// like `8` is the national prefix for Russia and both | ||
// `8 800 555 35 35` and `800 555 35 35` are valid numbers. | ||
if (matches_entirely(number, national_number_rule) && !matches_entirely(national_significant_number, national_number_rule)) { | ||
@@ -511,0 +514,0 @@ return number; |
0.4.0 / 29.03.2017 | ||
=================== | ||
* Removed `.valid` from "as you type" formatter because it wasn't reliable (gave false positives). Use `isValidNumber(value)` for phone number validation instead. | ||
* Removed `.valid` from "as you type" formatter because it wasn't reliable (gave false negatives). Use `isValidNumber(value)` for phone number validation instead. | ||
@@ -6,0 +6,0 @@ 0.3.11 / 07.03.2017 |
{ | ||
"name": "libphonenumber-js", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "A simpler (and smaller) rewrite of Google Android's popular libphonenumber library", | ||
@@ -5,0 +5,0 @@ "main": "index.common.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 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
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
1592745
5535