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.1.6 to 0.1.7

58

build/as you type.js

@@ -80,6 +80,6 @@ 'use strict';

this.country_metadata = _metadata2.default.countries[country_code];
this.initialize_possible_formats();
this.initialize_phone_number_formats_for_this_country();
}
this.clear();
this.reset();
}

@@ -180,3 +180,3 @@

if (!this.country_code) {
this.initialize_possible_formats();
this.initialize_phone_number_formats_for_this_country();
}

@@ -192,3 +192,4 @@

// Some national prefixes are substrings of other national prefixes
// (for the same country), therefore extract national prefix each time.
// (for the same country), therefore try to extract national prefix each time
// because a longer national prefix might be available at some point in time.

@@ -202,2 +203,5 @@ var previous_national_prefix = this.national_prefix;

if (this.national_prefix !== previous_national_prefix) {
// National number has changed
// (due to another national prefix been extracted)
// therefore reset all previous formatting data.
this.reset_formatting();

@@ -227,7 +231,8 @@ }

this.filter_possible_formats_by_leading_digits();
// Check if the previously chosen phone number format still holds
this.match_formats_by_leading_digits();
// If the previously chosen phone number format
// didn't match the next digit being input
// (leading digits).
// didn't match the next (current) digit being input
// (leading digits pattern didn't match).
if (this.choose_another_format()) {

@@ -270,4 +275,4 @@ // And a more appropriate phone number format

}, {
key: 'clear',
value: function clear() {
key: 'reset',
value: function reset() {
// // Input text so far, can contain any characters

@@ -300,3 +305,3 @@ // this.original_input = ''

value: function reset_formatting() {
this.possible_formats = this.available_formats;
this.matching_formats = undefined;

@@ -349,4 +354,4 @@ this.current_format = undefined;

}, {
key: 'initialize_possible_formats',
value: function initialize_possible_formats() {
key: 'initialize_phone_number_formats_for_this_country',
value: function initialize_phone_number_formats_for_this_country() {
if (!this.country_metadata) {

@@ -360,8 +365,6 @@ return;

});
this.possible_formats = this.available_formats;
}
}, {
key: 'filter_possible_formats_by_leading_digits',
value: function filter_possible_formats_by_leading_digits() {
key: 'match_formats_by_leading_digits',
value: function match_formats_by_leading_digits() {
var leading_digits = this.national_number;

@@ -384,3 +387,3 @@

this.possible_formats = this.get_possible_formats().filter(function (format) {
this.matching_formats = this.get_relevant_phone_number_formats().filter(function (format) {
var leading_digits_pattern_count = (0, _metadata3.get_format_leading_digits_patterns)(format).length;

@@ -399,6 +402,15 @@

}, {
key: 'get_possible_formats',
value: function get_possible_formats() {
key: 'get_relevant_phone_number_formats',
value: function get_relevant_phone_number_formats() {
var leading_digits = this.national_number;
// "leading digits" patterns start with a maximum 3 digits,
// and then with each additional digit
// a more precise "leading digits" pattern is specified.
// They could make "leading digits" patterns start
// with a maximum of a single digit, but they didn't,
// so it's possible that some phone number formats
// will be falsely rejected until there are at least
// 3 digits in the national (significant) number being input.
if (leading_digits.length <= MIN_LEADING_DIGITS_LENGTH) {

@@ -408,3 +420,5 @@ return this.available_formats;

return this.possible_formats;
// `matching_formats` is `undefined` when formatting has been reset.
// It will be set later, in `match_formats_by_leading_digits()` call.
return this.matching_formats || this.available_formats;
}

@@ -424,3 +438,3 @@

try {
for (var _iterator3 = (0, _getIterator3.default)(this.get_possible_formats()), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
for (var _iterator3 = (0, _getIterator3.default)(this.get_relevant_phone_number_formats()), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var format = _step3.value;

@@ -572,3 +586,3 @@

try {
for (var _iterator4 = (0, _getIterator3.default)(this.get_possible_formats()), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
for (var _iterator4 = (0, _getIterator3.default)(this.get_relevant_phone_number_formats()), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var format = _step4.value;

@@ -575,0 +589,0 @@

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

0.1.7 / 29.11.2016
===================
* (may be a breaking change) renamed `.clear()` to `.reset()` for "as you type" formatter
0.1.5 / 29.11.2016

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

{
"name": "libphonenumber-js",
"version": "0.1.6",
"version": "0.1.7",
"description": "A simpler (and smaller) rewrite of Google Android's famous libphonenumber library",

@@ -5,0 +5,0 @@ "main": "index.common.js",

@@ -11,3 +11,3 @@ # libphonenumber-js

`libphonenumber` is a phone number formatting and parsing library released by Google, originally developed for (and currently used in) Google's [Android](https://en.wikipedia.org/wiki/Android_(operating_system)) mobile phone operating system. Implementing a rigorous phone number formatting and parsing library was crucial for the phone OS overall usability (back then, in the early 2000s, it was originally meant to be a phone after all, not just a SnapChat device).
[`libphonenumber`](https://github.com/googlei18n/libphonenumber) is a phone number formatting and parsing library released by Google, originally developed for (and currently used in) Google's [Android](https://en.wikipedia.org/wiki/Android_(operating_system)) mobile phone operating system. Implementing a rigorous phone number formatting and parsing library was crucial for the phone OS overall usability (back then, in the early 2000s, it was originally meant to be a phone after all, not just a SnapChat device).

@@ -117,3 +117,3 @@ `libphonenumber-js` is a simplified pure javascript port of the original `libphonenumber` library (written in C++ and Java because those are the programming languages used in Android OS). While `libphonenumber` has an [official javascript port](https://github.com/googlei18n/libphonenumber/tree/master/javascript) which is being maintained by Google, it is tightly coupled to Google's `closure` javascript utility framework. It still can be compiled into [one big bundle](http://stackoverflow.com/questions/18678031/how-to-host-the-google-libphonenumber-locally/) which weighs 220 KiloBytes — quite a size for a phone number input component. It [can be reduced](https://github.com/leodido/i18n.phonenumbers.js) to a specific set of countries only but that wouldn't be an option for a worldwide international solution.

* `input(text)` — takes any text and appends it to the input; returns the formatted phone number
* `clear()` — clears input
* `reset()` — resets the input

@@ -120,0 +120,0 @@ ```js

@@ -101,6 +101,6 @@ // This is an enhanced port of Google Android `libphonenumber`'s

this.country_metadata = metadata.countries[country_code]
this.initialize_possible_formats()
this.initialize_phone_number_formats_for_this_country()
}
this.clear()
this.reset()
}

@@ -184,3 +184,3 @@

{
this.initialize_possible_formats()
this.initialize_phone_number_formats_for_this_country()
}

@@ -198,3 +198,4 @@

// Some national prefixes are substrings of other national prefixes
// (for the same country), therefore extract national prefix each time.
// (for the same country), therefore try to extract national prefix each time
// because a longer national prefix might be available at some point in time.

@@ -209,2 +210,5 @@ const previous_national_prefix = this.national_prefix

{
// National number has changed
// (due to another national prefix been extracted)
// therefore reset all previous formatting data.
this.reset_formatting()

@@ -235,7 +239,8 @@ }

this.filter_possible_formats_by_leading_digits()
// Check if the previously chosen phone number format still holds
this.match_formats_by_leading_digits()
// If the previously chosen phone number format
// didn't match the next digit being input
// (leading digits).
// didn't match the next (current) digit being input
// (leading digits pattern didn't match).
if (this.choose_another_format())

@@ -282,3 +287,3 @@ {

clear()
reset()
{

@@ -313,3 +318,3 @@ // // Input text so far, can contain any characters

{
this.possible_formats = this.available_formats
this.matching_formats = undefined

@@ -340,3 +345,3 @@ this.current_format = undefined

initialize_possible_formats()
initialize_phone_number_formats_for_this_country()
{

@@ -353,7 +358,5 @@ if (!this.country_metadata)

})
this.possible_formats = this.available_formats
}
filter_possible_formats_by_leading_digits()
match_formats_by_leading_digits()
{

@@ -378,3 +381,3 @@ const leading_digits = this.national_number

this.possible_formats = this.get_possible_formats().filter((format) =>
this.matching_formats = this.get_relevant_phone_number_formats().filter((format) =>
{

@@ -395,6 +398,15 @@ const leading_digits_pattern_count = get_format_leading_digits_patterns(format).length

get_possible_formats()
get_relevant_phone_number_formats()
{
const leading_digits = this.national_number
// "leading digits" patterns start with a maximum 3 digits,
// and then with each additional digit
// a more precise "leading digits" pattern is specified.
// They could make "leading digits" patterns start
// with a maximum of a single digit, but they didn't,
// so it's possible that some phone number formats
// will be falsely rejected until there are at least
// 3 digits in the national (significant) number being input.
if (leading_digits.length <= MIN_LEADING_DIGITS_LENGTH)

@@ -405,3 +417,5 @@ {

return this.possible_formats
// `matching_formats` is `undefined` when formatting has been reset.
// It will be set later, in `match_formats_by_leading_digits()` call.
return this.matching_formats || this.available_formats
}

@@ -414,3 +428,3 @@

{
for (let format of this.get_possible_formats())
for (let format of this.get_relevant_phone_number_formats())
{

@@ -552,3 +566,3 @@ const matcher = new RegExp('^(?:' + get_format_pattern(format) + ')$')

// format where a formatting template could be created.
for (let format of this.get_possible_formats())
for (let format of this.get_relevant_phone_number_formats())
{

@@ -555,0 +569,0 @@ // If this format is currently being used

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