Socket
Socket
Sign inDemoInstall

libphonenumber-js

Package Overview
Dependencies
Maintainers
1
Versions
392
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libphonenumber-js - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

77

build/as you type.js

@@ -305,2 +305,4 @@ 'use strict';

this.valid = false;
return this;
}

@@ -425,9 +427,13 @@ }, {

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();
var number_pattern = this.validate_format(format);
return (0, _format.format_national_number_using_format)(this.national_number, format, this.is_international(), this.national_prefix, this.country_metadata);
if (number_pattern) {
// To leave the formatter in a consistent state
this.reset_format();
this.chosen_format = format;
this.create_formatting_template(format, number_pattern);
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);
}
}

@@ -541,3 +547,7 @@ }

// and use it to format the phone number being input.
if (this.create_formatting_template(format)) {
var number_pattern = this.validate_format(format);
if (number_pattern) {
this.create_formatting_template(format, number_pattern);
this.chosen_format = format;

@@ -576,6 +586,4 @@

}, {
key: 'create_formatting_template',
value: function create_formatting_template(format) {
var number_pattern = (0, _metadata3.get_format_pattern)(format);
key: 'validate_format',
value: function validate_format(format) {
// The formatter doesn't format numbers when numberPattern contains '|', e.g.

@@ -585,8 +593,21 @@ // (20|3)\d{4}. In those cases we quickly return.

/* istanbul ignore if */
if (number_pattern.indexOf('|') >= 0) {
if ((0, _metadata3.get_format_pattern)(format).indexOf('|') >= 0) {
return;
}
// Now, a very smart trick by the guys at Google
number_pattern = number_pattern
var national_prefix_formatting_rule = (0, _metadata3.get_format_national_prefix_formatting_rule)(format, this.country_metadata);
// If national prefix formatting rule is set
// for this phone number format
if (national_prefix_formatting_rule) {
// If national prefix is mandatory for this rule
// and the user didn't input the national prefix
// then this template isn't suitable.
if (!(0, _metadata3.get_format_national_prefix_is_optional_when_formatting)(format, this.country_metadata) && !this.national_prefix) {
return;
}
}
// A very smart trick by the guys at Google
var number_pattern = (0, _metadata3.get_format_pattern)(format)
// Replace anything in the form of [..] with \d

@@ -597,5 +618,24 @@ .replace(CHARACTER_CLASS_PATTERN, '\\d')

// This match will always succeed,
// because the "longest dummy phone number"
// has enough length to accomodate any possible
// national phone number format pattern.
var dummy_phone_number_matching_format_pattern = LONGEST_DUMMY_PHONE_NUMBER.match(number_pattern)[0];
// If the national number entered is too long
// for any phone number format, then abort.
if (this.national_number.length > dummy_phone_number_matching_format_pattern.length) {
return;
}
return number_pattern;
}
}, {
key: 'create_formatting_template',
value: function create_formatting_template(format, number_pattern) {
var number_format = this.get_format_format(format);
this.national_prefix_is_part_of_formatting_template = false;
// If the user did input the national prefix
// then maybe make it a part of the phone number template
if (this.national_prefix) {

@@ -605,4 +645,5 @@ var national_prefix_formatting_rule = (0, _metadata3.get_format_national_prefix_formatting_rule)(format, this.country_metadata);

// If national prefix formatting rule is set
// (e.g. it is not set for US)
// for this phone number format
if (national_prefix_formatting_rule) {
// Make the national prefix a part of the phone number template
number_format = number_format.replace(_format.FIRST_GROUP_PATTERN, national_prefix_formatting_rule);

@@ -622,8 +663,2 @@ this.national_prefix_is_part_of_formatting_template = true;

// If the national number entered is too long
// for any phone number format, then abort.
if (this.national_number.length > dummy_phone_number_matching_format_pattern.length) {
return;
}
// Create formatting template for this phone number format

@@ -630,0 +665,0 @@ var template = dummy_phone_number_matching_format_pattern

@@ -0,1 +1,6 @@

0.2.6 / 22.12.2016
===================
* Fixed a minor bug in "as you type" when a local phone number without national prefix got formatted with the national prefix
0.2.2 / 14.12.2016

@@ -2,0 +7,0 @@ ===================

{
"name": "libphonenumber-js",
"version": "0.2.5",
"version": "0.2.6",
"description": "A simpler (and smaller) rewrite of Google Android's popular libphonenumber library",

@@ -29,3 +29,3 @@ "main": "index.common.js",

"scripts": {
"metadata:publish": "npm version patch && npm publish && git add package.json && git commit -m 'Bump version'",
"metadata:publish": "npm version patch && npm publish && git push",
"metadata:update": "npm run metadata:download && babel-node runnable/update",

@@ -32,0 +32,0 @@ "metadata:generate": "npm run generate && npm run compress",

@@ -18,2 +18,3 @@ // This is an enhanced port of Google Android `libphonenumber`'s

get_format_national_prefix_formatting_rule,
get_format_national_prefix_is_optional_when_formatting,
get_format_leading_digits_patterns,

@@ -345,2 +346,4 @@ get_metadata_by_country_phone_code

this.valid = false
return this
}

@@ -466,16 +469,21 @@

{
// To leave the formatter in a consistent state
this.reset_format()
this.chosen_format = format
this.create_formatting_template(format)
this.reformat_national_number()
const number_pattern = this.validate_format(format)
return format_national_number_using_format
(
this.national_number,
format,
this.is_international(),
this.national_prefix,
this.country_metadata
)
if (number_pattern)
{
// To leave the formatter in a consistent state
this.reset_format()
this.chosen_format = format
this.create_formatting_template(format, number_pattern)
this.reformat_national_number()
return format_national_number_using_format
(
this.national_number,
format,
this.is_international(),
this.national_prefix,
this.country_metadata
)
}
}

@@ -568,4 +576,8 @@ }

// and use it to format the phone number being input.
if (this.create_formatting_template(format))
const number_pattern = this.validate_format(format)
if (number_pattern)
{
this.create_formatting_template(format, number_pattern)
this.chosen_format = format

@@ -589,6 +601,4 @@

create_formatting_template(format)
validate_format(format)
{
let number_pattern = get_format_pattern(format)
// The formatter doesn't format numbers when numberPattern contains '|', e.g.

@@ -598,3 +608,3 @@ // (20|3)\d{4}. In those cases we quickly return.

/* istanbul ignore if */
if (number_pattern.indexOf('|') >= 0)
if (get_format_pattern(format).indexOf('|') >= 0)
{

@@ -604,4 +614,20 @@ return

// Now, a very smart trick by the guys at Google
number_pattern = number_pattern
const national_prefix_formatting_rule = get_format_national_prefix_formatting_rule(format, this.country_metadata)
// If national prefix formatting rule is set
// for this phone number format
if (national_prefix_formatting_rule)
{
// If national prefix is mandatory for this rule
// and the user didn't input the national prefix
// then this template isn't suitable.
if (!get_format_national_prefix_is_optional_when_formatting(format, this.country_metadata)
&& !this.national_prefix)
{
return
}
}
// A very smart trick by the guys at Google
const number_pattern = get_format_pattern(format)
// Replace anything in the form of [..] with \d

@@ -612,5 +638,25 @@ .replace(CHARACTER_CLASS_PATTERN, '\\d')

// This match will always succeed,
// because the "longest dummy phone number"
// has enough length to accomodate any possible
// national phone number format pattern.
const dummy_phone_number_matching_format_pattern = LONGEST_DUMMY_PHONE_NUMBER.match(number_pattern)[0]
// If the national number entered is too long
// for any phone number format, then abort.
if (this.national_number.length > dummy_phone_number_matching_format_pattern.length)
{
return
}
return number_pattern
}
create_formatting_template(format, number_pattern)
{
let number_format = this.get_format_format(format)
this.national_prefix_is_part_of_formatting_template = false
// If the user did input the national prefix
// then maybe make it a part of the phone number template
if (this.national_prefix)

@@ -621,5 +667,6 @@ {

// If national prefix formatting rule is set
// (e.g. it is not set for US)
// for this phone number format
if (national_prefix_formatting_rule)
{
// Make the national prefix a part of the phone number template
number_format = number_format.replace(FIRST_GROUP_PATTERN, national_prefix_formatting_rule)

@@ -639,9 +686,2 @@ this.national_prefix_is_part_of_formatting_template = true

// If the national number entered is too long
// for any phone number format, then abort.
if (this.national_number.length > dummy_phone_number_matching_format_pattern.length)
{
return
}
// Create formatting template for this phone number format

@@ -648,0 +688,0 @@ const template = dummy_phone_number_matching_format_pattern

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc