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.4.28 to 0.4.29

97

build/as you type.js

@@ -657,2 +657,37 @@ 'use strict';

// Get formatting template for this phone number format
var template = this.get_template_for_phone_number_format_pattern(format);
// If the national number entered is too long
// for any phone number format, then abort.
if (!template) {
return;
}
// This one is for national number only
this.partially_populated_template = template;
// For convenience, the public `.template` property
// contains the whole international number
// if the phone number being input is international:
// 'x' for the '+' sign, 'x'es for the country phone code,
// a spacebar and then the template for the formatted national number.
if (this.is_international()) {
this.template = DIGIT_PLACEHOLDER + repeat(DIGIT_PLACEHOLDER, this.country_phone_code.length) + ' ' + template;
}
// For local numbers, replace national prefix
// with a digit placeholder.
else {
this.template = template.replace(/\d/g, DIGIT_PLACEHOLDER);
}
// This one is for the full phone number
return this.template;
}
// Generates formatting template for a phone number format
}, {
key: 'get_template_for_phone_number_format_pattern',
value: function get_template_for_phone_number_format_pattern(format) {
var national_prefix_formatting_rule = (0, _metadata.get_format_national_prefix_formatting_rule)(format, this.country_metadata);

@@ -685,28 +720,46 @@

// Create formatting template for this phone number format
var template = dummy_phone_number_matching_format_pattern
// Format the dummy phone number according to the format
.replace(new RegExp(number_pattern, 'g'), number_format)
// Replace each dummy digit with a DIGIT_PLACEHOLDER
.replace(DUMMY_DIGIT_MATCHER, DIGIT_PLACEHOLDER);
// Below `strict_pattern` is used for the
// regular expression (with `^` and `$`).
// This wasn't originally in Google's `libphonenumber`
// and I guess they don't really need it
// because they're not using "templates" to format phone numbers
// but I added `strict_pattern` after encountering
// South Korean phone number formatting bug.
//
// Non-strict regular expression bug demonstration:
//
// this.national_number : `111111111` (9 digits)
//
// number_pattern : (\d{2})(\d{3,4})(\d{4})
// number_format : `$1 $2 $3`
// dummy_phone_number_matching_format_pattern : `9999999999` (10 digits)
//
// '9999999999'.replace(new RegExp(/(\d{2})(\d{3,4})(\d{4})/g), '$1 $2 $3') = "99 9999 9999"
//
// template : xx xxxx xxxx
//
// But the correct template in this case is `xx xxx xxxx`.
// The template was generated incorrectly because of the
// `{3,4}` variability in the `number_pattern`.
//
// The fix is, if `this.national_number` has already sufficient length
// to satisfy the `number_pattern` completely then `this.national_number` is used
// instead of `dummy_phone_number_matching_format_pattern`.
// This one is for national number only
this.partially_populated_template = template;
var strict_pattern = new RegExp('^' + number_pattern + '$');
var national_number_dummy_digits = this.national_number.replace(/\d/g, DUMMY_DIGIT);
// For convenience, the public `.template` property
// contains the whole international number
// if the phone number being input is international:
// 'x' for the '+' sign, 'x'es for the country phone code,
// a spacebar and then the template for the formatted national number.
if (this.is_international()) {
this.template = DIGIT_PLACEHOLDER + repeat(DIGIT_PLACEHOLDER, this.country_phone_code.length) + ' ' + template;
// If `this.national_number` has already sufficient length
// to satisfy the `number_pattern` completely then use it
// instead of `dummy_phone_number_matching_format_pattern`.
if (strict_pattern.test(national_number_dummy_digits)) {
dummy_phone_number_matching_format_pattern = national_number_dummy_digits;
}
// For local numbers, replace national prefix
// with a digit placeholder.
else {
this.template = template.replace(/\d/g, DIGIT_PLACEHOLDER);
}
// This one is for the full phone number
return this.template;
// Generate formatting template for this phone number format
return dummy_phone_number_matching_format_pattern
// Format the dummy phone number according to the format
.replace(new RegExp(number_pattern), number_format)
// Replace each dummy digit with a DIGIT_PLACEHOLDER
.replace(DUMMY_DIGIT_MATCHER, DIGIT_PLACEHOLDER);
}

@@ -713,0 +766,0 @@ }, {

@@ -635,2 +635,37 @@ import _getIterator from 'babel-runtime/core-js/get-iterator';

// Get formatting template for this phone number format
var template = this.get_template_for_phone_number_format_pattern(format);
// If the national number entered is too long
// for any phone number format, then abort.
if (!template) {
return;
}
// This one is for national number only
this.partially_populated_template = template;
// For convenience, the public `.template` property
// contains the whole international number
// if the phone number being input is international:
// 'x' for the '+' sign, 'x'es for the country phone code,
// a spacebar and then the template for the formatted national number.
if (this.is_international()) {
this.template = DIGIT_PLACEHOLDER + repeat(DIGIT_PLACEHOLDER, this.country_phone_code.length) + ' ' + template;
}
// For local numbers, replace national prefix
// with a digit placeholder.
else {
this.template = template.replace(/\d/g, DIGIT_PLACEHOLDER);
}
// This one is for the full phone number
return this.template;
}
// Generates formatting template for a phone number format
}, {
key: 'get_template_for_phone_number_format_pattern',
value: function get_template_for_phone_number_format_pattern(format) {
var national_prefix_formatting_rule = get_format_national_prefix_formatting_rule(format, this.country_metadata);

@@ -663,28 +698,46 @@

// Create formatting template for this phone number format
var template = dummy_phone_number_matching_format_pattern
// Format the dummy phone number according to the format
.replace(new RegExp(number_pattern, 'g'), number_format)
// Replace each dummy digit with a DIGIT_PLACEHOLDER
.replace(DUMMY_DIGIT_MATCHER, DIGIT_PLACEHOLDER);
// Below `strict_pattern` is used for the
// regular expression (with `^` and `$`).
// This wasn't originally in Google's `libphonenumber`
// and I guess they don't really need it
// because they're not using "templates" to format phone numbers
// but I added `strict_pattern` after encountering
// South Korean phone number formatting bug.
//
// Non-strict regular expression bug demonstration:
//
// this.national_number : `111111111` (9 digits)
//
// number_pattern : (\d{2})(\d{3,4})(\d{4})
// number_format : `$1 $2 $3`
// dummy_phone_number_matching_format_pattern : `9999999999` (10 digits)
//
// '9999999999'.replace(new RegExp(/(\d{2})(\d{3,4})(\d{4})/g), '$1 $2 $3') = "99 9999 9999"
//
// template : xx xxxx xxxx
//
// But the correct template in this case is `xx xxx xxxx`.
// The template was generated incorrectly because of the
// `{3,4}` variability in the `number_pattern`.
//
// The fix is, if `this.national_number` has already sufficient length
// to satisfy the `number_pattern` completely then `this.national_number` is used
// instead of `dummy_phone_number_matching_format_pattern`.
// This one is for national number only
this.partially_populated_template = template;
var strict_pattern = new RegExp('^' + number_pattern + '$');
var national_number_dummy_digits = this.national_number.replace(/\d/g, DUMMY_DIGIT);
// For convenience, the public `.template` property
// contains the whole international number
// if the phone number being input is international:
// 'x' for the '+' sign, 'x'es for the country phone code,
// a spacebar and then the template for the formatted national number.
if (this.is_international()) {
this.template = DIGIT_PLACEHOLDER + repeat(DIGIT_PLACEHOLDER, this.country_phone_code.length) + ' ' + template;
// If `this.national_number` has already sufficient length
// to satisfy the `number_pattern` completely then use it
// instead of `dummy_phone_number_matching_format_pattern`.
if (strict_pattern.test(national_number_dummy_digits)) {
dummy_phone_number_matching_format_pattern = national_number_dummy_digits;
}
// For local numbers, replace national prefix
// with a digit placeholder.
else {
this.template = template.replace(/\d/g, DIGIT_PLACEHOLDER);
}
// This one is for the full phone number
return this.template;
// Generate formatting template for this phone number format
return dummy_phone_number_matching_format_pattern
// Format the dummy phone number according to the format
.replace(new RegExp(number_pattern), number_format)
// Replace each dummy digit with a DIGIT_PLACEHOLDER
.replace(DUMMY_DIGIT_MATCHER, DIGIT_PLACEHOLDER);
}

@@ -691,0 +744,0 @@ }, {

{
"name": "libphonenumber-js",
"version": "0.4.28",
"version": "0.4.29",
"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 too big to display

Sorry, the diff of this file is not supported yet

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