libphonenumber-js
Advanced tools
Comparing version 0.1.17 to 0.2.0
@@ -160,10 +160,6 @@ 'use strict'; | ||
// If the possible phone number formats | ||
// haven't been initialized during instance creation, | ||
// then do it now. | ||
if (!this.default_country) { | ||
this.initialize_phone_number_formats_for_this_country(); | ||
this.reset_format(); | ||
this.determine_the_country(); | ||
} | ||
// Initialize country-specific data | ||
this.initialize_phone_number_formats_for_this_country_phone_code(); | ||
this.reset_format(); | ||
this.determine_the_country(); | ||
} | ||
@@ -298,3 +294,3 @@ // `this.country` could be `undefined`, | ||
this.initialize_phone_number_formats_for_this_country(); | ||
this.initialize_phone_number_formats_for_this_country_phone_code(); | ||
} else { | ||
@@ -333,4 +329,4 @@ this.country = undefined; | ||
}, { | ||
key: 'initialize_phone_number_formats_for_this_country', | ||
value: function initialize_phone_number_formats_for_this_country() { | ||
key: 'initialize_phone_number_formats_for_this_country_phone_code', | ||
value: function initialize_phone_number_formats_for_this_country_phone_code() { | ||
// Get all "eligible" phone number formats for this country | ||
@@ -431,2 +427,8 @@ this.available_formats = (0, _metadata3.get_formats)(this.country_metadata).filter(function (format) { | ||
if (matcher.test(this.national_number)) { | ||
// To leave the formatter in a consistent state | ||
this.reset_format(); | ||
this.chosen_format = format; | ||
this.create_formatting_template(format); | ||
this.reformat_national_number(); | ||
return (0, _format.format_national_number_using_format)(this.national_number, format, this.is_international(), this.national_prefix, this.country_metadata); | ||
@@ -484,11 +486,2 @@ } | ||
// Check country restriction | ||
if (this.default_country) { | ||
if (country_phone_code !== (0, _metadata3.get_phone_code)(this.country_metadata)) { | ||
// Invalid country phone code for the | ||
// international phone number being input. | ||
return; | ||
} | ||
} | ||
this.country_phone_code = country_phone_code; | ||
@@ -646,3 +639,3 @@ this.national_number = number; | ||
if (this.is_international()) { | ||
this.template = '+' + repeat(DIGIT_PLACEHOLDER, this.country_phone_code.length) + ' ' + this.template; | ||
this.template = DIGIT_PLACEHOLDER + repeat(DIGIT_PLACEHOLDER, this.country_phone_code.length) + ' ' + this.template; | ||
} | ||
@@ -666,3 +659,2 @@ // For local numbers, replace national prefix | ||
try { | ||
for (var _iterator3 = (0, _getIterator3.default)(digits), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
@@ -669,0 +661,0 @@ var digit = _step3.value; |
@@ -0,1 +1,6 @@ | ||
0.2.0 / 02.12.2016 | ||
=================== | ||
* "As you type" formatter's `country_code` argument is now `default_country_code`, and it doesn't restrict to the specified country anymore. | ||
0.1.17 / 01.12.2016 | ||
@@ -2,0 +7,0 @@ =================== |
{ | ||
"name": "libphonenumber-js", | ||
"version": "0.1.17", | ||
"version": "0.2.0", | ||
"description": "A simpler (and smaller) rewrite of Google Android's famous libphonenumber library", | ||
@@ -5,0 +5,0 @@ "main": "index.common.js", |
@@ -109,7 +109,7 @@ # libphonenumber-js | ||
### `class` asYouType(country_code) | ||
### `class` asYouType(default_country_code) | ||
(aka `as_you_type`) | ||
Creates a formatter for partially entered phone number. The two-letter `country_code` is optional and, if specified, restricts the phone number being input to the specified country. The instance of this class has two methods: | ||
Creates a formatter for partially entered phone number. The two-letter `default_country_code` is optional and, if specified, is gonna be the default country for the phone number being input (in case it's not an international one). The instance of this class has two methods: | ||
@@ -116,0 +116,0 @@ * `input(text)` — takes any text and appends it to the input; returns the formatted phone number |
@@ -188,11 +188,6 @@ // This is an enhanced port of Google Android `libphonenumber`'s | ||
// If the possible phone number formats | ||
// haven't been initialized during instance creation, | ||
// then do it now. | ||
if (!this.default_country) | ||
{ | ||
this.initialize_phone_number_formats_for_this_country() | ||
this.reset_format() | ||
this.determine_the_country() | ||
} | ||
// Initialize country-specific data | ||
this.initialize_phone_number_formats_for_this_country_phone_code() | ||
this.reset_format() | ||
this.determine_the_country() | ||
} | ||
@@ -336,3 +331,3 @@ // `this.country` could be `undefined`, | ||
this.initialize_phone_number_formats_for_this_country() | ||
this.initialize_phone_number_formats_for_this_country_phone_code() | ||
} | ||
@@ -371,3 +366,3 @@ else | ||
initialize_phone_number_formats_for_this_country() | ||
initialize_phone_number_formats_for_this_country_phone_code() | ||
{ | ||
@@ -472,2 +467,8 @@ // Get all "eligible" phone number formats for this country | ||
{ | ||
// To leave the formatter in a consistent state | ||
this.reset_format() | ||
this.chosen_format = format | ||
this.create_formatting_template(format) | ||
this.reformat_national_number() | ||
return format_national_number_using_format | ||
@@ -513,13 +514,2 @@ ( | ||
// Check country restriction | ||
if (this.default_country) | ||
{ | ||
if (country_phone_code !== get_phone_code(this.country_metadata)) | ||
{ | ||
// Invalid country phone code for the | ||
// international phone number being input. | ||
return | ||
} | ||
} | ||
this.country_phone_code = country_phone_code | ||
@@ -666,3 +656,3 @@ this.national_number = number | ||
{ | ||
this.template = '+' + repeat(DIGIT_PLACEHOLDER, this.country_phone_code.length) + ' ' + this.template | ||
this.template = DIGIT_PLACEHOLDER + repeat(DIGIT_PLACEHOLDER, this.country_phone_code.length) + ' ' + this.template | ||
} | ||
@@ -682,3 +672,2 @@ // For local numbers, replace national prefix | ||
{ | ||
for (let digit of digits) | ||
@@ -685,0 +674,0 @@ { |
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
1235124
3914