libphonenumber-js
Advanced tools
Comparing version 0.2.12 to 0.2.13
@@ -112,3 +112,3 @@ 'use strict'; | ||
// Validate possible first part of a phone number | ||
if (!(0, _common.matches_entirely)(VALID_INCOMPLETE_PHONE_NUMBER_PATTERN, extracted_number)) { | ||
if (!(0, _common.matches_entirely)(extracted_number, VALID_INCOMPLETE_PHONE_NUMBER_PATTERN)) { | ||
return this.current_output; | ||
@@ -128,2 +128,7 @@ } | ||
this.parsed_input += '+'; | ||
// If a default country was set | ||
// then reset it because an explicitly international | ||
// phone number is being entered | ||
this.reset_countriness(); | ||
} | ||
@@ -296,8 +301,3 @@ | ||
} else { | ||
this.country = undefined; | ||
this.country_metadata = undefined; | ||
this.country_phone_code = undefined; | ||
this.available_formats = []; | ||
this.matching_formats = this.available_formats; | ||
this.reset_countriness(); | ||
} | ||
@@ -312,2 +312,12 @@ | ||
}, { | ||
key: 'reset_countriness', | ||
value: function reset_countriness() { | ||
this.country = undefined; | ||
this.country_metadata = undefined; | ||
this.country_phone_code = undefined; | ||
this.available_formats = []; | ||
this.matching_formats = this.available_formats; | ||
} | ||
}, { | ||
key: 'reset_format', | ||
@@ -314,0 +324,0 @@ value: function reset_format() { |
@@ -9,4 +9,5 @@ 'use strict'; | ||
// against the regular expression. | ||
function matches_entirely(regular_expression) { | ||
var text = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1]; | ||
function matches_entirely() { | ||
var text = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0]; | ||
var regular_expression = arguments[1]; | ||
@@ -13,0 +14,0 @@ if (typeof regular_expression === 'string') { |
@@ -34,3 +34,7 @@ 'use strict'; | ||
function format(input, format, third_argument) { | ||
function format() { | ||
var input = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0]; | ||
var format = arguments[1]; | ||
var third_argument = arguments[2]; | ||
// If the first argument object is expanded | ||
@@ -149,3 +153,3 @@ if (typeof input === 'string') { | ||
if ((0, _common.matches_entirely)(new RegExp((0, _metadata3.get_format_pattern)(_format)), national_number)) { | ||
if ((0, _common.matches_entirely)(national_number, new RegExp((0, _metadata3.get_format_pattern)(_format)))) { | ||
return _format; | ||
@@ -152,0 +156,0 @@ } |
@@ -281,3 +281,3 @@ 'use strict'; | ||
if (!(0, _common.matches_entirely)(national_number_rule, national_number)) { | ||
if (!(0, _common.matches_entirely)(national_number, national_number_rule)) { | ||
return {}; | ||
@@ -341,3 +341,3 @@ } | ||
function is_viable_phone_number(number) { | ||
return number.length >= MIN_LENGTH_FOR_NSN && (0, _common.matches_entirely)(VALID_PHONE_NUMBER_PATTERN, number); | ||
return number.length >= MIN_LENGTH_FOR_NSN && (0, _common.matches_entirely)(number, VALID_PHONE_NUMBER_PATTERN); | ||
} | ||
@@ -468,3 +468,3 @@ | ||
// If the original number was viable, and the resultant number is not, then return. | ||
if ((0, _common.matches_entirely)(national_number_rule, number) && !(0, _common.matches_entirely)(national_number_rule, national_significant_number)) { | ||
if ((0, _common.matches_entirely)(number, national_number_rule) && !(0, _common.matches_entirely)(national_significant_number, national_number_rule)) { | ||
return number; | ||
@@ -609,4 +609,4 @@ } | ||
// get_type_pattern(type) === type | ||
return (0, _common.matches_entirely)(type, national_number); | ||
return (0, _common.matches_entirely)(national_number, type); | ||
} | ||
//# sourceMappingURL=parse.js.map |
@@ -0,1 +1,6 @@ | ||
0.2.13 / 23.12.2016 | ||
=================== | ||
* Reset `default_country` for "as you type" if the input is an international phone number | ||
0.2.12 / 23.12.2016 | ||
@@ -2,0 +7,0 @@ =================== |
{ | ||
"name": "libphonenumber-js", | ||
"version": "0.2.12", | ||
"version": "0.2.13", | ||
"description": "A simpler (and smaller) rewrite of Google Android's popular libphonenumber library", | ||
@@ -5,0 +5,0 @@ "main": "index.common.js", |
@@ -57,2 +57,6 @@ # libphonenumber-js | ||
## Country code definition | ||
"Country code" means either a [two-letter ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (like `US`) or a special `001` country code used for non-geographical entities (as per [Google's libphonenumber library](https://github.com/googlei18n/libphonenumber/blob/0068d861a68d3d4612f7bf8646ab844dd3cefce5/java/libphonenumber/test/com/google/i18n/phonenumbers/RegionCode.java#L23-L24)). For example, `+7 800 555 35 35` phone number belongs to Russia so it has `RU` country code where as `+800 1 1111 1111` phone number could belong to any country so it has `001` country code. | ||
## API | ||
@@ -67,6 +71,6 @@ | ||
{ | ||
restrict — (a two-letter country code) | ||
restrict — (country code) | ||
the phone number must be in this country | ||
default — (a two-letter country code) | ||
default — (country code) | ||
default country to use for phone number parsing and validation | ||
@@ -77,5 +81,5 @@ (if no country code could be derived from the phone number) | ||
or just a two-letter country code which is gonna be `country.restrict`. | ||
or just a [country code](https://github.com/halt-hammerzeit/libphonenumber-js#country-code-definition) which is gonna be `country.restrict`. | ||
Returns `{ country, phone }` where `country` is a two-letter country code, and `phone` is a national (significant) number. If the phone number supplied isn't valid then an empty object `{}` is returned. | ||
Returns `{ country, phone }` where `country` is a [country code](https://github.com/halt-hammerzeit/libphonenumber-js#country-code-definition), and `phone` is a national (significant) number. If the phone number supplied isn't valid then an empty object `{}` is returned. | ||
@@ -126,4 +130,5 @@ ```js | ||
* `valid` — is the phone number being input a valid one already | ||
* `country` — a two-letter country code of the country this phone belongs to | ||
* `country` — a [country code](https://github.com/halt-hammerzeit/libphonenumber-js#country-code-definition) of the country this phone belongs to | ||
* `country_phone_code` — a phone code of the `country` | ||
* `national_number` — national number part (so far) | ||
* `template` — currently used phone number formatting template, where digits (and the plus sign, if present) are denoted by `x`-es | ||
@@ -130,0 +135,0 @@ |
@@ -135,3 +135,3 @@ // This is an enhanced port of Google Android `libphonenumber`'s | ||
// Validate possible first part of a phone number | ||
if (!matches_entirely(VALID_INCOMPLETE_PHONE_NUMBER_PATTERN, extracted_number)) | ||
if (!matches_entirely(extracted_number, VALID_INCOMPLETE_PHONE_NUMBER_PATTERN)) | ||
{ | ||
@@ -154,2 +154,7 @@ return this.current_output | ||
this.parsed_input += '+' | ||
// If a default country was set | ||
// then reset it because an explicitly international | ||
// phone number is being entered | ||
this.reset_countriness() | ||
} | ||
@@ -336,8 +341,3 @@ | ||
{ | ||
this.country = undefined | ||
this.country_metadata = undefined | ||
this.country_phone_code = undefined | ||
this.available_formats = [] | ||
this.matching_formats = this.available_formats | ||
this.reset_countriness() | ||
} | ||
@@ -352,2 +352,12 @@ | ||
reset_countriness() | ||
{ | ||
this.country = undefined | ||
this.country_metadata = undefined | ||
this.country_phone_code = undefined | ||
this.available_formats = [] | ||
this.matching_formats = this.available_formats | ||
} | ||
reset_format() | ||
@@ -354,0 +364,0 @@ { |
// Checks whether the entire input sequence can be matched | ||
// against the regular expression. | ||
export function matches_entirely(regular_expression, text = '') | ||
export function matches_entirely(text = '', regular_expression) | ||
{ | ||
@@ -5,0 +5,0 @@ if (typeof regular_expression === 'string') |
@@ -29,3 +29,3 @@ // This is a port of Google Android `libphonenumber`'s | ||
export default function format(input, format, third_argument) | ||
export default function format(input = '', format, third_argument) | ||
{ | ||
@@ -167,3 +167,3 @@ // If the first argument object is expanded | ||
if (matches_entirely(new RegExp(get_format_pattern(format)), national_number)) | ||
if (matches_entirely(national_number, new RegExp(get_format_pattern(format)))) | ||
{ | ||
@@ -170,0 +170,0 @@ return format |
@@ -301,3 +301,3 @@ // This is a port of Google Android `libphonenumber`'s | ||
if (!matches_entirely(national_number_rule, national_number)) | ||
if (!matches_entirely(national_number, national_number_rule)) | ||
{ | ||
@@ -347,3 +347,3 @@ return {} | ||
return number.length >= MIN_LENGTH_FOR_NSN && | ||
matches_entirely(VALID_PHONE_NUMBER_PATTERN, number) | ||
matches_entirely(number, VALID_PHONE_NUMBER_PATTERN) | ||
} | ||
@@ -492,4 +492,4 @@ | ||
// If the original number was viable, and the resultant number is not, then return. | ||
if (matches_entirely(national_number_rule, number) && | ||
!matches_entirely(national_number_rule, national_significant_number)) | ||
if (matches_entirely(number, national_number_rule) && | ||
!matches_entirely(national_significant_number, national_number_rule)) | ||
{ | ||
@@ -636,3 +636,3 @@ return number | ||
// get_type_pattern(type) === type | ||
return matches_entirely(type, national_number) | ||
return matches_entirely(national_number, type) | ||
} |
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 not supported yet
Sorry, the diff of this file is too big to display
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
1098733
4587
244