libphonenumber-js 1.13.2 → 1.13.4
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/.gitlab-ci.yml +24 -9
- package/CHANGELOG.md +15 -2
- package/README.md +29 -21
- package/build/AsYouType.js +100 -27
- package/build/AsYouType.js.map +1 -1
- package/build/AsYouType.test.js.map +1 -1
- package/build/AsYouTypeFormatter.complete.js +2 -2
- package/build/AsYouTypeFormatter.complete.js.map +1 -1
- package/build/AsYouTypeFormatter.js +1 -1
- package/build/AsYouTypeFormatter.js.map +1 -1
- package/build/AsYouTypeState.js +15 -1
- package/build/AsYouTypeState.js.map +1 -1
- package/build/PhoneNumber.js +26 -39
- package/build/PhoneNumber.js.map +1 -1
- package/build/format.js +3 -3
- package/build/format.js.map +1 -1
- package/build/formatPhoneNumberForMobileDialing.js +4 -3
- package/build/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/build/helpers/checkNumberLength.js +21 -6
- package/build/helpers/checkNumberLength.js.map +1 -1
- package/build/helpers/checkNumberLength.test.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.js +16 -11
- package/build/helpers/extractCountryCallingCode.js.map +1 -1
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +21 -10
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -0
- package/build/helpers/extractNationalNumber.js +12 -3
- package/build/helpers/extractNationalNumber.js.map +1 -1
- package/build/helpers/extractNationalNumber.test.js.map +1 -1
- package/build/helpers/getCountryAndCallingCodeFromOneOfThem.js +35 -0
- package/build/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -0
- package/build/helpers/getCountryByCallingCode.js +10 -7
- package/build/helpers/getCountryByCallingCode.js.map +1 -1
- package/build/helpers/getCountryByNationalNumber.js +13 -9
- package/build/helpers/getCountryByNationalNumber.js.map +1 -1
- package/build/helpers/getIddPrefix.js +1 -1
- package/build/helpers/getIddPrefix.js.map +1 -1
- package/build/helpers/getNumberType.js +3 -3
- package/build/helpers/getNumberType.js.map +1 -1
- package/build/helpers/getPossibleCountriesForNumber.js +4 -7
- package/build/helpers/getPossibleCountriesForNumber.js.map +1 -1
- package/build/helpers/isCallingCode.js +11 -0
- package/build/helpers/isCallingCode.js.map +1 -0
- package/build/helpers/isCallingCode.test.js.map +1 -0
- package/build/helpers/isCountryCode.js +11 -0
- package/build/helpers/isCountryCode.js.map +1 -0
- package/build/helpers/isCountryCode.test.js.map +1 -0
- package/build/helpers/stripIddPrefix.js +9 -4
- package/build/helpers/stripIddPrefix.js.map +1 -1
- package/build/isPossible.js +14 -8
- package/build/isPossible.js.map +1 -1
- package/build/isValid.js +3 -3
- package/build/isValid.js.map +1 -1
- package/build/metadata.js +80 -31
- package/build/metadata.js.map +1 -1
- package/build/metadata.test.js.map +1 -1
- package/build/parse.js +36 -12
- package/build/parse.js.map +1 -1
- package/build/validatePhoneNumberLength.js +3 -3
- package/build/validatePhoneNumberLength.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 -0
- package/core/index.d.ts +1 -0
- package/custom.d.ts +3 -1
- package/es6/AsYouType.js +100 -27
- package/es6/AsYouType.js.map +1 -1
- package/es6/AsYouType.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.complete.js +2 -2
- package/es6/AsYouTypeFormatter.complete.js.map +1 -1
- package/es6/AsYouTypeFormatter.js +1 -1
- package/es6/AsYouTypeFormatter.js.map +1 -1
- package/es6/AsYouTypeState.js +15 -1
- package/es6/AsYouTypeState.js.map +1 -1
- package/es6/PhoneNumber.js +26 -39
- package/es6/PhoneNumber.js.map +1 -1
- package/es6/format.js +3 -3
- package/es6/format.js.map +1 -1
- package/es6/formatPhoneNumberForMobileDialing.js +4 -3
- package/es6/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/es6/helpers/checkNumberLength.js +22 -6
- package/es6/helpers/checkNumberLength.js.map +1 -1
- package/es6/helpers/checkNumberLength.test.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.js +16 -11
- package/es6/helpers/extractCountryCallingCode.js.map +1 -1
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +21 -10
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -0
- package/es6/helpers/extractNationalNumber.js +12 -3
- package/es6/helpers/extractNationalNumber.js.map +1 -1
- package/es6/helpers/extractNationalNumber.test.js.map +1 -1
- package/es6/helpers/getCountryAndCallingCodeFromOneOfThem.js +28 -0
- package/es6/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -0
- package/es6/helpers/getCountryByCallingCode.js +10 -7
- package/es6/helpers/getCountryByCallingCode.js.map +1 -1
- package/es6/helpers/getCountryByNationalNumber.js +13 -9
- package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
- package/es6/helpers/getIddPrefix.js +1 -1
- package/es6/helpers/getIddPrefix.js.map +1 -1
- package/es6/helpers/getNumberType.js +3 -3
- package/es6/helpers/getNumberType.js.map +1 -1
- package/es6/helpers/getPossibleCountriesForNumber.js +4 -7
- package/es6/helpers/getPossibleCountriesForNumber.js.map +1 -1
- package/es6/helpers/isCallingCode.js +5 -0
- package/es6/helpers/isCallingCode.js.map +1 -0
- package/es6/helpers/isCallingCode.test.js.map +1 -0
- package/es6/helpers/isCountryCode.js +5 -0
- package/es6/helpers/isCountryCode.js.map +1 -0
- package/es6/helpers/isCountryCode.test.js.map +1 -0
- package/es6/helpers/stripIddPrefix.js +9 -4
- package/es6/helpers/stripIddPrefix.js.map +1 -1
- package/es6/isPossible.js +14 -8
- package/es6/isPossible.js.map +1 -1
- package/es6/isValid.js +3 -3
- package/es6/isValid.js.map +1 -1
- package/es6/metadata.js +80 -31
- package/es6/metadata.js.map +1 -1
- package/es6/metadata.test.js.map +1 -1
- package/es6/parse.js +36 -12
- package/es6/parse.js.map +1 -1
- package/es6/validatePhoneNumberLength.js +3 -3
- package/es6/validatePhoneNumberLength.js.map +1 -1
- package/es6-modern/AsYouType.js +100 -26
- package/es6-modern/AsYouType.js.map +1 -1
- package/es6-modern/AsYouType.test.js.map +1 -1
- package/es6-modern/AsYouTypeFormatter.complete.js +2 -2
- package/es6-modern/AsYouTypeFormatter.complete.js.map +1 -1
- package/es6-modern/AsYouTypeFormatter.js +1 -1
- package/es6-modern/AsYouTypeFormatter.js.map +1 -1
- package/es6-modern/AsYouTypeState.js +15 -1
- package/es6-modern/AsYouTypeState.js.map +1 -1
- package/es6-modern/PhoneNumber.js +25 -36
- package/es6-modern/PhoneNumber.js.map +1 -1
- package/es6-modern/format.js +3 -3
- package/es6-modern/format.js.map +1 -1
- package/es6-modern/formatPhoneNumberForMobileDialing.js +4 -3
- package/es6-modern/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/es6-modern/helpers/checkNumberLength.js +22 -6
- package/es6-modern/helpers/checkNumberLength.js.map +1 -1
- package/es6-modern/helpers/checkNumberLength.test.js.map +1 -1
- package/es6-modern/helpers/extractCountryCallingCode.js +16 -11
- package/es6-modern/helpers/extractCountryCallingCode.js.map +1 -1
- package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +21 -10
- package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -0
- package/es6-modern/helpers/extractNationalNumber.js +12 -3
- package/es6-modern/helpers/extractNationalNumber.js.map +1 -1
- package/es6-modern/helpers/extractNationalNumber.test.js.map +1 -1
- package/es6-modern/helpers/getCountryAndCallingCodeFromOneOfThem.js +28 -0
- package/es6-modern/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -0
- package/es6-modern/helpers/getCountryByCallingCode.js +10 -7
- package/es6-modern/helpers/getCountryByCallingCode.js.map +1 -1
- package/es6-modern/helpers/getCountryByNationalNumber.js +13 -10
- package/es6-modern/helpers/getCountryByNationalNumber.js.map +1 -1
- package/es6-modern/helpers/getIddPrefix.js +1 -1
- package/es6-modern/helpers/getIddPrefix.js.map +1 -1
- package/es6-modern/helpers/getNumberType.js +3 -3
- package/es6-modern/helpers/getNumberType.js.map +1 -1
- package/es6-modern/helpers/getPossibleCountriesForNumber.js +4 -7
- package/es6-modern/helpers/getPossibleCountriesForNumber.js.map +1 -1
- package/es6-modern/helpers/isCallingCode.js +5 -0
- package/es6-modern/helpers/isCallingCode.js.map +1 -0
- package/es6-modern/helpers/isCallingCode.test.js.map +1 -0
- package/es6-modern/helpers/isCountryCode.js +5 -0
- package/es6-modern/helpers/isCountryCode.js.map +1 -0
- package/es6-modern/helpers/isCountryCode.test.js.map +1 -0
- package/es6-modern/helpers/stripIddPrefix.js +9 -4
- package/es6-modern/helpers/stripIddPrefix.js.map +1 -1
- package/es6-modern/isPossible.js +14 -8
- package/es6-modern/isPossible.js.map +1 -1
- package/es6-modern/isValid.js +3 -3
- package/es6-modern/isValid.js.map +1 -1
- package/es6-modern/metadata.js +78 -31
- package/es6-modern/metadata.js.map +1 -1
- package/es6-modern/metadata.test.js.map +1 -1
- package/es6-modern/parse.js +41 -12
- package/es6-modern/parse.js.map +1 -1
- package/es6-modern/validatePhoneNumberLength.js +3 -3
- package/es6-modern/validatePhoneNumberLength.js.map +1 -1
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/max/index.d.cts +1 -0
- package/max/index.d.ts +1 -0
- package/max/metadata/metadata.max.json +1 -1
- package/max/metadata/metadata.max.json.js +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 -0
- package/min/index.d.ts +1 -0
- package/min/metadata/metadata.min.json +1 -1
- package/min/metadata/metadata.min.json.js +1 -1
- package/mobile/index.d.cts +1 -0
- package/mobile/index.d.ts +1 -0
- package/mobile/metadata/metadata.mobile.json +1 -1
- package/mobile/metadata/metadata.mobile.json.js +1 -1
- package/package.json +1 -1
- package/source/AsYouType.js +108 -27
- package/source/AsYouTypeFormatter.complete.js +2 -2
- package/source/AsYouTypeFormatter.js +1 -1
- package/source/AsYouTypeState.js +15 -1
- package/source/PhoneNumber.js +24 -39
- package/source/format.js +3 -3
- package/source/formatPhoneNumberForMobileDialing.js +4 -3
- package/source/helpers/checkNumberLength.js +21 -6
- package/source/helpers/extractCountryCallingCode.js +16 -11
- package/source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +20 -10
- package/source/helpers/extractNationalNumber.js +11 -3
- package/source/helpers/getCountryAndCallingCodeFromOneOfThem.js +31 -0
- package/source/helpers/getCountryByCallingCode.js +10 -7
- package/source/helpers/getCountryByNationalNumber.js +14 -11
- package/source/helpers/getIddPrefix.js +1 -1
- package/source/helpers/getNumberType.js +3 -3
- package/source/helpers/getPossibleCountriesForNumber.js +4 -7
- package/source/helpers/isCallingCode.js +5 -0
- package/source/helpers/isCountryCode.js +5 -0
- package/source/helpers/stripIddPrefix.js +10 -4
- package/source/isPossible.js +13 -7
- package/source/isValid.js +3 -3
- package/source/metadata.js +77 -33
- package/source/parse.js +41 -11
- package/source/validatePhoneNumberLength.js +3 -3
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Metadata from '../metadata.js'
|
|
2
|
+
import isCountryCode from './isCountryCode.js'
|
|
3
|
+
|
|
4
|
+
const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
|
|
5
|
+
|
|
6
|
+
export default function getCountryAndCallingCodeFromOneOfThem(countryOrCallingCode, metadataJson) {
|
|
7
|
+
let country
|
|
8
|
+
let callingCode
|
|
9
|
+
|
|
10
|
+
const metadata = new Metadata(metadataJson)
|
|
11
|
+
// If country code is passed then derive `countryCallingCode` from it.
|
|
12
|
+
// Also store the country code as `.country`.
|
|
13
|
+
if (isCountryCode(countryOrCallingCode)) {
|
|
14
|
+
country = countryOrCallingCode
|
|
15
|
+
metadata.selectNumberingPlan(country)
|
|
16
|
+
callingCode = metadata.countryCallingCode()
|
|
17
|
+
} else {
|
|
18
|
+
callingCode = countryOrCallingCode
|
|
19
|
+
/* istanbul ignore if */
|
|
20
|
+
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
21
|
+
if (metadata.isNonGeographicCallingCode(callingCode)) {
|
|
22
|
+
country = '001'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
country,
|
|
29
|
+
callingCode
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -2,10 +2,16 @@ import getCountryByNationalNumber from './getCountryByNationalNumber.js'
|
|
|
2
2
|
|
|
3
3
|
const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Returns the exact country that a given national (significant) number belongs to
|
|
7
|
+
* in case of ambiguity, i.e. when multiple countries share the same "country calling code".
|
|
8
|
+
* @param {string} [callingCode]
|
|
9
|
+
* @param {string} [options.nationalNumber] — National (significant) number.
|
|
10
|
+
* @param {Metadata} options.metadata — Metadata instance.
|
|
11
|
+
* @returns {string?} Returns the most suitable country for this calling code and national (significant) number.
|
|
12
|
+
*/
|
|
7
13
|
export default function getCountryByCallingCode(callingCode, {
|
|
8
|
-
nationalNumber
|
|
14
|
+
nationalNumber,
|
|
9
15
|
metadata
|
|
10
16
|
}) {
|
|
11
17
|
/* istanbul ignore if */
|
|
@@ -23,8 +29,5 @@ export default function getCountryByCallingCode(callingCode, {
|
|
|
23
29
|
if (possibleCountries.length === 1) {
|
|
24
30
|
return possibleCountries[0]
|
|
25
31
|
}
|
|
26
|
-
return getCountryByNationalNumber(
|
|
27
|
-
countries: possibleCountries,
|
|
28
|
-
metadata: metadata.metadata
|
|
29
|
-
})
|
|
32
|
+
return getCountryByNationalNumber(nationalNumber, possibleCountries, metadata.metadata)
|
|
30
33
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import Metadata from '../metadata.js'
|
|
2
2
|
import getNumberType from './getNumberType.js'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Returns the exact country that a given national (significant) number belongs to
|
|
6
|
+
* in case of ambiguity, i.e. when multiple countries share the same "country calling code".
|
|
7
|
+
* @param {string} [nationalNumber]
|
|
8
|
+
* @param {string[]} countries — A list of countries that share the same calling code.
|
|
9
|
+
* @param {object} metadata — Metadata JSON.
|
|
10
|
+
* @returns {string?} Returns the exact country this number belongs to, or `undefined` if the exact country couldn't be determined.
|
|
11
|
+
*/
|
|
12
|
+
export default function getCountryByNationalNumber(nationalNumber, countries, metadataJson) {
|
|
13
|
+
// Create a new `metadata` instance because it will be selecting a `country`.
|
|
14
|
+
const metadata = new Metadata(metadataJson)
|
|
12
15
|
|
|
13
16
|
// const matchingCountries = []
|
|
14
17
|
|
|
@@ -22,14 +25,14 @@ export default function getCountryByNationalNumber(nationalPhoneNumber, {
|
|
|
22
25
|
// I'd suppose that "leading digits" patterns are mutually exclusive for different countries
|
|
23
26
|
// because of the intended use of that feature.
|
|
24
27
|
if (metadata.leadingDigits()) {
|
|
25
|
-
if (
|
|
26
|
-
|
|
28
|
+
if (nationalNumber &&
|
|
29
|
+
nationalNumber.search(metadata.leadingDigits()) === 0) {
|
|
27
30
|
return country
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
// Else perform full validation with all of those
|
|
31
34
|
// fixed-line/mobile/etc regular expressions.
|
|
32
|
-
else if (getNumberType({ phone:
|
|
35
|
+
else if (getNumberType({ phone: nationalNumber, country }, undefined, metadata.metadata)) {
|
|
33
36
|
// When multiple countries share the same "country calling code",
|
|
34
37
|
// type patterns aren't guaranteed to be unique among them.
|
|
35
38
|
// For example, both `US` and `CA` have the same pattern for `toll_free` numbers.
|
|
@@ -15,7 +15,7 @@ const SINGLE_IDD_PREFIX_REG_EXP = /^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/
|
|
|
15
15
|
// If the `country` doesn't support IDD calling, it returns `undefined`.
|
|
16
16
|
export default function getIddPrefix(country, callingCode, metadata) {
|
|
17
17
|
const countryMetadata = new Metadata(metadata)
|
|
18
|
-
countryMetadata.selectNumberingPlan(country
|
|
18
|
+
countryMetadata.selectNumberingPlan(country || callingCode)
|
|
19
19
|
if (countryMetadata.defaultIDDPrefix()) {
|
|
20
20
|
return countryMetadata.defaultIDDPrefix()
|
|
21
21
|
}
|
|
@@ -14,7 +14,7 @@ const NON_FIXED_LINE_PHONE_TYPES = [
|
|
|
14
14
|
]
|
|
15
15
|
|
|
16
16
|
// Finds out national phone number type (fixed line, mobile, etc)
|
|
17
|
-
export default function getNumberType(input, options,
|
|
17
|
+
export default function getNumberType(input, options, metadataJson)
|
|
18
18
|
{
|
|
19
19
|
// If assigning the `{}` default value is moved to the arguments above,
|
|
20
20
|
// code coverage would decrease for some weird reason.
|
|
@@ -27,9 +27,9 @@ export default function getNumberType(input, options, metadata)
|
|
|
27
27
|
return
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
metadata = new Metadata(
|
|
30
|
+
const metadata = new Metadata(metadataJson)
|
|
31
31
|
|
|
32
|
-
metadata.selectNumberingPlan(input.country
|
|
32
|
+
metadata.selectNumberingPlan(input.country || input.countryCallingCode)
|
|
33
33
|
|
|
34
34
|
const nationalNumber = options.v2 ? input.nationalNumber : input.phone
|
|
35
35
|
|
|
@@ -18,11 +18,8 @@ export default function getPossibleCountriesForNumber(callingCode, nationalNumbe
|
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function couldNationalNumberBelongToCountry(nationalNumber, country,
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return true
|
|
26
|
-
}
|
|
27
|
-
return false
|
|
21
|
+
function couldNationalNumberBelongToCountry(nationalNumber, country, metadataJson) {
|
|
22
|
+
const metadata = new Metadata(metadataJson)
|
|
23
|
+
metadata.selectNumberingPlan(country)
|
|
24
|
+
return metadata.numberingPlan.possibleLengths().indexOf(nationalNumber.length) >= 0
|
|
28
25
|
}
|
|
@@ -3,19 +3,24 @@ import { VALID_DIGITS } from '../constants.js'
|
|
|
3
3
|
|
|
4
4
|
const CAPTURING_DIGIT_PATTERN = new RegExp('([' + VALID_DIGITS + '])')
|
|
5
5
|
|
|
6
|
-
export default function stripIddPrefix(number, country, callingCode,
|
|
6
|
+
export default function stripIddPrefix(number, country, callingCode, metadataJson) {
|
|
7
7
|
if (!country) {
|
|
8
8
|
return
|
|
9
9
|
}
|
|
10
|
+
|
|
11
|
+
// Get the IDD prefix pattern.
|
|
12
|
+
const metadata = new Metadata(metadataJson)
|
|
13
|
+
metadata.selectNumberingPlan(country || callingCode)
|
|
14
|
+
const IDDPrefixPattern = new RegExp(metadata.IDDPrefix())
|
|
15
|
+
|
|
10
16
|
// Check if the number is IDD-prefixed.
|
|
11
|
-
const countryMetadata = new Metadata(metadata)
|
|
12
|
-
countryMetadata.selectNumberingPlan(country, callingCode)
|
|
13
|
-
const IDDPrefixPattern = new RegExp(countryMetadata.IDDPrefix())
|
|
14
17
|
if (number.search(IDDPrefixPattern) !== 0) {
|
|
15
18
|
return
|
|
16
19
|
}
|
|
20
|
+
|
|
17
21
|
// Strip IDD prefix.
|
|
18
22
|
number = number.slice(number.match(IDDPrefixPattern)[0].length)
|
|
23
|
+
|
|
19
24
|
// If there're any digits after an IDD prefix,
|
|
20
25
|
// then those digits are a country calling code.
|
|
21
26
|
// Since no country code starts with a `0`,
|
|
@@ -26,5 +31,6 @@ export default function stripIddPrefix(number, country, callingCode, metadata) {
|
|
|
26
31
|
return
|
|
27
32
|
}
|
|
28
33
|
}
|
|
34
|
+
|
|
29
35
|
return number
|
|
30
36
|
}
|
package/source/isPossible.js
CHANGED
|
@@ -11,22 +11,22 @@ import checkNumberLength from './helpers/checkNumberLength.js'
|
|
|
11
11
|
*
|
|
12
12
|
* @param {object|PhoneNumber} input — If `options.v2: true` flag is passed, the `input` should be a `PhoneNumber` instance. Otherwise, it should be an object of shape `{ phone: '...', country: '...' }`.
|
|
13
13
|
* @param {object} [options]
|
|
14
|
-
* @param {object}
|
|
14
|
+
* @param {object} metadataJson
|
|
15
15
|
* @return {string}
|
|
16
16
|
*/
|
|
17
|
-
export default function isPossiblePhoneNumber(input, options,
|
|
17
|
+
export default function isPossiblePhoneNumber(input, options, metadataJson) {
|
|
18
18
|
/* istanbul ignore if */
|
|
19
19
|
if (options === undefined) {
|
|
20
20
|
options = {}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
metadata = new Metadata(
|
|
23
|
+
const metadata = new Metadata(metadataJson)
|
|
24
24
|
|
|
25
25
|
if (options.v2) {
|
|
26
26
|
if (!input.countryCallingCode) {
|
|
27
27
|
throw new Error('Invalid phone number object passed')
|
|
28
28
|
}
|
|
29
|
-
metadata.selectNumberingPlan(input.countryCallingCode)
|
|
29
|
+
metadata.selectNumberingPlan(input.country || input.countryCallingCode)
|
|
30
30
|
} else {
|
|
31
31
|
if (!input.phone) {
|
|
32
32
|
return false
|
|
@@ -47,7 +47,7 @@ export default function isPossiblePhoneNumber(input, options, metadata) {
|
|
|
47
47
|
// Old (legacy) metadata (< 1.0.18) had no "possible length" data.
|
|
48
48
|
// So `isPossibleNumber()` function is supported only for non-legacy metadata.
|
|
49
49
|
if (metadata.possibleLengths()) {
|
|
50
|
-
return isPossibleNumber(input.phone || input.nationalNumber,
|
|
50
|
+
return isPossibleNumber(input.phone || input.nationalNumber, metadata)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// There was a bug in versions from `1.7.35` to `1.7.37` of `libphonenumber-js`
|
|
@@ -65,8 +65,14 @@ export default function isPossiblePhoneNumber(input, options, metadata) {
|
|
|
65
65
|
throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.');
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Tells if a given national (significant) number is possible
|
|
70
|
+
* @param {string} nationalNumber
|
|
71
|
+
* @param {Metadata} metadata = Metadata instance with a pre-selected telephone numbering plan.
|
|
72
|
+
* @returns {boolean}
|
|
73
|
+
*/
|
|
74
|
+
export function isPossibleNumber(nationalNumber, metadata) {
|
|
75
|
+
switch (checkNumberLength(nationalNumber, undefined, metadata)) {
|
|
70
76
|
case 'IS_POSSIBLE':
|
|
71
77
|
return true
|
|
72
78
|
// This library ignores "local-only" phone numbers (for simplicity).
|
package/source/isValid.js
CHANGED
|
@@ -36,15 +36,15 @@ import getNumberType from './helpers/getNumberType.js'
|
|
|
36
36
|
* isValidNumber({ phone: '8005553535', country: 'RU' }, metadata)
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export default function isValidNumber(input, options,
|
|
39
|
+
export default function isValidNumber(input, options, metadataJson)
|
|
40
40
|
{
|
|
41
41
|
// If assigning the `{}` default value is moved to the arguments above,
|
|
42
42
|
// code coverage would decrease for some weird reason.
|
|
43
43
|
options = options || {}
|
|
44
44
|
|
|
45
|
-
metadata = new Metadata(
|
|
45
|
+
const metadata = new Metadata(metadataJson)
|
|
46
46
|
|
|
47
|
-
metadata.selectNumberingPlan(input.country
|
|
47
|
+
metadata.selectNumberingPlan(input.country || input.countryCallingCode)
|
|
48
48
|
|
|
49
49
|
// By default, countries only have type regexps when it's required for
|
|
50
50
|
// distinguishing different countries having the same `countryCallingCode`.
|
package/source/metadata.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import compare from './tools/semver-compare.js'
|
|
2
2
|
import isObject from './helpers/isObject.js'
|
|
3
|
+
import isCallingCode from './helpers/isCallingCode.js'
|
|
3
4
|
|
|
4
5
|
// Added "possibleLengths" and renamed
|
|
5
6
|
// "country_phone_code_to_countries" to "country_calling_codes".
|
|
@@ -13,12 +14,13 @@ const V4 = '1.7.35'
|
|
|
13
14
|
|
|
14
15
|
const DEFAULT_EXT_PREFIX = ' ext. '
|
|
15
16
|
|
|
16
|
-
const CALLING_CODE_REG_EXP = /^\d+$/
|
|
17
|
-
|
|
18
17
|
/**
|
|
19
18
|
* See: https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md
|
|
20
19
|
*/
|
|
21
20
|
export default class Metadata {
|
|
21
|
+
/**
|
|
22
|
+
* @param {object} metadata — Metadata JSON.
|
|
23
|
+
*/
|
|
22
24
|
constructor(metadata) {
|
|
23
25
|
validateMetadata(metadata)
|
|
24
26
|
this.metadata = metadata
|
|
@@ -75,17 +77,35 @@ export default class Metadata {
|
|
|
75
77
|
return this.selectNumberingPlan(countryCode)
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Selects a telephone numbering plan based on either a country code or a calling code.
|
|
82
|
+
* @param {string} argument — Country code or calling code.
|
|
83
|
+
* @param {string} legacyArgumentCallingCode — Legacy argument: calling code, if the first argument is not passed.
|
|
84
|
+
*/
|
|
85
|
+
selectNumberingPlan(argument, legacyArgumentCallingCode) {
|
|
86
|
+
let countryCode
|
|
87
|
+
let callingCode
|
|
88
|
+
if (argument) {
|
|
89
|
+
if (isCallingCode(argument)) {
|
|
90
|
+
callingCode = argument
|
|
91
|
+
} else {
|
|
92
|
+
countryCode = argument
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Previously, the signature of this method was: `.selectNumberingPlan(country, callingCode)`.
|
|
96
|
+
// And if `country` argument wasn't passed, it looked into the second argument `callingCode`.
|
|
97
|
+
// Now it's preferred to only pass either `country` or `callingCode` as the first argument.
|
|
98
|
+
if (legacyArgumentCallingCode) {
|
|
99
|
+
callingCode = legacyArgumentCallingCode
|
|
83
100
|
}
|
|
101
|
+
|
|
102
|
+
// Select a telephone numbering plan.
|
|
84
103
|
if (countryCode && countryCode !== '001') {
|
|
85
|
-
|
|
104
|
+
const countryMetadata = this.getCountryMetadata(countryCode)
|
|
105
|
+
if (!countryMetadata) {
|
|
86
106
|
throw new Error(`Unknown country: ${countryCode}`)
|
|
87
107
|
}
|
|
88
|
-
this.numberingPlan = new NumberingPlan(
|
|
108
|
+
this.numberingPlan = new NumberingPlan(countryMetadata, this)
|
|
89
109
|
} else if (callingCode) {
|
|
90
110
|
if (!this.hasCallingCode(callingCode)) {
|
|
91
111
|
throw new Error(`Unknown calling code: ${callingCode}`)
|
|
@@ -94,6 +114,7 @@ export default class Metadata {
|
|
|
94
114
|
} else {
|
|
95
115
|
this.numberingPlan = undefined
|
|
96
116
|
}
|
|
117
|
+
|
|
97
118
|
return this
|
|
98
119
|
}
|
|
99
120
|
|
|
@@ -124,6 +145,10 @@ export default class Metadata {
|
|
|
124
145
|
}
|
|
125
146
|
|
|
126
147
|
getNumberingPlanMetadata(callingCode) {
|
|
148
|
+
// If a calling code is specified, choose the telephone numbering plan
|
|
149
|
+
// of the "default" country for this calling code.
|
|
150
|
+
// For example, if calling code `1` is passed,
|
|
151
|
+
// the telephone numbering plan of `US` will be selected.
|
|
127
152
|
const countryCode = this.getCountryCodeForCallingCode(callingCode)
|
|
128
153
|
if (countryCode) {
|
|
129
154
|
return this.getCountryMetadata(countryCode)
|
|
@@ -232,16 +257,27 @@ class NumberingPlan {
|
|
|
232
257
|
return this.metadata[0]
|
|
233
258
|
}
|
|
234
259
|
|
|
235
|
-
//
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
|
|
260
|
+
// When multiple countries share the same calling code,
|
|
261
|
+
// all phone number formatting rules are included in the metadata
|
|
262
|
+
// of the "default" country for that calling code.
|
|
263
|
+
// Any other countries' metdata doesn't include any formatting rules.
|
|
264
|
+
// Google developers said that such storage architecture was chosen for performance reasons.
|
|
265
|
+
//
|
|
266
|
+
// For example, for NANPA region ("North American Numbering Plan Administration",
|
|
267
|
+
// which includes USA, Canada, Cayman Islands, Bahamas, etc) all formatting rules
|
|
268
|
+
// are contained in the metadata of `US` country.
|
|
269
|
+
//
|
|
270
|
+
// This is not public API.
|
|
271
|
+
//
|
|
272
|
+
_getDefaultCountryMetadataForThisCallingCode() {
|
|
242
273
|
return this.globalMetadataObject.getNumberingPlanMetadata(this.callingCode())
|
|
243
274
|
}
|
|
244
275
|
|
|
276
|
+
// Deprecated.
|
|
277
|
+
getDefaultCountryMetadataForRegion() {
|
|
278
|
+
return this._getDefaultCountryMetadataForThisCallingCode()
|
|
279
|
+
}
|
|
280
|
+
|
|
245
281
|
// Is always present.
|
|
246
282
|
IDDPrefix() {
|
|
247
283
|
if (this.v1 || this.v2) return
|
|
@@ -273,7 +309,7 @@ class NumberingPlan {
|
|
|
273
309
|
// formats are all stored in the "main" country for that region.
|
|
274
310
|
// E.g. "RU" and "KZ", "US" and "CA".
|
|
275
311
|
formats() {
|
|
276
|
-
const formats = this._getFormats(this.metadata) || this._getFormats(this.
|
|
312
|
+
const formats = this._getFormats(this.metadata) || this._getFormats(this._getDefaultCountryMetadataForThisCallingCode()) || []
|
|
277
313
|
return formats.map(_ => new Format(_, this))
|
|
278
314
|
}
|
|
279
315
|
|
|
@@ -289,7 +325,7 @@ class NumberingPlan {
|
|
|
289
325
|
// national prefix formatting rule is stored in the "main" country for that region.
|
|
290
326
|
// E.g. "RU" and "KZ", "US" and "CA".
|
|
291
327
|
nationalPrefixFormattingRule() {
|
|
292
|
-
return this._getNationalPrefixFormattingRule(this.metadata) || this._getNationalPrefixFormattingRule(this.
|
|
328
|
+
return this._getNationalPrefixFormattingRule(this.metadata) || this._getNationalPrefixFormattingRule(this._getDefaultCountryMetadataForThisCallingCode())
|
|
293
329
|
}
|
|
294
330
|
|
|
295
331
|
_nationalPrefixForParsing() {
|
|
@@ -316,7 +352,7 @@ class NumberingPlan {
|
|
|
316
352
|
// E.g. "RU" and "KZ", "US" and "CA".
|
|
317
353
|
nationalPrefixIsOptionalWhenFormattingInNationalFormat() {
|
|
318
354
|
return this._getNationalPrefixIsOptionalWhenFormatting(this.metadata) ||
|
|
319
|
-
this._getNationalPrefixIsOptionalWhenFormatting(this.
|
|
355
|
+
this._getNationalPrefixIsOptionalWhenFormatting(this._getDefaultCountryMetadataForThisCallingCode())
|
|
320
356
|
}
|
|
321
357
|
|
|
322
358
|
leadingDigits() {
|
|
@@ -479,8 +515,8 @@ const typeOf = _ => typeof _
|
|
|
479
515
|
* // Returns " ext. "
|
|
480
516
|
* getExtPrefix("US")
|
|
481
517
|
*/
|
|
482
|
-
export function getExtPrefix(country,
|
|
483
|
-
metadata = new Metadata(
|
|
518
|
+
export function getExtPrefix(country, metadataJson) {
|
|
519
|
+
const metadata = new Metadata(metadataJson)
|
|
484
520
|
if (metadata.hasCountry(country)) {
|
|
485
521
|
return metadata.selectNumberingPlan(country).ext()
|
|
486
522
|
}
|
|
@@ -491,26 +527,39 @@ export function getExtPrefix(country, metadata) {
|
|
|
491
527
|
* Returns "country calling code" for a country.
|
|
492
528
|
* Throws an error if the country doesn't exist or isn't supported by this library.
|
|
493
529
|
* @param {string} country
|
|
494
|
-
* @param {object}
|
|
530
|
+
* @param {object} metadataJson
|
|
495
531
|
* @return {string}
|
|
496
532
|
* @example
|
|
497
533
|
* // Returns "44"
|
|
498
534
|
* getCountryCallingCode("GB")
|
|
499
535
|
*/
|
|
500
|
-
export function getCountryCallingCode(country,
|
|
501
|
-
metadata = new Metadata(
|
|
536
|
+
export function getCountryCallingCode(country, metadataJson) {
|
|
537
|
+
const metadata = new Metadata(metadataJson)
|
|
502
538
|
if (metadata.hasCountry(country)) {
|
|
503
539
|
return metadata.selectNumberingPlan(country).countryCallingCode()
|
|
504
540
|
}
|
|
505
541
|
throw new Error(`Unknown country: ${country}`)
|
|
506
542
|
}
|
|
507
543
|
|
|
508
|
-
|
|
509
|
-
|
|
544
|
+
/**
|
|
545
|
+
* Tells if a country code is supported.
|
|
546
|
+
* @param {string} country
|
|
547
|
+
* @param {object} metadataJson
|
|
548
|
+
* @return {boolean}
|
|
549
|
+
* @example
|
|
550
|
+
* // Returns `true`
|
|
551
|
+
* isSupportedCountry("GB")
|
|
552
|
+
*/
|
|
553
|
+
export function isSupportedCountry(country, metadataJson) {
|
|
554
|
+
// const metadata = new Metadata(metadataJson)
|
|
510
555
|
// return metadata.hasCountry(country)
|
|
511
|
-
return
|
|
556
|
+
return metadataJson.countries.hasOwnProperty(country)
|
|
512
557
|
}
|
|
513
558
|
|
|
559
|
+
/**
|
|
560
|
+
* Sets `v1`/`v2`/`v3`/`v4` properties on `this` object.
|
|
561
|
+
* @param {object} metadata — Metadata JSON
|
|
562
|
+
*/
|
|
514
563
|
function setVersion(metadata) {
|
|
515
564
|
const { version } = metadata
|
|
516
565
|
if (typeof version === 'number') {
|
|
@@ -529,9 +578,4 @@ function setVersion(metadata) {
|
|
|
529
578
|
this.v4 = true
|
|
530
579
|
}
|
|
531
580
|
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
// const ISO_COUNTRY_CODE = /^[A-Z]{2}$/
|
|
535
|
-
// function isCountryCode(countryCode) {
|
|
536
|
-
// return ISO_COUNTRY_CODE.test(countryCodeOrCountryCallingCode)
|
|
537
|
-
// }
|
|
581
|
+
}
|
package/source/parse.js
CHANGED
|
@@ -61,15 +61,15 @@ const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
|
|
|
61
61
|
*
|
|
62
62
|
* @param {string} input
|
|
63
63
|
* @param {object} [options]
|
|
64
|
-
* @param {object}
|
|
64
|
+
* @param {object} metadataJson
|
|
65
65
|
* @return {object|PhoneNumber?} If `options.v2: true` flag is passed, it returns a `PhoneNumber?` instance. Otherwise, returns an object of shape `{ phone: '...', country: '...' }` (or just `{}` if no phone number was parsed).
|
|
66
66
|
*/
|
|
67
|
-
export default function parse(text, options,
|
|
67
|
+
export default function parse(text, options, metadataJson) {
|
|
68
68
|
// If assigning the `{}` default value is moved to the arguments above,
|
|
69
69
|
// code coverage would decrease for some weird reason.
|
|
70
70
|
options = options || {}
|
|
71
71
|
|
|
72
|
-
metadata = new Metadata(
|
|
72
|
+
const metadata = new Metadata(metadataJson)
|
|
73
73
|
|
|
74
74
|
// Validate `defaultCountry`.
|
|
75
75
|
if (options.defaultCountry && !metadata.hasCountry(options.defaultCountry)) {
|
|
@@ -103,6 +103,9 @@ export default function parse(text, options, metadata) {
|
|
|
103
103
|
formattedPhoneNumber,
|
|
104
104
|
options.defaultCountry,
|
|
105
105
|
options.defaultCallingCode,
|
|
106
|
+
// If `country` is returned, its numbering plan will also be selected in `metadata`.
|
|
107
|
+
// Otherwise, if `countryCallingCode` is returned, its numbering plan will also be selected in `metadata`.
|
|
108
|
+
// Otherwise, if neither `country` nor `countryCallingCode` are returned, no numbering plan will be selected in `metadata`.
|
|
106
109
|
metadata
|
|
107
110
|
)
|
|
108
111
|
|
|
@@ -181,7 +184,7 @@ export default function parse(text, options, metadata) {
|
|
|
181
184
|
possible: valid ? true : (
|
|
182
185
|
options.extended === true &&
|
|
183
186
|
metadata.possibleLengths() &&
|
|
184
|
-
isPossibleNumber(nationalNumber,
|
|
187
|
+
isPossibleNumber(nationalNumber, metadata) ? true : false
|
|
185
188
|
),
|
|
186
189
|
phone: nationalNumber,
|
|
187
190
|
ext
|
|
@@ -278,7 +281,7 @@ function result(country, nationalNumber, ext) {
|
|
|
278
281
|
* @param {string} formattedPhoneNumber — Example: "(213) 373-4253".
|
|
279
282
|
* @param {string} [defaultCountry]
|
|
280
283
|
* @param {string} [defaultCallingCode]
|
|
281
|
-
* @param {Metadata} metadata
|
|
284
|
+
* @param {Metadata} metadata — Metadata instance with no pre-selected numbering plan. If `country` is returned, its numbering plan will also be selected in `metadata`. Otherwise, if `countryCallingCode` is returned, its numbering plan will also be selected in `metadata`. Otherwise, if neither `country` nor `countryCallingCode` are returned, no numbering plan will be selected in `metadata`.
|
|
282
285
|
* @return {object} Returns `{ country: string?, countryCallingCode: string?, nationalNumber: string? }`.
|
|
283
286
|
*/
|
|
284
287
|
function parsePhoneNumber(
|
|
@@ -287,10 +290,30 @@ function parsePhoneNumber(
|
|
|
287
290
|
defaultCallingCode,
|
|
288
291
|
metadata
|
|
289
292
|
) {
|
|
290
|
-
//
|
|
291
|
-
|
|
293
|
+
// Attempt to extract a calling code from a phone number.
|
|
294
|
+
// * If the phone number is found to be "international":
|
|
295
|
+
// * It will attempt to identify the calling code part of it and whether that part is complete and valid.
|
|
296
|
+
// * If the calling code part is complete and valid, it will return two properties:
|
|
297
|
+
// that calling code part (without `+`) and the rest of the digits.
|
|
298
|
+
// * Otherwise, i.e. if the calling code part is incomplete or invalid,
|
|
299
|
+
// it will return an empty object.
|
|
300
|
+
// * Otherwise, i.e. if the phone number is national, there's no callind code to extract
|
|
301
|
+
// so it will just return the originally-passed `number` string as the only property.
|
|
302
|
+
let {
|
|
303
|
+
// `countryCallingCodeSource` tells how the returned calling code was extracted (if it was extracted).
|
|
304
|
+
countryCallingCodeSource,
|
|
305
|
+
// `countryCallingCode` is the calling code that was extracted from the input phone number string.
|
|
306
|
+
countryCallingCode,
|
|
307
|
+
// `number` is the originally passed `number` without the extracted calling code (and without a `+`).
|
|
308
|
+
// If the calling code is present but incomplete or invalid, both `countryCallingCode` and `number`
|
|
309
|
+
// will be returned as `undefined`.
|
|
310
|
+
number
|
|
311
|
+
} = extractCountryCallingCode(
|
|
292
312
|
parseIncompletePhoneNumber(formattedPhoneNumber),
|
|
293
313
|
undefined,
|
|
314
|
+
// `defaultCountry` and `defaultCallingCode` are only used to detect
|
|
315
|
+
// if it's an "international" phone number or not. They won't be used
|
|
316
|
+
// to derive the resulting `countryCallingCode` from them, or anything like that.
|
|
294
317
|
defaultCountry,
|
|
295
318
|
defaultCallingCode,
|
|
296
319
|
metadata.metadata
|
|
@@ -307,21 +330,28 @@ function parsePhoneNumber(
|
|
|
307
330
|
// Else, if `formattedPhoneNumber` is passed in "national" format,
|
|
308
331
|
// then `number` is defined and `countryCallingCode` is `undefined`.
|
|
309
332
|
else if (number && (defaultCountry || defaultCallingCode)) {
|
|
310
|
-
metadata.selectNumberingPlan(defaultCountry, defaultCallingCode)
|
|
311
333
|
if (defaultCountry) {
|
|
312
334
|
country = defaultCountry
|
|
335
|
+
metadata.selectNumberingPlan(defaultCountry)
|
|
336
|
+
countryCallingCode = metadata.numberingPlan.callingCode()
|
|
313
337
|
} else {
|
|
338
|
+
metadata.selectNumberingPlan(defaultCallingCode)
|
|
339
|
+
countryCallingCode = defaultCallingCode
|
|
314
340
|
/* istanbul ignore if */
|
|
315
341
|
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
316
|
-
if (metadata.isNonGeographicCallingCode(
|
|
342
|
+
if (metadata.isNonGeographicCallingCode(countryCallingCode)) {
|
|
317
343
|
country = '001'
|
|
318
344
|
}
|
|
319
345
|
}
|
|
320
346
|
}
|
|
321
|
-
countryCallingCode = defaultCallingCode || getCountryCallingCode(defaultCountry, metadata.metadata)
|
|
322
347
|
}
|
|
323
348
|
else return {}
|
|
324
349
|
|
|
350
|
+
// At this point, `country` could be `undefined` but `countryCallingCode` is always defined.
|
|
351
|
+
//
|
|
352
|
+
// Also, if `country` is defined, its numbering plan is selected in `metadata`.
|
|
353
|
+
// Otherwise, the numering plan for the `countryCallingCode` is selected in `metadata`.
|
|
354
|
+
|
|
325
355
|
if (!number) {
|
|
326
356
|
return {
|
|
327
357
|
countryCallingCodeSource,
|
|
@@ -334,7 +364,7 @@ function parsePhoneNumber(
|
|
|
334
364
|
carrierCode
|
|
335
365
|
} = extractNationalNumber(
|
|
336
366
|
parseIncompletePhoneNumber(number),
|
|
337
|
-
|
|
367
|
+
undefined,
|
|
338
368
|
metadata
|
|
339
369
|
)
|
|
340
370
|
|
|
@@ -14,9 +14,9 @@ export default function validatePhoneNumberLength() {
|
|
|
14
14
|
// Parse phone number.
|
|
15
15
|
try {
|
|
16
16
|
const phoneNumber = parsePhoneNumberWithError(text, options, metadata)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const result = checkNumberLength(phoneNumber.nationalNumber,
|
|
17
|
+
const metadataInstance = new Metadata(metadata)
|
|
18
|
+
metadataInstance.selectNumberingPlan(phoneNumber.country || phoneNumber.countryCallingCode)
|
|
19
|
+
const result = checkNumberLength(phoneNumber.nationalNumber, undefined, metadataInstance)
|
|
20
20
|
if (result !== 'IS_POSSIBLE') {
|
|
21
21
|
return result
|
|
22
22
|
}
|