libphonenumber-js 1.10.45 → 1.10.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -2
- package/build/AsYouType.js +5 -3
- package/build/AsYouType.js.map +1 -1
- package/build/formatIncompletePhoneNumber.js +5 -5
- package/build/formatIncompletePhoneNumber.js.map +1 -1
- package/build/formatIncompletePhoneNumber.test.js +8 -0
- package/build/formatIncompletePhoneNumber.test.js.map +1 -1
- package/build/helpers/getNumberType.js +4 -3
- package/build/helpers/getNumberType.js.map +1 -1
- package/build/helpers/getNumberType.test.js +5 -0
- package/build/helpers/getNumberType.test.js.map +1 -1
- package/build/helpers/isObject.js +12 -0
- package/build/helpers/isObject.js.map +1 -0
- package/build/isValid.test.js +3 -0
- package/build/isValid.test.js.map +1 -1
- package/build/legacy/format.js +4 -12
- package/build/legacy/format.js.map +1 -1
- package/build/legacy/getNumberType.js +5 -13
- package/build/legacy/getNumberType.js.map +1 -1
- package/build/metadata.js +5 -11
- package/build/metadata.js.map +1 -1
- package/build/normalizeArguments.js +5 -10
- package/build/normalizeArguments.js.map +1 -1
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/core/index.d.cts +1 -1
- package/core/index.d.ts +1 -1
- package/custom.d.ts +1 -1
- package/es6/AsYouType.js +2 -3
- package/es6/AsYouType.js.map +1 -1
- package/es6/formatIncompletePhoneNumber.js +5 -5
- package/es6/formatIncompletePhoneNumber.js.map +1 -1
- package/es6/formatIncompletePhoneNumber.test.js +8 -0
- package/es6/formatIncompletePhoneNumber.test.js.map +1 -1
- package/es6/helpers/getNumberType.js +4 -3
- package/es6/helpers/getNumberType.js.map +1 -1
- package/es6/helpers/getNumberType.test.js +5 -0
- package/es6/helpers/getNumberType.test.js.map +1 -1
- package/es6/helpers/isObject.js +5 -0
- package/es6/helpers/isObject.js.map +1 -0
- package/es6/isValid.test.js +3 -0
- package/es6/isValid.test.js.map +1 -1
- package/es6/legacy/format.js +3 -12
- package/es6/legacy/format.js.map +1 -1
- package/es6/legacy/getNumberType.js +4 -12
- package/es6/legacy/getNumberType.js.map +1 -1
- package/es6/metadata.js +5 -12
- package/es6/metadata.js.map +1 -1
- package/es6/normalizeArguments.js +3 -10
- package/es6/normalizeArguments.js.map +1 -1
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/max/index.d.cts +1 -1
- package/max/index.d.ts +1 -1
- package/metadata.full.json +1 -1
- package/metadata.full.json.js +1 -1
- package/metadata.max.json +1 -1
- package/metadata.max.json.js +1 -1
- package/metadata.min.json +1 -1
- package/metadata.min.json.js +1 -1
- package/metadata.mobile.json +1 -1
- package/metadata.mobile.json.js +1 -1
- package/min/index.d.cts +1 -1
- package/min/index.d.ts +1 -1
- package/mobile/index.d.cts +1 -1
- package/mobile/index.d.ts +1 -1
- package/package.json +1 -1
- package/source/AsYouType.js +2 -1
- package/source/formatIncompletePhoneNumber.js +5 -5
- package/source/formatIncompletePhoneNumber.test.js +5 -0
- package/source/helpers/getNumberType.js +4 -3
- package/source/helpers/getNumberType.test.js +8 -0
- package/source/helpers/isObject.js +5 -0
- package/source/isValid.test.js +4 -0
- package/source/legacy/format.js +3 -7
- package/source/legacy/getNumberType.js +4 -8
- package/source/metadata.js +4 -8
- package/source/normalizeArguments.js +3 -5
package/min/index.d.cts
CHANGED
|
@@ -75,7 +75,7 @@ export function getExtPrefix(countryCode: CountryCode): string;
|
|
|
75
75
|
|
|
76
76
|
export function getExampleNumber(country: CountryCode, examples: Examples): PhoneNumber | undefined;
|
|
77
77
|
|
|
78
|
-
export function formatIncompletePhoneNumber(number: string,
|
|
78
|
+
export function formatIncompletePhoneNumber(number: string, defaultCountryCode?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): string;
|
|
79
79
|
export function parseIncompletePhoneNumber(text: string): string;
|
|
80
80
|
export function parsePhoneNumberCharacter(character: string): string;
|
|
81
81
|
export function parseDigits(character: string): string;
|
package/min/index.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export function getExtPrefix(countryCode: CountryCode): string;
|
|
|
75
75
|
|
|
76
76
|
export function getExampleNumber(country: CountryCode, examples: Examples): PhoneNumber | undefined;
|
|
77
77
|
|
|
78
|
-
export function formatIncompletePhoneNumber(number: string,
|
|
78
|
+
export function formatIncompletePhoneNumber(number: string, defaultCountryCode?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): string;
|
|
79
79
|
export function parseIncompletePhoneNumber(text: string): string;
|
|
80
80
|
export function parsePhoneNumberCharacter(character: string): string;
|
|
81
81
|
export function parseDigits(character: string): string;
|
package/mobile/index.d.cts
CHANGED
|
@@ -75,7 +75,7 @@ export function getExtPrefix(countryCode: CountryCode): string;
|
|
|
75
75
|
|
|
76
76
|
export function getExampleNumber(country: CountryCode, examples: Examples): PhoneNumber | undefined;
|
|
77
77
|
|
|
78
|
-
export function formatIncompletePhoneNumber(number: string,
|
|
78
|
+
export function formatIncompletePhoneNumber(number: string, defaultCountryCode?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): string;
|
|
79
79
|
export function parseIncompletePhoneNumber(text: string): string;
|
|
80
80
|
export function parsePhoneNumberCharacter(character: string): string;
|
|
81
81
|
export function parseDigits(character: string): string;
|
package/mobile/index.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export function getExtPrefix(countryCode: CountryCode): string;
|
|
|
75
75
|
|
|
76
76
|
export function getExampleNumber(country: CountryCode, examples: Examples): PhoneNumber | undefined;
|
|
77
77
|
|
|
78
|
-
export function formatIncompletePhoneNumber(number: string,
|
|
78
|
+
export function formatIncompletePhoneNumber(number: string, defaultCountryCode?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): string;
|
|
79
79
|
export function parseIncompletePhoneNumber(text: string): string;
|
|
80
80
|
export function parsePhoneNumberCharacter(character: string): string;
|
|
81
81
|
export function parseDigits(character: string): string;
|
package/package.json
CHANGED
package/source/AsYouType.js
CHANGED
|
@@ -5,6 +5,7 @@ import AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.js'
|
|
|
5
5
|
import AsYouTypeParser, { extractFormattedDigitsAndPlus } from './AsYouTypeParser.js'
|
|
6
6
|
import getCountryByCallingCode from './helpers/getCountryByCallingCode.js'
|
|
7
7
|
import getCountryByNationalNumber from './helpers/getCountryByNationalNumber.js'
|
|
8
|
+
import isObject from './helpers/isObject.js'
|
|
8
9
|
|
|
9
10
|
const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
|
|
10
11
|
|
|
@@ -30,7 +31,7 @@ export default class AsYouType {
|
|
|
30
31
|
let defaultCallingCode
|
|
31
32
|
// Turns out `null` also has type "object". Weird.
|
|
32
33
|
if (optionsOrDefaultCountry) {
|
|
33
|
-
if (
|
|
34
|
+
if (isObject(optionsOrDefaultCountry)) {
|
|
34
35
|
defaultCountry = optionsOrDefaultCountry.defaultCountry
|
|
35
36
|
defaultCallingCode = optionsOrDefaultCountry.defaultCallingCode
|
|
36
37
|
} else {
|
|
@@ -5,13 +5,13 @@ import AsYouType from './AsYouType.js'
|
|
|
5
5
|
* The phone number can be either in E.164 format
|
|
6
6
|
* or in a form of national number digits.
|
|
7
7
|
* @param {string} value - A possibly incomplete phone number. Either in E.164 format or in a form of national number digits.
|
|
8
|
-
* @param {string
|
|
8
|
+
* @param {string|object} [optionsOrDefaultCountry] - A two-letter ("ISO 3166-1 alpha-2") country code, or an object of shape `{ defaultCountry?: string, defaultCallingCode?: string }`.
|
|
9
9
|
* @return {string} Formatted (possibly incomplete) phone number.
|
|
10
10
|
*/
|
|
11
|
-
export default function formatIncompletePhoneNumber(value,
|
|
11
|
+
export default function formatIncompletePhoneNumber(value, optionsOrDefaultCountry, metadata) {
|
|
12
12
|
if (!metadata) {
|
|
13
|
-
metadata =
|
|
14
|
-
|
|
13
|
+
metadata = optionsOrDefaultCountry
|
|
14
|
+
optionsOrDefaultCountry = undefined
|
|
15
15
|
}
|
|
16
|
-
return new AsYouType(
|
|
16
|
+
return new AsYouType(optionsOrDefaultCountry, metadata).input(value)
|
|
17
17
|
}
|
|
@@ -18,4 +18,9 @@ describe('formatIncompletePhoneNumber', () => {
|
|
|
18
18
|
// International input, with country.
|
|
19
19
|
formatIncompletePhoneNumber('+780055535', 'RU', metadata).should.equal('+7 800 555 35')
|
|
20
20
|
})
|
|
21
|
+
|
|
22
|
+
it('should support an object argument', () => {
|
|
23
|
+
formatIncompletePhoneNumber('880055535', { defaultCountry: 'RU' }, metadata).should.equal('8 (800) 555-35')
|
|
24
|
+
formatIncompletePhoneNumber('880055535', { defaultCallingCode: '7' }, metadata).should.equal('8 (800) 555-35')
|
|
25
|
+
})
|
|
21
26
|
})
|
|
@@ -20,9 +20,10 @@ export default function getNumberType(input, options, metadata)
|
|
|
20
20
|
// code coverage would decrease for some weird reason.
|
|
21
21
|
options = options || {}
|
|
22
22
|
|
|
23
|
-
// When `parse()`
|
|
24
|
-
//
|
|
25
|
-
|
|
23
|
+
// When `parse()` returns an empty object — `{}` —
|
|
24
|
+
// that means that the phone number is malformed,
|
|
25
|
+
// so it can't possibly be valid.
|
|
26
|
+
if (!input.country && !input.countryCallingCode) {
|
|
26
27
|
return
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -15,4 +15,12 @@ describe('getNumberType', function() {
|
|
|
15
15
|
oldMetadata
|
|
16
16
|
).should.equal('FIXED_LINE_OR_MOBILE')
|
|
17
17
|
})
|
|
18
|
+
|
|
19
|
+
it('should return `undefined` when the phone number is a malformed one', function() {
|
|
20
|
+
expect(getNumberType(
|
|
21
|
+
{},
|
|
22
|
+
{ v2: true },
|
|
23
|
+
oldMetadata
|
|
24
|
+
)).to.equal(undefined)
|
|
25
|
+
})
|
|
18
26
|
})
|
package/source/isValid.test.js
CHANGED
|
@@ -113,4 +113,8 @@ describe('validate', () => {
|
|
|
113
113
|
// National
|
|
114
114
|
isValidNumber('88005553535 x123', { defaultCountry: 'RU' }).should.equal(true)
|
|
115
115
|
})
|
|
116
|
+
|
|
117
|
+
it('should validate non-geographic toll-free phone numbers', () => {
|
|
118
|
+
isValidNumber('+80074454123').should.equal(true)
|
|
119
|
+
})
|
|
116
120
|
})
|
package/source/legacy/format.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _formatNumber from '../format.js'
|
|
2
2
|
import parse from '../parse.js'
|
|
3
|
+
import isObject from '../helpers/isObject.js'
|
|
3
4
|
|
|
4
5
|
export default function formatNumber() {
|
|
5
6
|
const {
|
|
@@ -72,7 +73,7 @@ function normalizeArguments(args)
|
|
|
72
73
|
}
|
|
73
74
|
// If the phone number is passed as a parsed number object.
|
|
74
75
|
// `format({ phone: '8005553535', country: 'RU' }, 'NATIONAL', [options], metadata)`.
|
|
75
|
-
else if (
|
|
76
|
+
else if (isObject(arg_1))
|
|
76
77
|
{
|
|
77
78
|
input = arg_1
|
|
78
79
|
format = arg_2
|
|
@@ -102,9 +103,4 @@ function normalizeArguments(args)
|
|
|
102
103
|
options,
|
|
103
104
|
metadata
|
|
104
105
|
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Babel transforms `typeof` into some "branches"
|
|
108
|
-
// so istanbul will show this as "branch not covered".
|
|
109
|
-
/* istanbul ignore next */
|
|
110
|
-
const is_object = _ => typeof _ === 'object'
|
|
106
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import isViablePhoneNumber from '../helpers/isViablePhoneNumber.js'
|
|
2
2
|
import _getNumberType from '../helpers/getNumberType.js'
|
|
3
|
+
import isObject from '../helpers/isObject.js'
|
|
3
4
|
import parse from '../parse.js'
|
|
4
5
|
|
|
5
6
|
// Finds out national phone number type (fixed line, mobile, etc)
|
|
@@ -28,7 +29,7 @@ export function normalizeArguments(args)
|
|
|
28
29
|
// If "default country" argument is being passed
|
|
29
30
|
// then convert it to an `options` object.
|
|
30
31
|
// `getNumberType('88005553535', 'RU', metadata)`.
|
|
31
|
-
if (
|
|
32
|
+
if (!isObject(arg_2))
|
|
32
33
|
{
|
|
33
34
|
if (arg_4)
|
|
34
35
|
{
|
|
@@ -86,7 +87,7 @@ export function normalizeArguments(args)
|
|
|
86
87
|
}
|
|
87
88
|
// If the phone number is passed as a parsed phone number.
|
|
88
89
|
// `getNumberType({ phone: '88005553535', country: 'RU' }, ...)`.
|
|
89
|
-
else if (
|
|
90
|
+
else if (isObject(arg_1))
|
|
90
91
|
{
|
|
91
92
|
input = arg_1
|
|
92
93
|
|
|
@@ -107,9 +108,4 @@ export function normalizeArguments(args)
|
|
|
107
108
|
options,
|
|
108
109
|
metadata
|
|
109
110
|
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Babel transforms `typeof` into some "branches"
|
|
113
|
-
// so istanbul will show this as "branch not covered".
|
|
114
|
-
/* istanbul ignore next */
|
|
115
|
-
const is_object = _ => typeof _ === 'object'
|
|
111
|
+
}
|
package/source/metadata.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import compare from './tools/semver-compare.js'
|
|
2
|
+
import isObject from './helpers/isObject.js'
|
|
2
3
|
|
|
3
4
|
// Added "possibleLengths" and renamed
|
|
4
5
|
// "country_phone_code_to_countries" to "country_calling_codes".
|
|
@@ -458,20 +459,15 @@ export function validateMetadata(metadata) {
|
|
|
458
459
|
|
|
459
460
|
// `country_phone_code_to_countries` was renamed to
|
|
460
461
|
// `country_calling_codes` in `1.0.18`.
|
|
461
|
-
if (!
|
|
462
|
-
throw new Error(`[libphonenumber-js] \`metadata\` argument was passed but it's not a valid metadata. Must be an object having \`.countries\` child object property. Got ${
|
|
462
|
+
if (!isObject(metadata) || !isObject(metadata.countries)) {
|
|
463
|
+
throw new Error(`[libphonenumber-js] \`metadata\` argument was passed but it's not a valid metadata. Must be an object having \`.countries\` child object property. Got ${isObject(metadata) ? 'an object of shape: { ' + Object.keys(metadata).join(', ') + ' }' : 'a ' + typeOf(metadata) + ': ' + metadata}.`)
|
|
463
464
|
}
|
|
464
465
|
}
|
|
465
466
|
|
|
466
467
|
// Babel transforms `typeof` into some "branches"
|
|
467
468
|
// so istanbul will show this as "branch not covered".
|
|
468
469
|
/* istanbul ignore next */
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
// Babel transforms `typeof` into some "branches"
|
|
472
|
-
// so istanbul will show this as "branch not covered".
|
|
473
|
-
/* istanbul ignore next */
|
|
474
|
-
const type_of = _ => typeof _
|
|
470
|
+
const typeOf = _ => typeof _
|
|
475
471
|
|
|
476
472
|
/**
|
|
477
473
|
* Returns extension prefix for a country.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import isObject from './helpers/isObject.js'
|
|
2
|
+
|
|
1
3
|
// Extracts the following properties from function arguments:
|
|
2
4
|
// * input `text`
|
|
3
5
|
// * `options` object
|
|
@@ -50,8 +52,4 @@ export default function normalizeArguments(args) {
|
|
|
50
52
|
options,
|
|
51
53
|
metadata
|
|
52
54
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Otherwise istanbul would show this as "branch not covered".
|
|
56
|
-
/* istanbul ignore next */
|
|
57
|
-
const isObject = _ => typeof _ === 'object'
|
|
55
|
+
}
|