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.49 to 0.4.50

build/AsYouType.js

0

bin/update-metadata.js

@@ -0,0 +0,0 @@ #!/usr/bin/env node

2

build/common.js

@@ -18,4 +18,4 @@ 'use strict';

var matched_groups = text.match(regular_expression);
return matched_groups && matched_groups[0].length === text.length;
return matched_groups !== null && matched_groups[0].length === text.length;
}
//# sourceMappingURL=common.js.map

@@ -74,7 +74,13 @@ 'use strict';

var national_number = format_national_number(number, 'International', false, country_metadata);
return '+' + (0, _metadata.get_phone_code)(country_metadata) + ' ' + national_number;
var international_number = '+' + (0, _metadata.get_phone_code)(country_metadata) + ' ' + national_number;
return add_extension(international_number, input.ext);
case 'E.164':
// "International_plaintext" is deprecated
case 'International_plaintext':
return '+' + (0, _metadata.get_phone_code)(country_metadata) + input.phone;
case 'RFC3966':
return '+' + (0, _metadata.get_phone_code)(country_metadata) + input.phone + (input.ext !== undefined ? ';ext=' + input.ext : '');
case 'National':

@@ -84,10 +90,8 @@ if (!number) {

}
return format_national_number(number, 'National', false, country_metadata);
var _national_number = format_national_number(number, 'National', false, country_metadata);
return add_extension(_national_number, input.ext);
}
}
// This was originally set to $1 but there are some countries for which the
// first group is not used in the national pattern (e.g. Argentina) so the $1
// group does not match correctly. Therefore, we use \d, so that the first
// group actually used in the pattern will be matched.
// Adds phone number extension.
// This is a port of Google Android `libphonenumber`'s

@@ -98,2 +102,15 @@ // `phonenumberutil.js` of 17th November, 2016.

function add_extension(number, extension) {
if (extension === undefined) {
return number;
}
// The " ext. " part could be internationalized but that's a job for CLDR.
return number + ' ext. ' + extension;
}
// This was originally set to $1 but there are some countries for which the
// first group is not used in the national pattern (e.g. Argentina) so the $1
// group does not match correctly. Therefore, we use \d, so that the first
// group actually used in the pattern will be matched.
var FIRST_GROUP_PATTERN = exports.FIRST_GROUP_PATTERN = /(\$\d)/;

@@ -235,4 +252,7 @@

case 'International':
case 'E.164':
// "International_plaintext" is deprecated
case 'International_plaintext':
case 'National':
case 'RFC3966':
break;

@@ -239,0 +259,0 @@ default:

@@ -32,3 +32,3 @@ 'use strict';

var _getNumberType = require('./get number type');
var _getNumberType = require('./getNumberType');

@@ -39,2 +39,3 @@ var _getNumberType2 = _interopRequireDefault(_getNumberType);

// The maximum length of the country calling code.
// This is a port of Google Android `libphonenumber`'s

@@ -45,2 +46,15 @@ // `phonenumberutil.js` of 17th November, 2016.

var MAX_LENGTH_COUNTRY_CODE = 3;
// The minimum length of the national significant number.
var MIN_LENGTH_FOR_NSN = 2;
// The ITU says the maximum length should be 15,
// but one can find longer numbers in Germany.
var MAX_LENGTH_FOR_NSN = 17;
// We don't allow input strings for parsing to be longer than 250 chars.
// This prevents malicious input from consuming CPU.
var MAX_INPUT_STRING_LENGTH = 250;
var PLUS_CHARS = exports.PLUS_CHARS = '+\uFF0B';

@@ -66,2 +80,30 @@

// Pattern to capture digits used in an extension.
// Places a maximum length of '7' for an extension.
var CAPTURING_EXTN_DIGITS = '([' + VALID_DIGITS + ']{1,7})';
// The RFC 3966 format for extensions.
var RFC3966_EXTN_PREFIX = ';ext=';
/**
* Regexp of all possible ways to write extensions, for use when parsing. This
* will be run as a case-insensitive regexp match. Wide character versions are
* also provided after each ASCII version. There are three regular expressions
* here. The first covers RFC 3966 format, where the extension is added using
* ';ext='. The second more generic one starts with optional white space and
* ends with an optional full stop (.), followed by zero or more spaces/tabs
* /commas and then the numbers themselves. The other one covers the special
* case of American numbers where the extension is written with a hash at the
* end, such as '- 503#'. Note that the only capturing groups should be around
* the digits that you want to capture as part of the extension, or else parsing
* will fail! We allow two options for representing the accented o - the
* character itself, and one in the unicode decomposed form with the combining
* acute accent.
*/
var EXTN_PATTERNS_FOR_PARSING = RFC3966_EXTN_PREFIX + CAPTURING_EXTN_DIGITS + '|' + '[ \xA0\\t,]*' + '(?:e?xt(?:ensi(?:o\u0301?|\xF3))?n?|\uFF45?\uFF58\uFF54\uFF4E?|' + '[;,x\uFF58#\uFF03~\uFF5E]|int|anexo|\uFF49\uFF4E\uFF54)' + '[:\\.\uFF0E]?[ \xA0\\t,-]*' + CAPTURING_EXTN_DIGITS + '#?|' + '[- ]+([' + VALID_DIGITS + ']{1,5})#';
// Regexp of all known extension prefixes used by different regions followed by
// 1 or more valid digits, for use when parsing.
var EXTN_PATTERN = new RegExp('(?:' + EXTN_PATTERNS_FOR_PARSING + ')$', 'i');
// Regular expression of viable phone numbers. This is location independent.

@@ -105,5 +147,4 @@ // Checks we have at least three leading digits, and only valid punctuation,

'^' + VALID_PHONE_NUMBER +
// screw phone number extensions
// '(?:' + EXTN_PATTERNS_FOR_PARSING + ')?' +
'$', 'i');
// Phone number extensions
'(?:' + EXTN_PATTERNS_FOR_PARSING + ')?' + '$', 'i');

@@ -165,18 +206,4 @@ // This consists of the plus symbol, digits, and arabic-indic digits.

'\u06F9': '9' // Eastern-Arabic digit 9
};
// The maximum length of the country calling code.
};var MAX_LENGTH_COUNTRY_CODE = 3;
// The minimum length of the national significant number.
var MIN_LENGTH_FOR_NSN = 2;
// The ITU says the maximum length should be 15,
// but one can find longer numbers in Germany.
var MAX_LENGTH_FOR_NSN = 17;
// We don't allow input strings for parsing to be longer than 250 chars.
// This prevents malicious input from consuming CPU.
var MAX_INPUT_STRING_LENGTH = 250;
var default_options = {

@@ -242,2 +269,13 @@ country: {}

// Attempt to parse extension first, since it doesn't require region-specific
// data and we want to have the non-normalised number here.
var _strip_extension = strip_extension(formatted_phone_number),
number_without_extension = _strip_extension.number,
extension = _strip_extension.extension;
if (extension !== undefined) {
formatted_phone_number = number_without_extension;
}
var _parse_phone_number_a = parse_phone_number_and_country_phone_code(formatted_phone_number, metadata),

@@ -286,3 +324,3 @@ country_phone_code = _parse_phone_number_a.country_phone_code,

number = normalize(text);
number = normalize(formatted_phone_number);
}

@@ -362,3 +400,12 @@

return { country: country, phone: national_number };
var result = {
country: country,
phone: national_number
};
if (extension) {
result.ext = extension;
}
return result;
}

@@ -680,2 +727,32 @@

}
// Strips any extension (as in, the part of the number dialled after the call is
// connected, usually indicated with extn, ext, x or similar) from the end of
// the number, and returns it.
function strip_extension(number) {
var start = number.search(EXTN_PATTERN);
if (start < 0) {
return {};
}
// If we find a potential extension, and the number preceding this is a viable
// number, we assume it is an extension.
var number_without_extension = number.slice(0, start);
/* istanbul ignore if - seems a bit of a redundant check */
if (!is_viable_phone_number(number_without_extension)) {
return {};
}
var matches = number.match(EXTN_PATTERN);
var i = 1;
while (i < matches.length) {
if (matches[i] != null && matches[i].length > 0) {
return {
number: number_without_extension,
extension: matches[i]
};
}
i++;
}
}
//# sourceMappingURL=parse.js.map

@@ -239,4 +239,4 @@ 'use strict';

// Never happens
if (format.format.indexOf(_asYouType.DIGIT_PLACEHOLDER) >= 0) {
throw new Error('Phone number format "' + format.format + '" contains a reserved "' + _asYouType.DIGIT_PLACEHOLDER + '" symbol for pattern ' + format.pattern + ' for ' + country_code);
if (format.format.indexOf(_AsYouType.DIGIT_PLACEHOLDER) >= 0) {
throw new Error('Phone number format "' + format.format + '" contains a reserved "' + _AsYouType.DIGIT_PLACEHOLDER + '" symbol for pattern ' + format.pattern + ' for ' + country_code);
}

@@ -340,3 +340,3 @@ }

//
// This inncreases metadata size by 5 KiloBytes.
// This increases metadata size by 5 KiloBytes.
//

@@ -502,3 +502,3 @@ } catch (err) {

var _asYouType = require('../as you type');
var _AsYouType = require('../AsYouType');

@@ -576,3 +576,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// {
// '+7': ['RU', 'KZ', ...],
// '7': ['RU', 'KZ', ...],
// ...

@@ -612,2 +612,30 @@ // },

// }
//
// `country_phone_code_to_countries` map is kinda redundant.
// Not sure why did I choose to place country phone codes
// into a separate structure inside metadata instead of generating it in runtime.
// One extra feature it gives though is it tells what's the
// "default" country for a given country phone code.
// E.g. for country phone code `1` the "default" country is "US"
// and therefore "US" is the first country code in the
// `country_phone_code_to_countries["1"]` list.
// The "default" country is the one holding metadata for a country phone code
// so, for example, when "CA" (Canada) country is chosen
// then it uses the metadata for the "default" country ("US").
//
// `country_phone_code_to_countries` data takes about 3 KiloBytes
// so it could kinda make sense to drop it from the metadata file
// replacing it with a "default" country flag (something like `1` for "yes").
// In that scenario `country_phone_code_to_countries` would be generated on startup.
// It would have to also provide an exported `getCountryPhoneCodes()` function
// which would take `metadata` and return `country_phone_code_to_countries` map
// because some people use that `country_phone_code_to_countries` map in their projects.
//
// On the other hand, having `country_phone_code_to_countries`
// prepopulated yields more elegance to the exports
// because if `country_phone_code_to_countries` wasn't part of metadata
// it would have to be computed somewhere in global scope
// therefore the modules wouldn't be strictly "pure"
// so maybe `country_phone_code_to_countries` stays as part of metadata.
//

@@ -614,0 +642,0 @@

@@ -12,3 +12,3 @@ 'use strict';

var _getNumberType = require('./get number type');
var _getNumberType = require('./getNumberType');

@@ -15,0 +15,0 @@ var _getNumberType2 = _interopRequireDefault(_getNumberType);

@@ -8,11 +8,15 @@ 'use strict'

exports.format = require('./build/format').default
exports.get_number_type = require('./build/get number type').default
exports.is_valid_number = require('./build/validate').default
exports.as_you_type = require('./build/as you type').default
exports.DIGIT_PLACEHOLDER = require('./build/as you type').DIGIT_PLACEHOLDER
exports.getNumberType = require('./build/getNumberType').default
exports.isValidNumber = require('./build/validate').default
exports.AsYouType = require('./build/AsYouType').default
exports.DIGIT_PLACEHOLDER = require('./build/AsYouType').DIGIT_PLACEHOLDER
// camelCase aliases
exports.getNumberType = exports.get_number_type
exports.isValidNumber = exports.is_valid_number
exports.asYouType = exports.as_you_type
// `get_number_type` name is deprecated
exports.get_number_type = exports.getNumberType
// `is_valid_number` name is deprecated
exports.is_valid_number = exports.isValidNumber
// `as_you_type` name is deprecated
exports.as_you_type = exports.AsYouType
// `asYouType` name is deprecated
exports.asYouType = exports.AsYouType

@@ -19,0 +23,0 @@ var get_phone_code = require('./build/metadata').get_phone_code

@@ -12,4 +12,4 @@ // Checks whether the entire input sequence can be matched

var matched_groups = text.match(regular_expression);
return matched_groups && matched_groups[0].length === text.length;
return matched_groups !== null && matched_groups[0].length === text.length;
}
//# sourceMappingURL=common.js.map

@@ -61,7 +61,13 @@ import _getIterator from 'babel-runtime/core-js/get-iterator';

var national_number = format_national_number(number, 'International', false, country_metadata);
return '+' + get_phone_code(country_metadata) + ' ' + national_number;
var international_number = '+' + get_phone_code(country_metadata) + ' ' + national_number;
return add_extension(international_number, input.ext);
case 'E.164':
// "International_plaintext" is deprecated
case 'International_plaintext':
return '+' + get_phone_code(country_metadata) + input.phone;
case 'RFC3966':
return '+' + get_phone_code(country_metadata) + input.phone + (input.ext !== undefined ? ';ext=' + input.ext : '');
case 'National':

@@ -71,6 +77,17 @@ if (!number) {

}
return format_national_number(number, 'National', false, country_metadata);
var _national_number = format_national_number(number, 'National', false, country_metadata);
return add_extension(_national_number, input.ext);
}
}
// Adds phone number extension.
function add_extension(number, extension) {
if (extension === undefined) {
return number;
}
// The " ext. " part could be internationalized but that's a job for CLDR.
return number + ' ext. ' + extension;
}
// This was originally set to $1 but there are some countries for which the

@@ -216,4 +233,7 @@ // first group is not used in the national pattern (e.g. Argentina) so the $1

case 'International':
case 'E.164':
// "International_plaintext" is deprecated
case 'International_plaintext':
case 'National':
case 'RFC3966':
break;

@@ -220,0 +240,0 @@ default:

@@ -16,4 +16,18 @@ import _getIterator from 'babel-runtime/core-js/get-iterator';

import get_number_type from './get number type';
import get_number_type from './getNumberType';
// The maximum length of the country calling code.
var MAX_LENGTH_COUNTRY_CODE = 3;
// The minimum length of the national significant number.
var MIN_LENGTH_FOR_NSN = 2;
// The ITU says the maximum length should be 15,
// but one can find longer numbers in Germany.
var MAX_LENGTH_FOR_NSN = 17;
// We don't allow input strings for parsing to be longer than 250 chars.
// This prevents malicious input from consuming CPU.
var MAX_INPUT_STRING_LENGTH = 250;
export var PLUS_CHARS = '+\uFF0B';

@@ -39,2 +53,30 @@

// Pattern to capture digits used in an extension.
// Places a maximum length of '7' for an extension.
var CAPTURING_EXTN_DIGITS = '([' + VALID_DIGITS + ']{1,7})';
// The RFC 3966 format for extensions.
var RFC3966_EXTN_PREFIX = ';ext=';
/**
* Regexp of all possible ways to write extensions, for use when parsing. This
* will be run as a case-insensitive regexp match. Wide character versions are
* also provided after each ASCII version. There are three regular expressions
* here. The first covers RFC 3966 format, where the extension is added using
* ';ext='. The second more generic one starts with optional white space and
* ends with an optional full stop (.), followed by zero or more spaces/tabs
* /commas and then the numbers themselves. The other one covers the special
* case of American numbers where the extension is written with a hash at the
* end, such as '- 503#'. Note that the only capturing groups should be around
* the digits that you want to capture as part of the extension, or else parsing
* will fail! We allow two options for representing the accented o - the
* character itself, and one in the unicode decomposed form with the combining
* acute accent.
*/
var EXTN_PATTERNS_FOR_PARSING = RFC3966_EXTN_PREFIX + CAPTURING_EXTN_DIGITS + '|' + '[ \xA0\\t,]*' + '(?:e?xt(?:ensi(?:o\u0301?|\xF3))?n?|\uFF45?\uFF58\uFF54\uFF4E?|' + '[;,x\uFF58#\uFF03~\uFF5E]|int|anexo|\uFF49\uFF4E\uFF54)' + '[:\\.\uFF0E]?[ \xA0\\t,-]*' + CAPTURING_EXTN_DIGITS + '#?|' + '[- ]+([' + VALID_DIGITS + ']{1,5})#';
// Regexp of all known extension prefixes used by different regions followed by
// 1 or more valid digits, for use when parsing.
var EXTN_PATTERN = new RegExp('(?:' + EXTN_PATTERNS_FOR_PARSING + ')$', 'i');
// Regular expression of viable phone numbers. This is location independent.

@@ -78,5 +120,4 @@ // Checks we have at least three leading digits, and only valid punctuation,

'^' + VALID_PHONE_NUMBER +
// screw phone number extensions
// '(?:' + EXTN_PATTERNS_FOR_PARSING + ')?' +
'$', 'i');
// Phone number extensions
'(?:' + EXTN_PATTERNS_FOR_PARSING + ')?' + '$', 'i');

@@ -138,18 +179,4 @@ // This consists of the plus symbol, digits, and arabic-indic digits.

'\u06F9': '9' // Eastern-Arabic digit 9
};
// The maximum length of the country calling code.
};var MAX_LENGTH_COUNTRY_CODE = 3;
// The minimum length of the national significant number.
var MIN_LENGTH_FOR_NSN = 2;
// The ITU says the maximum length should be 15,
// but one can find longer numbers in Germany.
var MAX_LENGTH_FOR_NSN = 17;
// We don't allow input strings for parsing to be longer than 250 chars.
// This prevents malicious input from consuming CPU.
var MAX_INPUT_STRING_LENGTH = 250;
var default_options = {

@@ -215,2 +242,13 @@ country: {}

// Attempt to parse extension first, since it doesn't require region-specific
// data and we want to have the non-normalised number here.
var _strip_extension = strip_extension(formatted_phone_number),
number_without_extension = _strip_extension.number,
extension = _strip_extension.extension;
if (extension !== undefined) {
formatted_phone_number = number_without_extension;
}
var _parse_phone_number_a = parse_phone_number_and_country_phone_code(formatted_phone_number, metadata),

@@ -259,3 +297,3 @@ country_phone_code = _parse_phone_number_a.country_phone_code,

number = normalize(text);
number = normalize(formatted_phone_number);
}

@@ -335,3 +373,12 @@

return { country: country, phone: national_number };
var result = {
country: country,
phone: national_number
};
if (extension) {
result.ext = extension;
}
return result;
}

@@ -653,2 +700,32 @@

}
// Strips any extension (as in, the part of the number dialled after the call is
// connected, usually indicated with extn, ext, x or similar) from the end of
// the number, and returns it.
function strip_extension(number) {
var start = number.search(EXTN_PATTERN);
if (start < 0) {
return {};
}
// If we find a potential extension, and the number preceding this is a viable
// number, we assume it is an extension.
var number_without_extension = number.slice(0, start);
/* istanbul ignore if - seems a bit of a redundant check */
if (!is_viable_phone_number(number_without_extension)) {
return {};
}
var matches = number.match(EXTN_PATTERN);
var i = 1;
while (i < matches.length) {
if (matches[i] != null && matches[i].length > 0) {
return {
number: number_without_extension,
extension: matches[i]
};
}
i++;
}
}
//# sourceMappingURL=parse.js.map

@@ -6,3 +6,3 @@ import _Object$keys from 'babel-runtime/core-js/object/keys';

import { DIGIT_PLACEHOLDER } from '../as you type';
import { DIGIT_PLACEHOLDER } from '../AsYouType';

@@ -78,3 +78,3 @@ var phone_number_types = ['premium_rate', 'toll_free', 'shared_cost', 'voip', 'personal_number', 'pager', 'uan', 'voice_mail', 'fixed_line', 'mobile'];

// {
// '+7': ['RU', 'KZ', ...],
// '7': ['RU', 'KZ', ...],
// ...

@@ -114,2 +114,30 @@ // },

// }
//
// `country_phone_code_to_countries` map is kinda redundant.
// Not sure why did I choose to place country phone codes
// into a separate structure inside metadata instead of generating it in runtime.
// One extra feature it gives though is it tells what's the
// "default" country for a given country phone code.
// E.g. for country phone code `1` the "default" country is "US"
// and therefore "US" is the first country code in the
// `country_phone_code_to_countries["1"]` list.
// The "default" country is the one holding metadata for a country phone code
// so, for example, when "CA" (Canada) country is chosen
// then it uses the metadata for the "default" country ("US").
//
// `country_phone_code_to_countries` data takes about 3 KiloBytes
// so it could kinda make sense to drop it from the metadata file
// replacing it with a "default" country flag (something like `1` for "yes").
// In that scenario `country_phone_code_to_countries` would be generated on startup.
// It would have to also provide an exported `getCountryPhoneCodes()` function
// which would take `metadata` and return `country_phone_code_to_countries` map
// because some people use that `country_phone_code_to_countries` map in their projects.
//
// On the other hand, having `country_phone_code_to_countries`
// prepopulated yields more elegance to the exports
// because if `country_phone_code_to_countries` wasn't part of metadata
// it would have to be computed somewhere in global scope
// therefore the modules wouldn't be strictly "pure"
// so maybe `country_phone_code_to_countries` stays as part of metadata.
//
export default function (input, included_countries, extended, included_phone_number_types) {

@@ -439,3 +467,3 @@ // Validate `included_phone_number_types`

//
// This inncreases metadata size by 5 KiloBytes.
// This increases metadata size by 5 KiloBytes.
//

@@ -442,0 +470,0 @@ } catch (err) {

import parse, { is_viable_phone_number } from './parse';
import get_number_type, { sort_out_arguments } from './get number type';
import get_number_type, { sort_out_arguments } from './getNumberType';

@@ -4,0 +4,0 @@ import { get_types } from './metadata';

@@ -22,3 +22,3 @@ 'use strict'

exports.get_number_type = function get_number_type()
exports.getNumberType = function getNumberType()
{

@@ -30,3 +30,3 @@ var parameters = Array.prototype.slice.call(arguments)

exports.is_valid_number = function is_valid_number()
exports.isValidNumber = function isValidNumber()
{

@@ -38,9 +38,9 @@ var parameters = Array.prototype.slice.call(arguments)

exports.as_you_type = function as_you_type(country)
exports.AsYouType = function AsYouType(country)
{
custom.asYouType.call(this, country, metadata)
custom.AsYouType.call(this, country, metadata)
}
exports.as_you_type.prototype = Object.create(custom.asYouType.prototype, {})
exports.as_you_type.prototype.constructor = exports.as_you_type
exports.AsYouType.prototype = Object.create(custom.AsYouType.prototype, {})
exports.AsYouType.prototype.constructor = exports.AsYouType

@@ -51,5 +51,10 @@ exports.DIGIT_PLACEHOLDER = custom.DIGIT_PLACEHOLDER

// camelCase aliases
exports.getNumberType = exports.get_number_type
exports.isValidNumber = exports.is_valid_number
exports.asYouType = exports.as_you_type
// `get_number_type` name is deprecated
exports.get_number_type = exports.getNumberType
// `is_valid_number` name is deprecated
exports.is_valid_number = exports.isValidNumber
// `as_you_type` name is deprecated
exports.as_you_type = exports.AsYouType
// `asYouType` name is deprecated
exports.asYouType = exports.AsYouType

@@ -56,0 +61,0 @@ exports.getPhoneCode = function(country)

@@ -14,4 +14,4 @@

export function format(parsed_number: ParsedNumber, format: 'International' | 'International_plaintext' | 'National'): string;
export function format(phone: TelephoneNumber, country: CountryCode, format: 'International' | 'International_plaintext' | 'National'): string;
export function format(parsed_number: ParsedNumber, format: 'International' | 'International_plaintext' | 'E.164' | 'National'): string;
export function format(phone: TelephoneNumber, country: CountryCode, format: 'International' | 'International_plaintext' | 'E.164' | 'National'): string;

@@ -28,2 +28,3 @@ export function getNumberType(parsed_number: ParsedNumber): string;

// `asYouType` name is deprecated
export class asYouType {

@@ -38,1 +39,11 @@ constructor(default_country_code?: CountryCode);

}
export class AsYouType {
constructor(default_country_code?: CountryCode);
input(text: string): string;
reset(): void;
country: CountryCode;
country_phone_code: PhoneCode;
national_number: string;
template: string;
}
import metadata from './metadata.min.json'
import parseCustom from './es6/parse'
import getNumberTypeCustom from './es6/get number type'
import getNumberTypeCustom from './es6/getNumberType'
import formatCustom from './es6/format'
import isValidNumberCustom from './es6/validate'
import asYouTypeCustom from './es6/as you type'
import AsYouTypeCustom from './es6/AsYouType'

@@ -25,3 +25,3 @@ import { get_phone_code } from './es6/metadata'

export function get_number_type()
export function getNumberType()
{

@@ -33,9 +33,9 @@ var parameters = Array.prototype.slice.call(arguments)

// camelCase alias
export function getNumberType()
// `get_number_type` name is deprecated
export function get_number_type()
{
return get_number_type.apply(this, arguments)
return getNumberType.apply(this, arguments)
}
export function is_valid_number()
export function isValidNumber()
{

@@ -47,24 +47,32 @@ var parameters = Array.prototype.slice.call(arguments)

// camelCase alias
export function isValidNumber()
// `is_valid_number` name is deprecated
export function is_valid_number()
{
return is_valid_number.apply(this, arguments)
return isValidNumber.apply(this, arguments)
}
export function AsYouType(country)
{
AsYouTypeCustom.call(this, country, metadata)
}
AsYouType.prototype = Object.create(AsYouTypeCustom.prototype, {})
AsYouType.prototype.constructor = AsYouType
// `as_you_type` name is deprecated
export function as_you_type(country)
{
asYouTypeCustom.call(this, country, metadata)
AsYouTypeCustom.call(this, country, metadata)
}
as_you_type.prototype = Object.create(asYouTypeCustom.prototype, {})
as_you_type.prototype = Object.create(AsYouTypeCustom.prototype, {})
as_you_type.prototype.constructor = as_you_type
// camelCase alias
// `asYouType` name is deprecated
export function asYouType(country)
{
asYouTypeCustom.call(this, country, metadata)
AsYouTypeCustom.call(this, country, metadata)
}
asYouType.prototype = Object.create(asYouTypeCustom.prototype, {})
asYouType.prototype = Object.create(AsYouTypeCustom.prototype, {})
asYouType.prototype.constructor = asYouType

@@ -81,10 +89,12 @@

export { default as isValidNumberCustom } from './es6/validate'
export { default as getNumberTypeCustom } from './es6/get number type'
export { default as getNumberTypeCustom } from './es6/getNumberType'
export
{
default as AsYouTypeCustom,
// `asYouTypeCustom` name is deprecated
default as asYouTypeCustom,
DIGIT_PLACEHOLDER
}
from './es6/as you type'
from './es6/AsYouType'

@@ -91,0 +101,0 @@ export function getPhoneCode(country)

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

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

"chai": "^3.5.0",
"crlf": "^1.1.1",
"istanbul": "^1.1.0-alpha.1",

@@ -54,3 +55,3 @@ "json-loader": "^0.5.4",

"build": "npm-run-all clean-for-build build-commonjs-modules build-es6-modules",
"prepublish": "npm-run-all build test browser-build"
"prepublish": "crlf --set=LF bin/* && npm-run-all build test browser-build"
},

@@ -57,0 +58,0 @@ "betterScripts": {

@@ -27,3 +27,2 @@ # libphonenumber-js

* Assumes all phone numbers being `format`ted are internationally diallable, because that's the only type of phone numbers users are supposed to be inputting on websites (no one inputs short codes, emergency telephone numbers like `911`, etc.)
* Doesn't parse phone numbers with extensions (again, this is not the type of phone numbers users should input on websites — they're supposed to input their personal mobile phone numbers, or home stationary phone numbers if they're living in an area where celltowers don't have a good signal, not their business/enterprise stationary phone numbers)
* Doesn't use `possibleDigits` data to speed up phone number pre-validation (it just skips to the regular expression check itself)

@@ -44,3 +43,3 @@ * Doesn't distinguish between fixed line, mobile, pager, voicemail, toll free and other XXth century bullsh*t

```js
import { parse, format, asYouType } from 'libphonenumber-js'
import { parse, format, AsYouType } from 'libphonenumber-js'

@@ -53,5 +52,5 @@ parse('8 (800) 555 35 35', 'RU')

new asYouType().input('+12133734')
new AsYouType().input('+12133734')
// '+1 213 373 4'
new asYouType('US').input('2133734')
new AsYouType('US').input('2133734')
// '(213) 373-4'

@@ -84,5 +83,6 @@ ```

Returns `{ country, phone }` where
Returns `{ country, phone, ext }` where
* `country` is a [country code](https://github.com/catamphetamine/libphonenumber-js#country-code-definition)
* `phone` is a national (significant) number
* `ext` is a phone number extension

@@ -94,12 +94,18 @@ If the phone number supplied isn't valid then an empty object `{}` is returned.

parse('(213) 373-4253', 'US') === { country: 'US', phone: '2133734253' }
// Supports phone number extensions
parse('(213) 373-4253 ext. 123', 'US') === { country: 'US', phone: '2133734253', ext: '123' }
```
### format(parsed_number, format)
Speaking of phone number extensions, I myself consider them obsolete and I'd just discard the extension part given we're in XXI-st century. Still, some people [asked](https://github.com/catamphetamine/libphonenumber-js/issues/129) for phone number extensions support so it has been added. But I personally think it's an unnecessary complication.
### format(parsedNumber, format)
Formats a phone number using one of the following `format`s:
* `National` — e.g. `(213) 373-4253`
* `International` — e.g. `+1 213 373 4253`
* `International_plaintext` — (aka [`E.164`](https://en.wikipedia.org/wiki/E.164)) e.g. `+12133734253`
* `National` — e.g. `(213) 373-4253`
* [`E.164`](https://en.wikipedia.org/wiki/E.164) — e.g. `+12133734253`
* [`RFC3966`](https://www.ietf.org/rfc/rfc3966.txt) (the phone number URI) — e.g. `tel:+12133734253;ext=123`
`parsed_number` argument **must** be an already `parse()`d phone number (to strip national prefix from it). That means that first a phone number is `parse()`d and only then is it `format()`ted and there's no other way around it. For example, a phone number is `parse()`d before storing it in a database and then it is `forrmat()`ted each time it is read from the database. The `parsed_number` object argument can also be expanded into two string arguments (for those who prefer this kind of syntax):
`parsedNumber` argument **must** be an already `parse()`d phone number (to strip national prefix from it). That means that first a phone number is `parse()`d and only then is it `format()`ted and there's no other way around it. For example, a phone number is `parse()`d before storing it in a database and then it is `forrmat()`ted each time it is read from the database. The `parsedNumber` object argument can also be expanded into two string arguments (for those who prefer this kind of syntax):

@@ -112,6 +118,9 @@ ```js

// (has not been parsed previously and therefore contains the `0` national prefix)
format('017212345678', 'DE', 'International_plaintext') !== '+4917212345678'
format('017212345678', 'DE', 'E.164') !== '+4917212345678'
// Supports phone number extensions (except for E.164).
format({ country: 'US', phone: '2133734253', ext: '123' }, 'National') === '(213) 373-4253 ext. 123'
```
### getNumberType(parsed_number)
### getNumberType(parsedNumber)

@@ -129,6 +138,4 @@ Determines phone number type (fixed line, mobile, toll free, etc). This function will work if `--extended` (or relevant `--types`) metadata is available (see [Metadata](#metadata) section of this document). The regular expressions used to differentiate between various phone number types consume a lot of space (two thirds of the total size of the `--extended` library build) therefore they're not included in the bundle by default.

### isValidNumber(parsed_number)
### isValidNumber(parsedNumber)
(aka `is_valid_number`)
Checks if a phone number is valid.

@@ -169,6 +176,4 @@

### `class` asYouType(default_country_code)
### `class` AsYouType(default_country_code)
(aka `as_you_type`)
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:

@@ -189,6 +194,6 @@

```js
new asYouType().input('+12133734') === '+1 213 373 4'
new asYouType('US').input('2133734') === '(213) 373-4'
new AsYouType().input('+12133734') === '+1 213 373 4'
new AsYouType('US').input('2133734') === '(213) 373-4'
const formatter = new asYouType()
const formatter = new AsYouType()
formatter.input('+1-213-373-4253') === '+1 213 373 4253'

@@ -200,2 +205,4 @@ formatter.country === 'US'

Does not support phone number extensions (same as Google's original library).
### getPhoneCode(country_code)

@@ -239,8 +246,6 @@

If any inconsistencies with the [original Google's `libphonenumber`](https://libphonenumber.appspot.com/) are found then an issue can be reported in this repo.
When reporting an issue one must also provide a link to [Google's `libphonenumber` demo page](https://libphonenumber.appspot.com/) illustrating the expected behaviour. This includes validation, parsing, formatting and "as you type" formatting. For example, for an Australian number `438 331 999` Google's demo [outputs four sections](https://libphonenumber.appspot.com/phonenumberparser?number=438331999&country=AU) — "Parsing Result", "Validation Results", "Formatting Results" and "AsYouTypeFormatter Results". In a bug report, first describe the observed `libphonenumber-js` demo result and then Google's demo result (with a link to it) which must differ from the observed `libphonenumber-js` demo result. If the observed `libphonenumber-js` demo result is the same as Google's demo result and you don't agree with Google's demo result then create an issue in [Google's repo](https://github.com/googlei18n/libphonenumber).
When reporting an issue one must also provide a link to [Google's `libphonenumber` demo page](https://libphonenumber.appspot.com/) illustrating the expected behaviour.
Phone number validation bugs should **only** be reported if they appear when using [custom metadata functions](#customizing-metadata) fed with `metadata.full.json` because by default all functions in this library use the reduced metadata set which results in looser validation than the original Google `libphonenumber`'s. The [demo page](https://catamphetamine.github.io/libphonenumber-js/) also uses the reduced metadata set and therefore its validation is also looser than the original Google `libphonenumber`'s.
Phone number validation bugs should **only** be reported if they appear when using [custom metadata functions](#customizing-metadata) fed with `metadata.full.json` because by default all functions in this library use the reduced metadata set which results in looser validation than the original Google `libphonenumber`'s. The [demo page](https://catamphetamine.github.io/libphonenumber-js/) also uses the reduced metadata set and therefore its validation is also looser than the original Google `libphonenumber`'s. That being said, it's very unlikely that any phone number validation inconsistencies could even exist. This paragraph is here just to prevent people from reporting "validation inconsistency" issues.
## TypeScript

@@ -272,3 +277,3 @@

<script>
alert(new libphonenumber.asYouType('US').input('213-373-4253'))
alert(new libphonenumber.AsYouType('US').input('213-373-4253'))
</script>

@@ -315,3 +320,3 @@ ```

isValidNumberCustom,
asYouTypeCustom,
AsYouTypeCustom,
getNumberTypeCustom

@@ -327,3 +332,3 @@ } from 'libphonenumber-js'

export class asYouType extends asYouTypeCustom {
export class AsYouType extends AsYouTypeCustom {
constructor(country) {

@@ -365,9 +370,8 @@ super(country, metadata)

exports.asYouType = function asYouType(country) {
custom.asYouType.call(this, country, metadata)
exports.AsYouType = function AsYouType(country) {
custom.AsYouType.call(this, country, metadata)
}
exports.asYouType.prototype = Object.create(custom.asYouType.prototype, {})
exports.asYouType.prototype.constructor = exports.asYouType
exports.AsYouType.prototype = Object.create(custom.AsYouType.prototype, {})
exports.AsYouType.prototype.constructor = exports.AsYouType
```

@@ -477,4 +481,8 @@

## Advertisement
If you're looking for an international "2 days ago" javascript solution then check out [`javascript-time-ago`](https://github.com/catamphetamine/javascript-time-ago).
## License
[MIT](LICENSE)

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 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

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

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