libphonenumber-js 1.9.2 → 1.9.6
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/CHANGELOG.md +23 -0
- package/README.md +34 -9
- package/build/AsYouType.js +16 -21
- package/build/AsYouType.js.map +1 -1
- package/build/AsYouType.test.js +12 -3
- package/build/AsYouType.test.js.map +1 -1
- package/build/AsYouTypeFormatter.complete.js +4 -4
- package/build/AsYouTypeFormatter.complete.js.map +1 -1
- package/build/AsYouTypeFormatter.js +25 -15
- package/build/AsYouTypeFormatter.js.map +1 -1
- package/build/AsYouTypeParser.js +70 -37
- package/build/AsYouTypeParser.js.map +1 -1
- package/build/AsYouTypeState.js +1 -0
- package/build/AsYouTypeState.js.map +1 -1
- package/build/PhoneNumber.js +2 -2
- package/build/PhoneNumber.js.map +1 -1
- package/build/PhoneNumberMatcher.js +20 -16
- package/build/PhoneNumberMatcher.js.map +1 -1
- package/build/findNumbers/Leniency.js +1 -1
- package/build/findNumbers/Leniency.js.map +1 -1
- package/build/findNumbers.test.js +31 -22
- package/build/findNumbers.test.js.map +1 -1
- package/build/findPhoneNumbers_.js +21 -4
- package/build/findPhoneNumbers_.js.map +1 -1
- package/build/format.test.js +0 -6
- package/build/format.test.js.map +1 -1
- package/build/formatNumberForMobileDialing.js +3 -3
- package/build/formatNumberForMobileDialing.js.map +1 -1
- package/build/format_.js +15 -84
- package/build/format_.js.map +1 -1
- package/build/getNumberType.js +3 -3
- package/build/getNumberType.js.map +1 -1
- package/build/{RFC3966.js → helpers/RFC3966.js} +0 -0
- package/build/helpers/RFC3966.js.map +1 -0
- package/build/{RFC3966.test.js → helpers/RFC3966.test.js} +0 -0
- package/build/helpers/RFC3966.test.js.map +1 -0
- package/build/helpers/applyInternationalSeparatorStyle.js +43 -0
- package/build/helpers/applyInternationalSeparatorStyle.js.map +1 -0
- package/build/helpers/applyInternationalSeparatorStyle.test.js +13 -0
- package/build/helpers/applyInternationalSeparatorStyle.test.js.map +1 -0
- package/build/{checkNumberLength.js → helpers/checkNumberLength.js} +4 -2
- package/build/helpers/checkNumberLength.js.map +1 -0
- package/build/{checkNumberLength.test.js → helpers/checkNumberLength.test.js} +2 -2
- package/build/helpers/checkNumberLength.test.js.map +1 -0
- package/build/{extension.js → helpers/extension/createExtensionPattern.js} +3 -56
- package/build/helpers/extension/createExtensionPattern.js.map +1 -0
- package/build/helpers/extension/extractExtension.js +42 -0
- package/build/helpers/extension/extractExtension.js.map +1 -0
- package/build/helpers/extractCountryCallingCode.js +114 -0
- package/build/helpers/extractCountryCallingCode.js.map +1 -0
- package/build/helpers/extractCountryCallingCode.test.js +22 -0
- package/build/helpers/extractCountryCallingCode.test.js.map +1 -0
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +63 -0
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -0
- package/build/helpers/extractNationalNumber.js +110 -0
- package/build/helpers/extractNationalNumber.js.map +1 -0
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +114 -0
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -0
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +22 -0
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -0
- package/build/helpers/formatNationalNumberUsingFormat.js +46 -0
- package/build/helpers/formatNationalNumberUsingFormat.js.map +1 -0
- package/build/helpers/getCountryByCallingCode.js +73 -0
- package/build/helpers/getCountryByCallingCode.js.map +1 -0
- package/build/helpers/getIddPrefix.js +34 -0
- package/build/helpers/getIddPrefix.js.map +1 -0
- package/build/{getNumberType_.js → helpers/getNumberType.js} +12 -12
- package/build/helpers/getNumberType.js.map +1 -0
- package/build/{isViablePhoneNumber.js → helpers/isViablePhoneNumber.js} +5 -3
- package/build/helpers/isViablePhoneNumber.js.map +1 -0
- package/build/helpers/matchesEntirely.js +19 -0
- package/build/helpers/matchesEntirely.js.map +1 -0
- package/build/helpers/matchesEntirely.test.js +15 -0
- package/build/helpers/matchesEntirely.test.js.map +1 -0
- package/build/{util.js → helpers/mergeArrays.js} +3 -18
- package/build/helpers/mergeArrays.js.map +1 -0
- package/build/helpers/mergeArrays.test.js +12 -0
- package/build/helpers/mergeArrays.test.js.map +1 -0
- package/build/{parseDigits.js → helpers/parseDigits.js} +0 -0
- package/build/helpers/parseDigits.js.map +1 -0
- package/build/{parseDigits.test.js → helpers/parseDigits.test.js} +0 -0
- package/build/helpers/parseDigits.test.js.map +1 -0
- package/build/helpers/stripIddPrefix.js +46 -0
- package/build/helpers/stripIddPrefix.js.map +1 -0
- package/build/helpers/stripIddPrefix.test.js +23 -0
- package/build/helpers/stripIddPrefix.test.js.map +1 -0
- package/build/isPossibleNumber_.js +1 -1
- package/build/isPossibleNumber_.js.map +1 -1
- package/build/isValidNumberForRegion.js +1 -1
- package/build/isValidNumberForRegion.js.map +1 -1
- package/build/parse.test.js +1 -25
- package/build/parse.test.js.map +1 -1
- package/build/parseIncompletePhoneNumber.js +9 -6
- package/build/parseIncompletePhoneNumber.js.map +1 -1
- package/build/parse_.js +19 -425
- package/build/parse_.js.map +1 -1
- package/build/validate_.js +4 -4
- package/build/validate_.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.commonjs.js +5 -3
- package/core/index.d.ts +9 -1
- package/core/index.js +6 -2
- package/custom.d.ts +9 -1
- package/custom.js +5 -6
- package/es6/AsYouType.js +17 -22
- package/es6/AsYouType.js.map +1 -1
- package/es6/AsYouType.test.js +12 -3
- package/es6/AsYouType.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.complete.js +3 -3
- package/es6/AsYouTypeFormatter.complete.js.map +1 -1
- package/es6/AsYouTypeFormatter.js +22 -13
- package/es6/AsYouTypeFormatter.js.map +1 -1
- package/es6/AsYouTypeParser.js +65 -32
- package/es6/AsYouTypeParser.js.map +1 -1
- package/es6/AsYouTypeState.js +1 -0
- package/es6/AsYouTypeState.js.map +1 -1
- package/es6/PhoneNumber.js +1 -1
- package/es6/PhoneNumber.js.map +1 -1
- package/es6/PhoneNumberMatcher.js +18 -15
- package/es6/PhoneNumberMatcher.js.map +1 -1
- package/es6/findNumbers/Leniency.js +1 -1
- package/es6/findNumbers/Leniency.js.map +1 -1
- package/es6/findNumbers.test.js +10 -1
- package/es6/findNumbers.test.js.map +1 -1
- package/es6/findPhoneNumbers_.js +19 -2
- package/es6/findPhoneNumbers_.js.map +1 -1
- package/es6/format.test.js +0 -5
- package/es6/format.test.js.map +1 -1
- package/es6/formatNumberForMobileDialing.js +2 -2
- package/es6/formatNumberForMobileDialing.js.map +1 -1
- package/es6/format_.js +11 -76
- package/es6/format_.js.map +1 -1
- package/es6/getNumberType.js +2 -2
- package/es6/getNumberType.js.map +1 -1
- package/es6/{RFC3966.js → helpers/RFC3966.js} +0 -0
- package/es6/helpers/RFC3966.js.map +1 -0
- package/es6/{RFC3966.test.js → helpers/RFC3966.test.js} +0 -0
- package/es6/helpers/RFC3966.test.js.map +1 -0
- package/es6/helpers/applyInternationalSeparatorStyle.js +35 -0
- package/es6/helpers/applyInternationalSeparatorStyle.js.map +1 -0
- package/es6/helpers/applyInternationalSeparatorStyle.test.js +8 -0
- package/es6/helpers/applyInternationalSeparatorStyle.test.js.map +1 -0
- package/es6/{checkNumberLength.js → helpers/checkNumberLength.js} +1 -1
- package/es6/helpers/checkNumberLength.js.map +1 -0
- package/es6/{checkNumberLength.test.js → helpers/checkNumberLength.test.js} +2 -2
- package/es6/helpers/checkNumberLength.test.js.map +1 -0
- package/es6/{extension.js → helpers/extension/createExtensionPattern.js} +3 -51
- package/es6/helpers/extension/createExtensionPattern.js.map +1 -0
- package/es6/helpers/extension/extractExtension.js +32 -0
- package/es6/helpers/extension/extractExtension.js.map +1 -0
- package/es6/helpers/extractCountryCallingCode.js +102 -0
- package/es6/helpers/extractCountryCallingCode.js.map +1 -0
- package/es6/helpers/extractCountryCallingCode.test.js +16 -0
- package/es6/helpers/extractCountryCallingCode.test.js.map +1 -0
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +50 -0
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -0
- package/es6/helpers/extractNationalNumber.js +98 -0
- package/es6/helpers/extractNationalNumber.js.map +1 -0
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +107 -0
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -0
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +15 -0
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -0
- package/es6/helpers/formatNationalNumberUsingFormat.js +33 -0
- package/es6/helpers/formatNationalNumberUsingFormat.js.map +1 -0
- package/es6/helpers/getCountryByCallingCode.js +61 -0
- package/es6/helpers/getCountryByCallingCode.js.map +1 -0
- package/es6/helpers/getIddPrefix.js +25 -0
- package/es6/helpers/getIddPrefix.js.map +1 -0
- package/es6/{getNumberType_.js → helpers/getNumberType.js} +9 -9
- package/es6/helpers/getNumberType.js.map +1 -0
- package/es6/{isViablePhoneNumber.js → helpers/isViablePhoneNumber.js} +2 -2
- package/es6/helpers/isViablePhoneNumber.js.map +1 -0
- package/es6/helpers/matchesEntirely.js +12 -0
- package/es6/helpers/matchesEntirely.js.map +1 -0
- package/es6/helpers/matchesEntirely.test.js +10 -0
- package/es6/helpers/matchesEntirely.test.js.map +1 -0
- package/es6/{util.js → helpers/mergeArrays.js} +3 -16
- package/es6/helpers/mergeArrays.js.map +1 -0
- package/es6/helpers/mergeArrays.test.js +7 -0
- package/es6/helpers/mergeArrays.test.js.map +1 -0
- package/es6/{parseDigits.js → helpers/parseDigits.js} +0 -0
- package/es6/helpers/parseDigits.js.map +1 -0
- package/es6/{parseDigits.test.js → helpers/parseDigits.test.js} +0 -0
- package/es6/helpers/parseDigits.test.js.map +1 -0
- package/es6/helpers/stripIddPrefix.js +34 -0
- package/es6/helpers/stripIddPrefix.js.map +1 -0
- package/es6/helpers/stripIddPrefix.test.js +17 -0
- package/es6/helpers/stripIddPrefix.test.js.map +1 -0
- package/es6/isPossibleNumber_.js +1 -1
- package/es6/isPossibleNumber_.js.map +1 -1
- package/es6/isValidNumberForRegion.js +1 -1
- package/es6/isValidNumberForRegion.js.map +1 -1
- package/es6/parse.test.js +1 -24
- package/es6/parse.test.js.map +1 -1
- package/es6/parseIncompletePhoneNumber.js +9 -6
- package/es6/parseIncompletePhoneNumber.js.map +1 -1
- package/es6/parse_.js +12 -411
- package/es6/parse_.js.map +1 -1
- package/es6/validate_.js +2 -2
- package/es6/validate_.js.map +1 -1
- package/index.common.js +71 -183
- package/index.d.ts +9 -5
- package/index.es6.exports/PhoneNumberSearch.js +11 -0
- package/index.es6.exports/findPhoneNumbers.js +7 -0
- package/index.es6.exports/format.js +7 -0
- package/index.es6.exports/getNumberType.js +7 -0
- package/index.es6.exports/isPossibleNumber.js +7 -0
- package/index.es6.exports/isValidNumber.js +7 -0
- package/index.es6.exports/isValidNumberForRegion.js +7 -0
- package/index.es6.exports/parse.js +7 -0
- package/index.es6.exports/searchPhoneNumbers.js +7 -0
- package/index.es6.js +46 -254
- package/max/exports/AsYouType.js +9 -0
- package/max/exports/Metadata.js +9 -0
- package/max/exports/PhoneNumberMatcher.js +8 -0
- package/max/exports/findNumbers.js +6 -0
- package/max/exports/findPhoneNumbersInText.js +6 -0
- package/max/exports/formatIncompletePhoneNumber.js +6 -0
- package/max/exports/getCountries.js +6 -0
- package/max/exports/getCountryCallingCode.js +6 -0
- package/max/exports/getExampleNumber.js +6 -0
- package/max/exports/getExtPrefix.js +6 -0
- package/max/exports/isSupportedCountry.js +6 -0
- package/max/exports/parsePhoneNumberFromString.js +6 -0
- package/max/exports/parsePhoneNumberWithError.js +6 -0
- package/max/exports/searchNumbers.js +6 -0
- package/max/exports/searchPhoneNumbersInText.js +6 -0
- package/max/index.commonjs.js +1 -0
- package/max/index.js +23 -103
- package/max/metadata.js +11 -0
- package/metadata.full.json +1 -1
- package/metadata.full.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/exports/AsYouType.js +9 -0
- package/min/exports/Metadata.js +9 -0
- package/min/exports/PhoneNumberMatcher.js +8 -0
- package/min/exports/findNumbers.js +6 -0
- package/min/exports/findPhoneNumbersInText.js +6 -0
- package/min/exports/formatIncompletePhoneNumber.js +6 -0
- package/min/exports/getCountries.js +6 -0
- package/min/exports/getCountryCallingCode.js +6 -0
- package/min/exports/getExampleNumber.js +6 -0
- package/min/exports/getExtPrefix.js +6 -0
- package/min/exports/isSupportedCountry.js +6 -0
- package/min/exports/parsePhoneNumberFromString.js +6 -0
- package/min/exports/parsePhoneNumberWithError.js +6 -0
- package/min/exports/searchNumbers.js +6 -0
- package/min/exports/searchPhoneNumbersInText.js +6 -0
- package/min/index.commonjs.js +7 -0
- package/min/index.d.ts +11 -1
- package/min/index.js +23 -103
- package/min/metadata.js +11 -0
- package/mobile/exports/AsYouType.js +9 -0
- package/mobile/exports/Metadata.js +9 -0
- package/mobile/exports/PhoneNumberMatcher.js +8 -0
- package/mobile/exports/findNumbers.js +6 -0
- package/mobile/exports/findPhoneNumbersInText.js +6 -0
- package/mobile/exports/formatIncompletePhoneNumber.js +6 -0
- package/mobile/exports/getCountries.js +6 -0
- package/mobile/exports/getCountryCallingCode.js +6 -0
- package/mobile/exports/getExampleNumber.js +6 -0
- package/mobile/exports/getExtPrefix.js +6 -0
- package/mobile/exports/isSupportedCountry.js +6 -0
- package/mobile/exports/parsePhoneNumberFromString.js +6 -0
- package/mobile/exports/parsePhoneNumberWithError.js +6 -0
- package/mobile/exports/searchNumbers.js +6 -0
- package/mobile/exports/searchPhoneNumbersInText.js +6 -0
- package/mobile/index.commonjs.js +1 -0
- package/mobile/index.js +23 -103
- package/mobile/metadata.js +11 -0
- package/package.json +3 -2
- package/runnable/generate-country-codes.js +13 -0
- package/source/AsYouType.js +13 -23
- package/source/AsYouType.test.js +13 -3
- package/source/AsYouTypeFormatter.complete.js +3 -3
- package/source/AsYouTypeFormatter.js +21 -28
- package/source/AsYouTypeParser.js +65 -48
- package/source/AsYouTypeState.js +1 -0
- package/source/PhoneNumber.js +1 -1
- package/source/PhoneNumberMatcher.js +28 -35
- package/source/findNumbers/Leniency.js +1 -1
- package/source/findNumbers.test.js +14 -1
- package/source/findPhoneNumbers_.js +19 -2
- package/source/format.test.js +0 -6
- package/source/formatNumberForMobileDialing.js +2 -2
- package/source/format_.js +7 -86
- package/source/getNumberType.js +2 -2
- package/source/{RFC3966.js → helpers/RFC3966.js} +7 -16
- package/source/{RFC3966.test.js → helpers/RFC3966.test.js} +0 -0
- package/source/helpers/applyInternationalSeparatorStyle.js +35 -0
- package/source/helpers/applyInternationalSeparatorStyle.test.js +8 -0
- package/source/{checkNumberLength.js → helpers/checkNumberLength.js} +1 -1
- package/source/{checkNumberLength.test.js → helpers/checkNumberLength.test.js} +2 -2
- package/source/{extension.js → helpers/extension/createExtensionPattern.js} +2 -49
- package/source/helpers/extension/extractExtension.js +29 -0
- package/source/helpers/extractCountryCallingCode.js +106 -0
- package/source/helpers/extractCountryCallingCode.test.js +18 -0
- package/source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +63 -0
- package/source/helpers/extractNationalNumber.js +92 -0
- package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +104 -0
- package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +15 -0
- package/source/helpers/formatNationalNumberUsingFormat.js +46 -0
- package/source/helpers/getCountryByCallingCode.js +44 -0
- package/source/helpers/getIddPrefix.js +23 -0
- package/source/{getNumberType_.js → helpers/getNumberType.js} +14 -28
- package/source/{isViablePhoneNumber.js → helpers/isViablePhoneNumber.js} +3 -4
- package/source/helpers/matchesEntirely.js +11 -0
- package/source/helpers/matchesEntirely.test.js +11 -0
- package/source/helpers/mergeArrays.js +24 -0
- package/source/helpers/mergeArrays.test.js +7 -0
- package/source/{parseDigits.js → helpers/parseDigits.js} +2 -4
- package/source/{parseDigits.test.js → helpers/parseDigits.test.js} +0 -0
- package/source/helpers/stripIddPrefix.js +30 -0
- package/source/helpers/stripIddPrefix.test.js +21 -0
- package/source/isPossibleNumber_.js +1 -1
- package/source/isValidNumberForRegion.js +1 -1
- package/source/parse.test.js +1 -28
- package/source/parseIncompletePhoneNumber.js +9 -6
- package/source/parse_.js +12 -405
- package/source/validate_.js +2 -2
- package/types.d.ts +16 -1
- package/build/IDD.js +0 -70
- package/build/IDD.js.map +0 -1
- package/build/IDD.test.js +0 -23
- package/build/IDD.test.js.map +0 -1
- package/build/RFC3966.js.map +0 -1
- package/build/RFC3966.test.js.map +0 -1
- package/build/checkNumberLength.js.map +0 -1
- package/build/checkNumberLength.test.js.map +0 -1
- package/build/extension.js.map +0 -1
- package/build/getNumberType_.js.map +0 -1
- package/build/isViablePhoneNumber.js.map +0 -1
- package/build/parseDigits.js.map +0 -1
- package/build/parseDigits.test.js.map +0 -1
- package/build/util.js.map +0 -1
- package/build/util.test.js +0 -16
- package/build/util.test.js.map +0 -1
- package/es6/IDD.js +0 -57
- package/es6/IDD.js.map +0 -1
- package/es6/IDD.test.js +0 -17
- package/es6/IDD.test.js.map +0 -1
- package/es6/RFC3966.js.map +0 -1
- package/es6/RFC3966.test.js.map +0 -1
- package/es6/checkNumberLength.js.map +0 -1
- package/es6/checkNumberLength.test.js.map +0 -1
- package/es6/extension.js.map +0 -1
- package/es6/getNumberType_.js.map +0 -1
- package/es6/isViablePhoneNumber.js.map +0 -1
- package/es6/parseDigits.js.map +0 -1
- package/es6/parseDigits.test.js.map +0 -1
- package/es6/util.js.map +0 -1
- package/es6/util.test.js +0 -13
- package/es6/util.test.js.map +0 -1
- package/source/IDD.js +0 -52
- package/source/IDD.test.js +0 -21
- package/source/util.js +0 -37
- package/source/util.test.js +0 -15
package/source/parse_.js
CHANGED
|
@@ -7,23 +7,24 @@ import {
|
|
|
7
7
|
VALID_DIGITS,
|
|
8
8
|
PLUS_CHARS,
|
|
9
9
|
MIN_LENGTH_FOR_NSN,
|
|
10
|
-
MAX_LENGTH_FOR_NSN
|
|
11
|
-
MAX_LENGTH_COUNTRY_CODE
|
|
10
|
+
MAX_LENGTH_FOR_NSN
|
|
12
11
|
} from './constants'
|
|
13
12
|
|
|
14
|
-
import { matchesEntirely } from './util'
|
|
15
13
|
import ParseError from './ParseError'
|
|
16
14
|
import Metadata from './metadata'
|
|
17
|
-
import isViablePhoneNumber from './isViablePhoneNumber'
|
|
18
|
-
import
|
|
15
|
+
import isViablePhoneNumber from './helpers/isViablePhoneNumber'
|
|
16
|
+
import extractExtension from './helpers/extension/extractExtension'
|
|
19
17
|
import parseIncompletePhoneNumber from './parseIncompletePhoneNumber'
|
|
20
18
|
import getCountryCallingCode from './getCountryCallingCode'
|
|
21
|
-
import getNumberType from './getNumberType_'
|
|
22
|
-
import checkNumberLength from './checkNumberLength'
|
|
23
19
|
import { isPossibleNumber } from './isPossibleNumber_'
|
|
24
|
-
import {
|
|
25
|
-
import { parseRFC3966 } from './RFC3966'
|
|
20
|
+
import { parseRFC3966 } from './helpers/RFC3966'
|
|
26
21
|
import PhoneNumber from './PhoneNumber'
|
|
22
|
+
import matchesEntirely from './helpers/matchesEntirely'
|
|
23
|
+
import extractCountryCallingCode from './helpers/extractCountryCallingCode'
|
|
24
|
+
import extractCountryCallingCodeFromInternationalNumberWithoutPlusSign from './helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign'
|
|
25
|
+
import extractNationalNumber from './helpers/extractNationalNumber'
|
|
26
|
+
import stripIddPrefix from './helpers/stripIddPrefix'
|
|
27
|
+
import getCountryByCallingCode from './helpers/getCountryByCallingCode'
|
|
27
28
|
|
|
28
29
|
// We don't allow input strings for parsing to be longer than 250 chars.
|
|
29
30
|
// This prevents malicious input from consuming CPU.
|
|
@@ -217,180 +218,6 @@ export function extractFormattedPhoneNumber(text, throwOnError) {
|
|
|
217
218
|
.replace(AFTER_PHONE_NUMBER_END_PATTERN, '')
|
|
218
219
|
}
|
|
219
220
|
|
|
220
|
-
/**
|
|
221
|
-
* Strips any national prefix (such as 0, 1) present in a
|
|
222
|
-
* (possibly incomplete) number provided.
|
|
223
|
-
* "Carrier codes" are only used in Colombia and Brazil,
|
|
224
|
-
* and only when dialing within those countries from a mobile phone to a fixed line number.
|
|
225
|
-
* Sometimes it won't actually strip national prefix
|
|
226
|
-
* and will instead prepend some digits to the `number`:
|
|
227
|
-
* for example, when number `2345678` is passed with `VI` country selected,
|
|
228
|
-
* it will return `{ number: "3402345678" }`, because `340` area code is prepended.
|
|
229
|
-
* @param {string} number — National number digits.
|
|
230
|
-
* @param {object} metadata — Metadata with country selected.
|
|
231
|
-
* @return {object} `{ nationalNumber: string, nationalPrefix: string? carrierCode: string? }`.
|
|
232
|
-
*/
|
|
233
|
-
export function extractNationalNumberFromPossiblyIncompleteNumber(number, metadata) {
|
|
234
|
-
if (number && metadata.numberingPlan.nationalPrefixForParsing()) {
|
|
235
|
-
// See METADATA.md for the description of
|
|
236
|
-
// `national_prefix_for_parsing` and `national_prefix_transform_rule`.
|
|
237
|
-
// Attempt to parse the first digits as a national prefix.
|
|
238
|
-
const prefixPattern = new RegExp('^(?:' + metadata.numberingPlan.nationalPrefixForParsing() + ')')
|
|
239
|
-
const prefixMatch = prefixPattern.exec(number)
|
|
240
|
-
if (prefixMatch) {
|
|
241
|
-
let nationalNumber
|
|
242
|
-
let carrierCode
|
|
243
|
-
// https://gitlab.com/catamphetamine/libphonenumber-js/-/blob/master/METADATA.md#national_prefix_for_parsing--national_prefix_transform_rule
|
|
244
|
-
// If a `national_prefix_for_parsing` has any "capturing groups"
|
|
245
|
-
// then it means that the national (significant) number is equal to
|
|
246
|
-
// those "capturing groups" transformed via `national_prefix_transform_rule`,
|
|
247
|
-
// and nothing could be said about the actual national prefix:
|
|
248
|
-
// what is it and was it even there.
|
|
249
|
-
// If a `national_prefix_for_parsing` doesn't have any "capturing groups",
|
|
250
|
-
// then everything it matches is a national prefix.
|
|
251
|
-
// To determine whether `national_prefix_for_parsing` matched any
|
|
252
|
-
// "capturing groups", the value of the result of calling `.exec()`
|
|
253
|
-
// is looked at, and if it has non-undefined values where there're
|
|
254
|
-
// "capturing groups" in the regular expression, then it means
|
|
255
|
-
// that "capturing groups" have been matched.
|
|
256
|
-
// It's not possible to tell whether there'll be any "capturing gropus"
|
|
257
|
-
// before the matching process, because a `national_prefix_for_parsing`
|
|
258
|
-
// could exhibit both behaviors.
|
|
259
|
-
const capturedGroupsCount = prefixMatch.length - 1
|
|
260
|
-
const hasCapturedGroups = capturedGroupsCount > 0 && prefixMatch[capturedGroupsCount]
|
|
261
|
-
if (metadata.nationalPrefixTransformRule() && hasCapturedGroups) {
|
|
262
|
-
nationalNumber = number.replace(
|
|
263
|
-
prefixPattern,
|
|
264
|
-
metadata.nationalPrefixTransformRule()
|
|
265
|
-
)
|
|
266
|
-
// If there's more than one captured group,
|
|
267
|
-
// then carrier code is the second one.
|
|
268
|
-
if (capturedGroupsCount > 1) {
|
|
269
|
-
carrierCode = prefixMatch[1]
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
// If there're no "capturing groups",
|
|
273
|
-
// or if there're "capturing groups" but no
|
|
274
|
-
// `national_prefix_transform_rule`,
|
|
275
|
-
// then just strip the national prefix from the number,
|
|
276
|
-
// and possibly a carrier code.
|
|
277
|
-
// Seems like there could be more.
|
|
278
|
-
else {
|
|
279
|
-
// `prefixBeforeNationalNumber` is the whole substring matched by
|
|
280
|
-
// the `national_prefix_for_parsing` regular expression.
|
|
281
|
-
// There seem to be no guarantees that it's just a national prefix.
|
|
282
|
-
// For example, if there's a carrier code, it's gonna be a
|
|
283
|
-
// part of `prefixBeforeNationalNumber` too.
|
|
284
|
-
const prefixBeforeNationalNumber = prefixMatch[0]
|
|
285
|
-
nationalNumber = number.slice(prefixBeforeNationalNumber.length)
|
|
286
|
-
// If there's at least one captured group,
|
|
287
|
-
// then carrier code is the first one.
|
|
288
|
-
if (hasCapturedGroups) {
|
|
289
|
-
carrierCode = prefixMatch[1]
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
// Tries to guess whether a national prefix was present in the input.
|
|
293
|
-
// This is not something copy-pasted from Google's library:
|
|
294
|
-
// they don't seem to have an equivalent for that.
|
|
295
|
-
// So this isn't an "officially approved" way of doing something like that.
|
|
296
|
-
// But since there seems no other existing method, this library uses it.
|
|
297
|
-
let nationalPrefix
|
|
298
|
-
if (hasCapturedGroups) {
|
|
299
|
-
const possiblePositionOfTheFirstCapturedGroup = number.indexOf(prefixMatch[1])
|
|
300
|
-
const possibleNationalPrefix = number.slice(0, possiblePositionOfTheFirstCapturedGroup)
|
|
301
|
-
// Example: an Argentinian (AR) phone number `0111523456789`.
|
|
302
|
-
// `prefixMatch[0]` is `01115`, and `$1` is `11`,
|
|
303
|
-
// and the rest of the phone number is `23456789`.
|
|
304
|
-
// The national number is transformed via `9$1` to `91123456789`.
|
|
305
|
-
// National prefix `0` is detected being present at the start.
|
|
306
|
-
// if (possibleNationalPrefix.indexOf(metadata.numberingPlan.nationalPrefix()) === 0) {
|
|
307
|
-
if (possibleNationalPrefix === metadata.numberingPlan.nationalPrefix()) {
|
|
308
|
-
nationalPrefix = metadata.numberingPlan.nationalPrefix()
|
|
309
|
-
}
|
|
310
|
-
} else {
|
|
311
|
-
nationalPrefix = prefixMatch[0]
|
|
312
|
-
}
|
|
313
|
-
return {
|
|
314
|
-
nationalNumber,
|
|
315
|
-
nationalPrefix,
|
|
316
|
-
carrierCode
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return {
|
|
321
|
-
nationalNumber: number
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// In some countries, the same digit could be a national prefix
|
|
326
|
-
// or a leading digit of a valid phone number.
|
|
327
|
-
// For example, in Russia, national prefix is `8`,
|
|
328
|
-
// and also `800 555 35 35` is a valid number
|
|
329
|
-
// in which `8` is not a national prefix, but the first digit
|
|
330
|
-
// of a national (significant) number.
|
|
331
|
-
// Same's with Belarus:
|
|
332
|
-
// `82004910060` is a valid national (significant) number,
|
|
333
|
-
// but `2004910060` is not.
|
|
334
|
-
// To support such cases (to prevent the code from always stripping
|
|
335
|
-
// national prefix), a condition is imposed: a national prefix
|
|
336
|
-
// is not extracted when the original number is "viable" and the
|
|
337
|
-
// resultant number is not, a "viable" national number being the one
|
|
338
|
-
// that matches `national_number_pattern`.
|
|
339
|
-
function shouldExtractNationalPrefix(number, nationalSignificantNumber, metadata) {
|
|
340
|
-
// The equivalent in Google's code is:
|
|
341
|
-
// https://github.com/google/libphonenumber/blob/e326fa1fc4283bb05eb35cb3c15c18f98a31af33/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L2969-L3004
|
|
342
|
-
if (matchesEntirely(number, metadata.nationalNumberPattern()) &&
|
|
343
|
-
!matchesEntirely(nationalSignificantNumber, metadata.nationalNumberPattern())) {
|
|
344
|
-
return false
|
|
345
|
-
}
|
|
346
|
-
// Just "possible" number check would be more relaxed, so it's not used.
|
|
347
|
-
// if (isPossibleNumber(number, metadata) &&
|
|
348
|
-
// !isPossibleNumber(numberWithNationalPrefixExtracted, metadata)) {
|
|
349
|
-
// return false
|
|
350
|
-
// }
|
|
351
|
-
return true
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
export function findCountryCode(callingCode, nationalPhoneNumber, metadata) {
|
|
355
|
-
/* istanbul ignore if */
|
|
356
|
-
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
357
|
-
if (metadata.isNonGeographicCallingCode(callingCode)) {
|
|
358
|
-
return '001'
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
// Is always non-empty, because `callingCode` is always valid
|
|
362
|
-
const possibleCountries = metadata.getCountryCodesForCallingCode(callingCode)
|
|
363
|
-
if (!possibleCountries) {
|
|
364
|
-
return
|
|
365
|
-
}
|
|
366
|
-
// If there's just one country corresponding to the country code,
|
|
367
|
-
// then just return it, without further phone number digits validation.
|
|
368
|
-
if (possibleCountries.length === 1) {
|
|
369
|
-
return possibleCountries[0]
|
|
370
|
-
}
|
|
371
|
-
return _findCountryCode(possibleCountries, nationalPhoneNumber, metadata.metadata)
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Changes `metadata` `country`.
|
|
375
|
-
function _findCountryCode(possibleCountries, nationalPhoneNumber, metadata) {
|
|
376
|
-
metadata = new Metadata(metadata)
|
|
377
|
-
for (const country of possibleCountries) {
|
|
378
|
-
metadata.country(country)
|
|
379
|
-
// Leading digits check would be the simplest one
|
|
380
|
-
if (metadata.leadingDigits()) {
|
|
381
|
-
if (nationalPhoneNumber &&
|
|
382
|
-
nationalPhoneNumber.search(metadata.leadingDigits()) === 0) {
|
|
383
|
-
return country
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
// Else perform full validation with all of those
|
|
387
|
-
// fixed-line/mobile/etc regular expressions.
|
|
388
|
-
else if (getNumberType({ phone: nationalPhoneNumber, country }, undefined, metadata.metadata)) {
|
|
389
|
-
return country
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
221
|
/**
|
|
395
222
|
* @param {string} text - Input.
|
|
396
223
|
* @return {object} `{ ?number, ?ext }`.
|
|
@@ -495,7 +322,7 @@ function parsePhoneNumber(
|
|
|
495
322
|
// get their countries populated with the full set of
|
|
496
323
|
// "phone number type" regular expressions.
|
|
497
324
|
//
|
|
498
|
-
const exactCountry =
|
|
325
|
+
const exactCountry = getCountryByCallingCode(countryCallingCode, nationalNumber, metadata)
|
|
499
326
|
if (exactCountry) {
|
|
500
327
|
country = exactCountry
|
|
501
328
|
/* istanbul ignore if */
|
|
@@ -514,224 +341,4 @@ function parsePhoneNumber(
|
|
|
514
341
|
nationalNumber,
|
|
515
342
|
carrierCode
|
|
516
343
|
}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
* Strips national prefix and carrier code from a complete phone number.
|
|
521
|
-
* The difference from the non-"FromCompleteNumber" function is that
|
|
522
|
-
* it won't extract national prefix if the resultant number is too short
|
|
523
|
-
* to be a complete number for the selected phone numbering plan.
|
|
524
|
-
* @param {string} number — Complete phone number digits.
|
|
525
|
-
* @param {Metadata} metadata — Metadata with a phone numbering plan selected.
|
|
526
|
-
* @return {object} `{ nationalNumber: string, carrierCode: string? }`.
|
|
527
|
-
*/
|
|
528
|
-
export function extractNationalNumber(number, metadata) {
|
|
529
|
-
// Parsing national prefixes and carrier codes
|
|
530
|
-
// is only required for local phone numbers
|
|
531
|
-
// but some people don't understand that
|
|
532
|
-
// and sometimes write international phone numbers
|
|
533
|
-
// with national prefixes (or maybe even carrier codes).
|
|
534
|
-
// http://ucken.blogspot.ru/2016/03/trunk-prefixes-in-skype4b.html
|
|
535
|
-
// Google's original library forgives such mistakes
|
|
536
|
-
// and so does this library, because it has been requested:
|
|
537
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/127
|
|
538
|
-
const {
|
|
539
|
-
nationalNumber,
|
|
540
|
-
carrierCode
|
|
541
|
-
} = extractNationalNumberFromPossiblyIncompleteNumber(
|
|
542
|
-
number,
|
|
543
|
-
metadata
|
|
544
|
-
)
|
|
545
|
-
if (!shouldExtractNationalPrefix(number, nationalNumber, metadata)) {
|
|
546
|
-
// Don't strip the national prefix.
|
|
547
|
-
return { nationalNumber: number }
|
|
548
|
-
}
|
|
549
|
-
// If a national prefix has been extracted, check to see
|
|
550
|
-
// if the resultant number isn't too short.
|
|
551
|
-
// Same code in Google's `libphonenumber`:
|
|
552
|
-
// https://github.com/google/libphonenumber/blob/e326fa1fc4283bb05eb35cb3c15c18f98a31af33/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L3291-L3302
|
|
553
|
-
// For some reason, they do this check right after the `national_number_pattern` check
|
|
554
|
-
// this library does in `shouldExtractNationalPrefix()` function.
|
|
555
|
-
// Why is there a second "resultant" number validity check?
|
|
556
|
-
// They don't provide an explanation.
|
|
557
|
-
// This library just copies the behavior.
|
|
558
|
-
if (number.length !== nationalNumber.length + (carrierCode ? carrierCode.length : 0)) {
|
|
559
|
-
// If not using legacy generated metadata (before version `1.0.18`)
|
|
560
|
-
// then it has "possible lengths", so use those to validate the number length.
|
|
561
|
-
if (metadata.possibleLengths()) {
|
|
562
|
-
// "We require that the NSN remaining after stripping the national prefix and
|
|
563
|
-
// carrier code be long enough to be a possible length for the region.
|
|
564
|
-
// Otherwise, we don't do the stripping, since the original number could be
|
|
565
|
-
// a valid short number."
|
|
566
|
-
// https://github.com/google/libphonenumber/blob/876268eb1ad6cdc1b7b5bef17fc5e43052702d57/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L3236-L3250
|
|
567
|
-
switch (checkNumberLength(nationalNumber, metadata)) {
|
|
568
|
-
case 'TOO_SHORT':
|
|
569
|
-
case 'INVALID_LENGTH':
|
|
570
|
-
// case 'IS_POSSIBLE_LOCAL_ONLY':
|
|
571
|
-
// Don't strip the national prefix.
|
|
572
|
-
return { nationalNumber: number }
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
return { nationalNumber, carrierCode }
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* Converts a phone number digits (possibly with a `+`)
|
|
581
|
-
* into a calling code and the rest phone number digits.
|
|
582
|
-
* The "rest phone number digits" could include
|
|
583
|
-
* a national prefix, carrier code, and national
|
|
584
|
-
* (significant) number.
|
|
585
|
-
* @param {string} number — Phone number digits (possibly with a `+`).
|
|
586
|
-
* @param {string} [country] — Default country.
|
|
587
|
-
* @param {string} [callingCode] — Default calling code (some phone numbering plans are non-geographic).
|
|
588
|
-
* @param {object} metadata
|
|
589
|
-
* @return {object} `{ countryCallingCode: string?, number: string }`
|
|
590
|
-
* @example
|
|
591
|
-
* // Returns `{ countryCallingCode: "1", number: "2133734253" }`.
|
|
592
|
-
* extractCountryCallingCode('2133734253', 'US', null, metadata)
|
|
593
|
-
* extractCountryCallingCode('2133734253', null, '1', metadata)
|
|
594
|
-
* extractCountryCallingCode('+12133734253', null, null, metadata)
|
|
595
|
-
* extractCountryCallingCode('+12133734253', 'RU', null, metadata)
|
|
596
|
-
*/
|
|
597
|
-
export function extractCountryCallingCode(
|
|
598
|
-
number,
|
|
599
|
-
country,
|
|
600
|
-
callingCode,
|
|
601
|
-
metadata
|
|
602
|
-
) {
|
|
603
|
-
if (!number) {
|
|
604
|
-
return {}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
// If this is not an international phone number,
|
|
608
|
-
// then either extract an "IDD" prefix, or extract a
|
|
609
|
-
// country calling code from a number by autocorrecting it
|
|
610
|
-
// by prepending a leading `+` in cases when it starts
|
|
611
|
-
// with the country calling code.
|
|
612
|
-
// https://wikitravel.org/en/International_dialling_prefix
|
|
613
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/376
|
|
614
|
-
if (number[0] !== '+') {
|
|
615
|
-
// Convert an "out-of-country" dialing phone number
|
|
616
|
-
// to a proper international phone number.
|
|
617
|
-
const numberWithoutIDD = stripIDDPrefix(number, country, callingCode, metadata)
|
|
618
|
-
// If an IDD prefix was stripped then
|
|
619
|
-
// convert the number to international one
|
|
620
|
-
// for subsequent parsing.
|
|
621
|
-
if (numberWithoutIDD && numberWithoutIDD !== number) {
|
|
622
|
-
number = '+' + numberWithoutIDD
|
|
623
|
-
} else {
|
|
624
|
-
// Check to see if the number starts with the country calling code
|
|
625
|
-
// for the default country. If so, we remove the country calling code,
|
|
626
|
-
// and do some checks on the validity of the number before and after.
|
|
627
|
-
// https://github.com/catamphetamine/libphonenumber-js/issues/376
|
|
628
|
-
if (country || callingCode) {
|
|
629
|
-
const {
|
|
630
|
-
countryCallingCode,
|
|
631
|
-
number: shorterNumber
|
|
632
|
-
} = extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(
|
|
633
|
-
number,
|
|
634
|
-
country,
|
|
635
|
-
callingCode,
|
|
636
|
-
metadata
|
|
637
|
-
)
|
|
638
|
-
if (countryCallingCode) {
|
|
639
|
-
return {
|
|
640
|
-
countryCallingCode,
|
|
641
|
-
number: shorterNumber
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
return { number }
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
// Fast abortion: country codes do not begin with a '0'
|
|
650
|
-
if (number[1] === '0') {
|
|
651
|
-
return {}
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
metadata = new Metadata(metadata)
|
|
655
|
-
|
|
656
|
-
// The thing with country phone codes
|
|
657
|
-
// is that they are orthogonal to each other
|
|
658
|
-
// i.e. there's no such country phone code A
|
|
659
|
-
// for which country phone code B exists
|
|
660
|
-
// where B starts with A.
|
|
661
|
-
// Therefore, while scanning digits,
|
|
662
|
-
// if a valid country code is found,
|
|
663
|
-
// that means that it is the country code.
|
|
664
|
-
//
|
|
665
|
-
let i = 2
|
|
666
|
-
while (i - 1 <= MAX_LENGTH_COUNTRY_CODE && i <= number.length) {
|
|
667
|
-
const countryCallingCode = number.slice(1, i)
|
|
668
|
-
if (metadata.hasCallingCode(countryCallingCode)) {
|
|
669
|
-
metadata.selectNumberingPlan(countryCallingCode)
|
|
670
|
-
return {
|
|
671
|
-
countryCallingCode,
|
|
672
|
-
number: number.slice(i)
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
i++
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
return {}
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* Sometimes some people incorrectly input international phone numbers
|
|
683
|
-
* without the leading `+`. This function corrects such input.
|
|
684
|
-
* @param {string} number — Phone number digits.
|
|
685
|
-
* @param {string?} country
|
|
686
|
-
* @param {string?} callingCode
|
|
687
|
-
* @param {object} metadata
|
|
688
|
-
* @return {object} `{ countryCallingCode: string?, number: string }`.
|
|
689
|
-
*/
|
|
690
|
-
export function extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(
|
|
691
|
-
number,
|
|
692
|
-
country,
|
|
693
|
-
callingCode,
|
|
694
|
-
metadata
|
|
695
|
-
) {
|
|
696
|
-
const countryCallingCode = country ? getCountryCallingCode(country, metadata) : callingCode
|
|
697
|
-
if (number.indexOf(countryCallingCode) === 0) {
|
|
698
|
-
metadata = new Metadata(metadata)
|
|
699
|
-
metadata.selectNumberingPlan(country, callingCode)
|
|
700
|
-
const possibleShorterNumber = number.slice(countryCallingCode.length)
|
|
701
|
-
const {
|
|
702
|
-
nationalNumber: possibleShorterNationalNumber,
|
|
703
|
-
} = extractNationalNumber(
|
|
704
|
-
possibleShorterNumber,
|
|
705
|
-
metadata
|
|
706
|
-
)
|
|
707
|
-
const {
|
|
708
|
-
nationalNumber
|
|
709
|
-
} = extractNationalNumber(
|
|
710
|
-
number,
|
|
711
|
-
metadata
|
|
712
|
-
)
|
|
713
|
-
// If the number was not valid before but is valid now,
|
|
714
|
-
// or if it was too long before, we consider the number
|
|
715
|
-
// with the country calling code stripped to be a better result
|
|
716
|
-
// and keep that instead.
|
|
717
|
-
// For example, in Germany (+49), `49` is a valid area code,
|
|
718
|
-
// so if a number starts with `49`, it could be both a valid
|
|
719
|
-
// national German number or an international number without
|
|
720
|
-
// a leading `+`.
|
|
721
|
-
if (
|
|
722
|
-
(
|
|
723
|
-
!matchesEntirely(nationalNumber, metadata.nationalNumberPattern())
|
|
724
|
-
&&
|
|
725
|
-
matchesEntirely(possibleShorterNationalNumber, metadata.nationalNumberPattern())
|
|
726
|
-
)
|
|
727
|
-
||
|
|
728
|
-
checkNumberLength(nationalNumber, metadata) === 'TOO_LONG'
|
|
729
|
-
) {
|
|
730
|
-
return {
|
|
731
|
-
countryCallingCode,
|
|
732
|
-
number: possibleShorterNumber
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
return { number }
|
|
737
|
-
}
|
|
344
|
+
}
|
package/source/validate_.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Metadata from './metadata'
|
|
2
|
-
import
|
|
3
|
-
import getNumberType from './
|
|
2
|
+
import matchesEntirely from './helpers/matchesEntirely'
|
|
3
|
+
import getNumberType from './helpers/getNumberType'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Checks if a given phone number is valid.
|
package/types.d.ts
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
// The rationale for having a separate `CountryCode` type instead of just a `string`:
|
|
2
|
+
// https://github.com/catamphetamine/libphonenumber-js/issues/170#issuecomment-363156068
|
|
3
|
+
export type CountryCode = 'AC' | 'AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AO' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' | 'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FK' | 'FM' | 'FO' | 'FR' | 'GA' | 'GB' | 'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' | 'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GT' | 'GU' | 'GW' | 'GY' | 'HK' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MH' | 'MK' | 'ML' | 'MM' | 'MN' | 'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PR' | 'PS' | 'PT' | 'PW' | 'PY' | 'QA' | 'RE' | 'RO' | 'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' | 'SX' | 'SY' | 'SZ' | 'TA' | 'TC' | 'TD' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'XK' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW';
|
|
2
4
|
|
|
3
5
|
export type CountryCallingCodes = {
|
|
4
6
|
[countryCallingCode: string]: CountryCode[];
|
|
5
7
|
};
|
|
6
8
|
|
|
7
9
|
export type Countries = {
|
|
10
|
+
// Metadata here is a compressed one,
|
|
11
|
+
// so a country's data is just an array of some properties
|
|
12
|
+
// instead of a JSON object of shape:
|
|
13
|
+
// {
|
|
14
|
+
// phone_code: string,
|
|
15
|
+
// idd_prefix: string,
|
|
16
|
+
// national_number_pattern: string,
|
|
17
|
+
// types: object,
|
|
18
|
+
// examples: object,
|
|
19
|
+
// formats: object[]?,
|
|
20
|
+
// possible_lengths: number[],
|
|
21
|
+
// ...
|
|
22
|
+
// }
|
|
8
23
|
[country in CountryCode]: any[];
|
|
9
24
|
};
|
|
10
25
|
|
package/build/IDD.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getIDDPrefix = getIDDPrefix;
|
|
7
|
-
exports.stripIDDPrefix = stripIDDPrefix;
|
|
8
|
-
|
|
9
|
-
var _metadata = _interopRequireDefault(require("./metadata"));
|
|
10
|
-
|
|
11
|
-
var _constants = require("./constants");
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
|
-
|
|
15
|
-
var CAPTURING_DIGIT_PATTERN = new RegExp('([' + _constants.VALID_DIGITS + '])');
|
|
16
|
-
/**
|
|
17
|
-
* Pattern that makes it easy to distinguish whether a region has a single
|
|
18
|
-
* international dialing prefix or not. If a region has a single international
|
|
19
|
-
* prefix (e.g. 011 in USA), it will be represented as a string that contains
|
|
20
|
-
* a sequence of ASCII digits, and possibly a tilde, which signals waiting for
|
|
21
|
-
* the tone. If there are multiple available international prefixes in a
|
|
22
|
-
* region, they will be represented as a regex string that always contains one
|
|
23
|
-
* or more characters that are not ASCII digits or a tilde.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
var SINGLE_IDD_PREFIX = /^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/; // For regions that have multiple IDD prefixes
|
|
27
|
-
// a preferred IDD prefix is returned.
|
|
28
|
-
|
|
29
|
-
function getIDDPrefix(country, callingCode, metadata) {
|
|
30
|
-
var countryMetadata = new _metadata["default"](metadata);
|
|
31
|
-
countryMetadata.selectNumberingPlan(country, callingCode);
|
|
32
|
-
|
|
33
|
-
if (SINGLE_IDD_PREFIX.test(countryMetadata.IDDPrefix())) {
|
|
34
|
-
return countryMetadata.IDDPrefix();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return countryMetadata.defaultIDDPrefix();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function stripIDDPrefix(number, country, callingCode, metadata) {
|
|
41
|
-
if (!country) {
|
|
42
|
-
return;
|
|
43
|
-
} // Check if the number is IDD-prefixed.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var countryMetadata = new _metadata["default"](metadata);
|
|
47
|
-
countryMetadata.selectNumberingPlan(country, callingCode);
|
|
48
|
-
var IDDPrefixPattern = new RegExp(countryMetadata.IDDPrefix());
|
|
49
|
-
|
|
50
|
-
if (number.search(IDDPrefixPattern) !== 0) {
|
|
51
|
-
return;
|
|
52
|
-
} // Strip IDD prefix.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
number = number.slice(number.match(IDDPrefixPattern)[0].length); // If there're any digits after an IDD prefix,
|
|
56
|
-
// then those digits are a country calling code.
|
|
57
|
-
// Since no country code starts with a `0`,
|
|
58
|
-
// the code below validates that the next digit (if present) is not `0`.
|
|
59
|
-
|
|
60
|
-
var matchedGroups = number.match(CAPTURING_DIGIT_PATTERN);
|
|
61
|
-
|
|
62
|
-
if (matchedGroups && matchedGroups[1] != null && matchedGroups[1].length > 0) {
|
|
63
|
-
if (matchedGroups[1] === '0') {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return number;
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=IDD.js.map
|
package/build/IDD.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/IDD.js"],"names":["CAPTURING_DIGIT_PATTERN","RegExp","VALID_DIGITS","SINGLE_IDD_PREFIX","getIDDPrefix","country","callingCode","metadata","countryMetadata","Metadata","selectNumberingPlan","test","IDDPrefix","defaultIDDPrefix","stripIDDPrefix","number","IDDPrefixPattern","search","slice","match","length","matchedGroups"],"mappings":";;;;;;;;AAAA;;AACA;;;;AAEA,IAAMA,uBAAuB,GAAG,IAAIC,MAAJ,CAAW,OAAOC,uBAAP,GAAsB,IAAjC,CAAhC;AAEA;;;;;;;;;;AASA,IAAMC,iBAAiB,GAAG,wCAA1B,C,CAEA;AACA;;AACO,SAASC,YAAT,CAAsBC,OAAtB,EAA+BC,WAA/B,EAA4CC,QAA5C,EAAsD;AAC5D,MAAMC,eAAe,GAAG,IAAIC,oBAAJ,CAAaF,QAAb,CAAxB;AACAC,EAAAA,eAAe,CAACE,mBAAhB,CAAoCL,OAApC,EAA6CC,WAA7C;;AACA,MAAIH,iBAAiB,CAACQ,IAAlB,CAAuBH,eAAe,CAACI,SAAhB,EAAvB,CAAJ,EAAyD;AACxD,WAAOJ,eAAe,CAACI,SAAhB,EAAP;AACA;;AACD,SAAOJ,eAAe,CAACK,gBAAhB,EAAP;AACA;;AAEM,SAASC,cAAT,CAAwBC,MAAxB,EAAgCV,OAAhC,EAAyCC,WAAzC,EAAsDC,QAAtD,EAAgE;AACtE,MAAI,CAACF,OAAL,EAAc;AACb;AACA,GAHqE,CAItE;;;AACA,MAAMG,eAAe,GAAG,IAAIC,oBAAJ,CAAaF,QAAb,CAAxB;AACAC,EAAAA,eAAe,CAACE,mBAAhB,CAAoCL,OAApC,EAA6CC,WAA7C;AACA,MAAMU,gBAAgB,GAAG,IAAIf,MAAJ,CAAWO,eAAe,CAACI,SAAhB,EAAX,CAAzB;;AACA,MAAIG,MAAM,CAACE,MAAP,CAAcD,gBAAd,MAAoC,CAAxC,EAA2C;AAC1C;AACA,GAVqE,CAWtE;;;AACAD,EAAAA,MAAM,GAAGA,MAAM,CAACG,KAAP,CAAaH,MAAM,CAACI,KAAP,CAAaH,gBAAb,EAA+B,CAA/B,EAAkCI,MAA/C,CAAT,CAZsE,CAatE;AACA;AACA;AACA;;AACA,MAAMC,aAAa,GAAGN,MAAM,CAACI,KAAP,CAAanB,uBAAb,CAAtB;;AACA,MAAIqB,aAAa,IAAIA,aAAa,CAAC,CAAD,CAAb,IAAoB,IAArC,IAA6CA,aAAa,CAAC,CAAD,CAAb,CAAiBD,MAAjB,GAA0B,CAA3E,EAA8E;AAC7E,QAAIC,aAAa,CAAC,CAAD,CAAb,KAAqB,GAAzB,EAA8B;AAC7B;AACA;AACD;;AACD,SAAON,MAAP;AACA","sourcesContent":["import Metadata from './metadata'\r\nimport { VALID_DIGITS } from './constants'\r\n\r\nconst CAPTURING_DIGIT_PATTERN = new RegExp('([' + VALID_DIGITS + '])')\r\n\r\n/**\r\n * Pattern that makes it easy to distinguish whether a region has a single\r\n * international dialing prefix or not. If a region has a single international\r\n * prefix (e.g. 011 in USA), it will be represented as a string that contains\r\n * a sequence of ASCII digits, and possibly a tilde, which signals waiting for\r\n * the tone. If there are multiple available international prefixes in a\r\n * region, they will be represented as a regex string that always contains one\r\n * or more characters that are not ASCII digits or a tilde.\r\n */\r\nconst SINGLE_IDD_PREFIX = /^[\\d]+(?:[~\\u2053\\u223C\\uFF5E][\\d]+)?$/\r\n\r\n// For regions that have multiple IDD prefixes\r\n// a preferred IDD prefix is returned.\r\nexport function getIDDPrefix(country, callingCode, metadata) {\r\n\tconst countryMetadata = new Metadata(metadata)\r\n\tcountryMetadata.selectNumberingPlan(country, callingCode)\r\n\tif (SINGLE_IDD_PREFIX.test(countryMetadata.IDDPrefix())) {\r\n\t\treturn countryMetadata.IDDPrefix()\r\n\t}\r\n\treturn countryMetadata.defaultIDDPrefix()\r\n}\r\n\r\nexport function stripIDDPrefix(number, country, callingCode, metadata) {\r\n\tif (!country) {\r\n\t\treturn\r\n\t}\r\n\t// Check if the number is IDD-prefixed.\r\n\tconst countryMetadata = new Metadata(metadata)\r\n\tcountryMetadata.selectNumberingPlan(country, callingCode)\r\n\tconst IDDPrefixPattern = new RegExp(countryMetadata.IDDPrefix())\r\n\tif (number.search(IDDPrefixPattern) !== 0) {\r\n\t\treturn\r\n\t}\r\n\t// Strip IDD prefix.\r\n\tnumber = number.slice(number.match(IDDPrefixPattern)[0].length)\r\n\t// If there're any digits after an IDD prefix,\r\n\t// then those digits are a country calling code.\r\n\t// Since no country code starts with a `0`,\r\n\t// the code below validates that the next digit (if present) is not `0`.\r\n\tconst matchedGroups = number.match(CAPTURING_DIGIT_PATTERN)\r\n\tif (matchedGroups && matchedGroups[1] != null && matchedGroups[1].length > 0) {\r\n\t\tif (matchedGroups[1] === '0') {\r\n\t\t\treturn\r\n\t\t}\r\n\t}\r\n\treturn number\r\n}"],"file":"IDD.js"}
|
package/build/IDD.test.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _IDD = require("./IDD");
|
|
4
|
-
|
|
5
|
-
var _metadataMin = _interopRequireDefault(require("../metadata.min.json"));
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
|
-
|
|
9
|
-
describe('IDD', function () {
|
|
10
|
-
it('should strip a valid IDD prefix', function () {
|
|
11
|
-
(0, _IDD.stripIDDPrefix)('01178005553535', 'US', '1', _metadataMin["default"]).should.equal('78005553535');
|
|
12
|
-
});
|
|
13
|
-
it('should strip a valid IDD prefix (no country calling code)', function () {
|
|
14
|
-
(0, _IDD.stripIDDPrefix)('011', 'US', '1', _metadataMin["default"]).should.equal('');
|
|
15
|
-
});
|
|
16
|
-
it('should strip a valid IDD prefix (valid country calling code)', function () {
|
|
17
|
-
(0, _IDD.stripIDDPrefix)('0117', 'US', '1', _metadataMin["default"]).should.equal('7');
|
|
18
|
-
});
|
|
19
|
-
it('should strip a valid IDD prefix (not a valid country calling code)', function () {
|
|
20
|
-
expect((0, _IDD.stripIDDPrefix)('0110', 'US', '1', _metadataMin["default"])).to.be.undefined;
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
//# sourceMappingURL=IDD.test.js.map
|
package/build/IDD.test.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/IDD.test.js"],"names":["describe","it","metadata","should","equal","expect","to","be","undefined"],"mappings":";;AAAA;;AAEA;;;;AAEAA,QAAQ,CAAC,KAAD,EAAQ,YAAM;AACrBC,EAAAA,EAAE,CAAC,iCAAD,EAAoC,YAAM;AAC3C,6BAAe,gBAAf,EAAiC,IAAjC,EAAuC,GAAvC,EAA4CC,uBAA5C,EAAsDC,MAAtD,CAA6DC,KAA7D,CAAmE,aAAnE;AACA,GAFC,CAAF;AAIAH,EAAAA,EAAE,CAAC,2DAAD,EAA8D,YAAM;AACrE,6BAAe,KAAf,EAAsB,IAAtB,EAA4B,GAA5B,EAAiCC,uBAAjC,EAA2CC,MAA3C,CAAkDC,KAAlD,CAAwD,EAAxD;AACA,GAFC,CAAF;AAIAH,EAAAA,EAAE,CAAC,8DAAD,EAAiE,YAAM;AACxE,6BAAe,MAAf,EAAuB,IAAvB,EAA6B,GAA7B,EAAkCC,uBAAlC,EAA4CC,MAA5C,CAAmDC,KAAnD,CAAyD,GAAzD;AACA,GAFC,CAAF;AAIAH,EAAAA,EAAE,CAAC,oEAAD,EAAuE,YAAM;AAC9EI,IAAAA,MAAM,CAAC,yBAAe,MAAf,EAAuB,IAAvB,EAA6B,GAA7B,EAAkCH,uBAAlC,CAAD,CAAN,CAAoDI,EAApD,CAAuDC,EAAvD,CAA0DC,SAA1D;AACA,GAFC,CAAF;AAGA,CAhBO,CAAR","sourcesContent":["import { stripIDDPrefix } from './IDD'\r\n\r\nimport metadata from '../metadata.min.json'\r\n\r\ndescribe('IDD', () => {\r\n\tit('should strip a valid IDD prefix', () => {\r\n\t\tstripIDDPrefix('01178005553535', 'US', '1', metadata).should.equal('78005553535')\r\n\t})\r\n\r\n\tit('should strip a valid IDD prefix (no country calling code)', () => {\r\n\t\tstripIDDPrefix('011', 'US', '1', metadata).should.equal('')\r\n\t})\r\n\r\n\tit('should strip a valid IDD prefix (valid country calling code)', () => {\r\n\t\tstripIDDPrefix('0117', 'US', '1', metadata).should.equal('7')\r\n\t})\r\n\r\n\tit('should strip a valid IDD prefix (not a valid country calling code)', () => {\r\n\t\texpect(stripIDDPrefix('0110', 'US', '1', metadata)).to.be.undefined\r\n\t})\r\n})"],"file":"IDD.test.js"}
|
package/build/RFC3966.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/RFC3966.js"],"names":["parseRFC3966","text","number","ext","replace","split","part","name","value","result","formatRFC3966","Error"],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;AAEA;;AAEA;;;;AAIO,SAASA,YAAT,CAAsBC,IAAtB,EACP;AACC,MAAIC,MAAJ;AACA,MAAIC,GAAJ,CAFD,CAIC;;AACAF,EAAAA,IAAI,GAAGA,IAAI,CAACG,OAAL,CAAa,OAAb,EAAsB,MAAtB,CAAP;;AAEA,uBAAmBH,IAAI,CAACI,KAAL,CAAW,GAAX,CAAnB,kHACA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,QADWC,IACX;;AAAA,sBACuBA,IAAI,CAACD,KAAL,CAAW,GAAX,CADvB;AAAA;AAAA,QACQE,IADR;AAAA,QACcC,KADd;;AAEC,YAAQD,IAAR;AAEC,WAAK,KAAL;AACCL,QAAAA,MAAM,GAAGM,KAAT;AACA;;AACD,WAAK,KAAL;AACCL,QAAAA,GAAG,GAAGK,KAAN;AACA;;AACD,WAAK,eAAL;AACC;AACA;AACA,YAAIA,KAAK,CAAC,CAAD,CAAL,KAAa,GAAjB,EAAsB;AACrBN,UAAAA,MAAM,GAAGM,KAAK,GAAGN,MAAjB;AACA;;AACD;AAdF;AAgBA,GA1BF,CA4BC;;;AACA,MAAI,CAAC,qCAAoBA,MAApB,CAAL,EACA;AACC,WAAO,EAAP;AACA;;AAED,MAAMO,MAAM,GAAG;AAAEP,IAAAA,MAAM,EAANA;AAAF,GAAf;;AACA,MAAIC,GAAJ,EAAS;AACRM,IAAAA,MAAM,CAACN,GAAP,GAAaA,GAAb;AACA;;AACD,SAAOM,MAAP;AACA;AAED;;;;;;AAIO,SAASC,aAAT,QACP;AAAA,MADgCR,MAChC,SADgCA,MAChC;AAAA,MADwCC,GACxC,SADwCA,GACxC;;AACC,MAAI,CAACD,MAAL,EACA;AACC,WAAO,EAAP;AACA;;AAED,MAAIA,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlB,EACA;AACC,UAAM,IAAIS,KAAJ,iEAAN;AACA;;AAED,uBAAcT,MAAd,SAAuBC,GAAG,GAAG,UAAUA,GAAb,GAAmB,EAA7C;AACA","sourcesContent":["import isViablePhoneNumber from './isViablePhoneNumber'\r\n\r\n// https://www.ietf.org/rfc/rfc3966.txt\r\n\r\n/**\r\n * @param {string} text - Phone URI (RFC 3966).\r\n * @return {object} `{ ?number, ?ext }`.\r\n */\r\nexport function parseRFC3966(text)\r\n{\r\n\tlet number\r\n\tlet ext\r\n\r\n\t// Replace \"tel:\" with \"tel=\" for parsing convenience.\r\n\ttext = text.replace(/^tel:/, 'tel=')\r\n\r\n\tfor (const part of text.split(';'))\r\n\t{\r\n\t\tconst [name, value] = part.split('=')\r\n\t\tswitch (name)\r\n\t\t{\r\n\t\t\tcase 'tel':\r\n\t\t\t\tnumber = value\r\n\t\t\t\tbreak\r\n\t\t\tcase 'ext':\r\n\t\t\t\text = value\r\n\t\t\t\tbreak\r\n\t\t\tcase 'phone-context':\r\n\t\t\t\t// Only \"country contexts\" are supported.\r\n\t\t\t\t// \"Domain contexts\" are ignored.\r\n\t\t\t\tif (value[0] === '+') {\r\n\t\t\t\t\tnumber = value + number\r\n\t\t\t\t}\r\n\t\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\r\n\t// If the phone number is not viable, then abort.\r\n\tif (!isViablePhoneNumber(number))\r\n\t{\r\n\t\treturn {}\r\n\t}\r\n\r\n\tconst result = { number }\r\n\tif (ext) {\r\n\t\tresult.ext = ext\r\n\t}\r\n\treturn result\r\n}\r\n\r\n/**\r\n * @param {object} - `{ ?number, ?extension }`.\r\n * @return {string} Phone URI (RFC 3966).\r\n */\r\nexport function formatRFC3966({ number, ext })\r\n{\r\n\tif (!number)\r\n\t{\r\n\t\treturn ''\r\n\t}\r\n\r\n\tif (number[0] !== '+')\r\n\t{\r\n\t\tthrow new Error(`\"formatRFC3966()\" expects \"number\" to be in E.164 format.`)\r\n\t}\r\n\r\n\treturn `tel:${number}${ext ? ';ext=' + ext : ''}`\r\n}"],"file":"RFC3966.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/RFC3966.test.js"],"names":["describe","it","expect","number","to","should","equal","ext","deep"],"mappings":";;AAAA;;AAEAA,QAAQ,CAAC,SAAD,EAAY,YAAM;AACzBC,EAAAA,EAAE,CAAC,eAAD,EAAkB,YAAM;AACzBC,IAAAA,MAAM,CAAC;AAAA,aAAM,wBAAc;AAAEC,QAAAA,MAAM,EAAE;AAAV,OAAd,CAAN;AAAA,KAAD,CAAN,CAA+CC,EAA/C,UAAwD,wCAAxD;AACA,4BAAc,EAAd,EAAkBC,MAAlB,CAAyBC,KAAzB,CAA+B,EAA/B;AACA,4BAAc;AAAEH,MAAAA,MAAM,EAAE;AAAV,KAAd,EAA0CE,MAA1C,CAAiDC,KAAjD,CAAuD,kBAAvD;AACA,4BAAc;AAAEH,MAAAA,MAAM,EAAE,cAAV;AAA0BI,MAAAA,GAAG,EAAE;AAA/B,KAAd,EAAsDF,MAAtD,CAA6DC,KAA7D,CAAmE,0BAAnE;AACA,GALC,CAAF;AAOAL,EAAAA,EAAE,CAAC,cAAD,EAAiB,YAAM;AACxB,2BAAa,kBAAb,EAAiCI,MAAjC,CAAwCG,IAAxC,CAA6CF,KAA7C,CAAmD;AAClDH,MAAAA,MAAM,EAAG;AADyC,KAAnD;AAIA,2BAAa,0BAAb,EAAyCE,MAAzC,CAAgDG,IAAhD,CAAqDF,KAArD,CAA2D;AAC1DH,MAAAA,MAAM,EAAG,cADiD;AAE1DI,MAAAA,GAAG,EAAM;AAFiD,KAA3D,EALwB,CAUxB;;AACA,2BAAa,yCAAb,EAAwDF,MAAxD,CAA+DG,IAA/D,CAAoEF,KAApE,CAA0E;AACzEH,MAAAA,MAAM,EAAG,cADgE;AAEzEI,MAAAA,GAAG,EAAM;AAFgE,KAA1E,EAXwB,CAgBxB;;AACA,2BAAa,2DAAb,EAA0EF,MAA1E,CAAiFG,IAAjF,CAAsFF,KAAtF,CAA4F;AAC3FH,MAAAA,MAAM,EAAG,YADkF;AAE3FI,MAAAA,GAAG,EAAM;AAFkF,KAA5F;AAIA,GArBC,CAAF;AAsBA,CA9BO,CAAR","sourcesContent":["import { parseRFC3966, formatRFC3966 } from './RFC3966'\r\n\r\ndescribe('RFC3966', () => {\r\n\tit('should format', () => {\r\n\t\texpect(() => formatRFC3966({ number: '123' })).to.throw('expects \"number\" to be in E.164 format')\r\n\t\tformatRFC3966({}).should.equal('')\r\n\t\tformatRFC3966({ number: '+78005553535' }).should.equal('tel:+78005553535')\r\n\t\tformatRFC3966({ number: '+78005553535', ext: '123' }).should.equal('tel:+78005553535;ext=123')\r\n\t})\r\n\r\n\tit('should parse', () => {\r\n\t\tparseRFC3966('tel:+78005553535').should.deep.equal({\r\n\t\t\tnumber : '+78005553535'\r\n\t\t})\r\n\r\n\t\tparseRFC3966('tel:+78005553535;ext=123').should.deep.equal({\r\n\t\t\tnumber : '+78005553535',\r\n\t\t\text : '123'\r\n\t\t})\r\n\r\n\t\t// With `phone-context`\r\n\t\tparseRFC3966('tel:8005553535;ext=123;phone-context=+7').should.deep.equal({\r\n\t\t\tnumber : '+78005553535',\r\n\t\t\text : '123'\r\n\t\t})\r\n\r\n\t\t// \"Domain contexts\" are ignored\r\n\t\tparseRFC3966('tel:8005553535;ext=123;phone-context=www.leningrad.spb.ru').should.deep.equal({\r\n\t\t\tnumber : '8005553535',\r\n\t\t\text : '123'\r\n\t\t})\r\n\t})\r\n})\r\n"],"file":"RFC3966.test.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/checkNumberLength.js"],"names":["checkNumberLength","nationalNumber","metadata","checkNumberLengthForType","undefined","type","type_info","possible_lengths","possibleLengths","mobile_type","actual_length","length","minimum_length","indexOf"],"mappings":";;;;;;;;AAAA;;AAEe,SAASA,iBAAT,CAA2BC,cAA3B,EAA2CC,QAA3C,EAAqD;AACnE,SAAOC,wBAAwB,CAACF,cAAD,EAAiBG,SAAjB,EAA4BF,QAA5B,CAA/B;AACA,C,CAED;AACA;;;AACO,SAASC,wBAAT,CAAkCF,cAAlC,EAAkDI,IAAlD,EAAwDH,QAAxD,EAAkE;AACxE,MAAMI,SAAS,GAAGJ,QAAQ,CAACG,IAAT,CAAcA,IAAd,CAAlB,CADwE,CAGxE;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAIE,gBAAgB,GAAGD,SAAS,IAAIA,SAAS,CAACE,eAAV,EAAb,IAA4CN,QAAQ,CAACM,eAAT,EAAnE,CAVwE,CAWxE;AAEA;;AACA,MAAI,CAACD,gBAAL,EAAuB;AACtB,WAAO,aAAP;AACA;;AAED,MAAIF,IAAI,KAAK,sBAAb,EAAqC;AACpC;;AACA;AACA,QAAI,CAACH,QAAQ,CAACG,IAAT,CAAc,YAAd,CAAL,EAAkC;AACjC;AACA;AACA,aAAOF,wBAAwB,CAACF,cAAD,EAAiB,QAAjB,EAA2BC,QAA3B,CAA/B;AACA;;AAED,QAAMO,WAAW,GAAGP,QAAQ,CAACG,IAAT,CAAc,QAAd,CAApB;;AACA,QAAII,WAAJ,EAAiB;AAChB;AACA;AACA;AACA;AACA;AACAF,MAAAA,gBAAgB,GAAG,uBAAYA,gBAAZ,EAA8BE,WAAW,CAACD,eAAZ,EAA9B,CAAnB,CANgB,CAOhB;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACD,GA3BD,CA4BA;AA5BA,OA6BK,IAAIH,IAAI,IAAI,CAACC,SAAb,EAAwB;AAC5B,aAAO,gBAAP;AACA;;AAED,MAAMI,aAAa,GAAGT,cAAc,CAACU,MAArC,CAnDwE,CAqDxE;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,cAAc,GAAGL,gBAAgB,CAAC,CAAD,CAAvC;;AAEA,MAAIK,cAAc,KAAKF,aAAvB,EAAsC;AACrC,WAAO,aAAP;AACA;;AAED,MAAIE,cAAc,GAAGF,aAArB,EAAoC;AACnC,WAAO,WAAP;AACA;;AAED,MAAIH,gBAAgB,CAACA,gBAAgB,CAACI,MAAjB,GAA0B,CAA3B,CAAhB,GAAgDD,aAApD,EAAmE;AAClE,WAAO,UAAP;AACA,GAzEuE,CA2ExE;;;AACA,SAAOH,gBAAgB,CAACM,OAAjB,CAAyBH,aAAzB,EAAwC,CAAxC,KAA8C,CAA9C,GAAkD,aAAlD,GAAkE,gBAAzE;AACA","sourcesContent":["import { mergeArrays } from './util'\r\n\r\nexport default function checkNumberLength(nationalNumber, metadata) {\r\n\treturn checkNumberLengthForType(nationalNumber, undefined, metadata)\r\n}\r\n\r\n// Checks whether a number is possible for the country based on its length.\r\n// Should only be called for the \"new\" metadata which has \"possible lengths\".\r\nexport function checkNumberLengthForType(nationalNumber, type, metadata) {\r\n\tconst type_info = metadata.type(type)\r\n\r\n\t// There should always be \"<possiblePengths/>\" set for every type element.\r\n\t// This is declared in the XML schema.\r\n\t// For size efficiency, where a sub-description (e.g. fixed-line)\r\n\t// has the same \"<possiblePengths/>\" as the \"general description\", this is missing,\r\n\t// so we fall back to the \"general description\". Where no numbers of the type\r\n\t// exist at all, there is one possible length (-1) which is guaranteed\r\n\t// not to match the length of any real phone number.\r\n\tlet possible_lengths = type_info && type_info.possibleLengths() || metadata.possibleLengths()\r\n\t// let local_lengths = type_info && type.possibleLengthsLocal() || metadata.possibleLengthsLocal()\r\n\r\n\t// Metadata before version `1.0.18` didn't contain `possible_lengths`.\r\n\tif (!possible_lengths) {\r\n\t\treturn 'IS_POSSIBLE'\r\n\t}\r\n\r\n\tif (type === 'FIXED_LINE_OR_MOBILE') {\r\n\t\t// No such country in metadata.\r\n\t\t/* istanbul ignore next */\r\n\t\tif (!metadata.type('FIXED_LINE')) {\r\n\t\t\t// The rare case has been encountered where no fixedLine data is available\r\n\t\t\t// (true for some non-geographic entities), so we just check mobile.\r\n\t\t\treturn checkNumberLengthForType(nationalNumber, 'MOBILE', metadata)\r\n\t\t}\r\n\r\n\t\tconst mobile_type = metadata.type('MOBILE')\r\n\t\tif (mobile_type) {\r\n\t\t\t// Merge the mobile data in if there was any. \"Concat\" creates a new\r\n\t\t\t// array, it doesn't edit possible_lengths in place, so we don't need a copy.\r\n\t\t\t// Note that when adding the possible lengths from mobile, we have\r\n\t\t\t// to again check they aren't empty since if they are this indicates\r\n\t\t\t// they are the same as the general desc and should be obtained from there.\r\n\t\t\tpossible_lengths = mergeArrays(possible_lengths, mobile_type.possibleLengths())\r\n\t\t\t// The current list is sorted; we need to merge in the new list and\r\n\t\t\t// re-sort (duplicates are okay). Sorting isn't so expensive because\r\n\t\t\t// the lists are very small.\r\n\r\n\t\t\t// if (local_lengths) {\r\n\t\t\t// \tlocal_lengths = mergeArrays(local_lengths, mobile_type.possibleLengthsLocal())\r\n\t\t\t// } else {\r\n\t\t\t// \tlocal_lengths = mobile_type.possibleLengthsLocal()\r\n\t\t\t// }\r\n\t\t}\r\n\t}\r\n\t// If the type doesn't exist then return 'INVALID_LENGTH'.\r\n\telse if (type && !type_info) {\r\n\t\treturn 'INVALID_LENGTH'\r\n\t}\r\n\r\n\tconst actual_length = nationalNumber.length\r\n\r\n\t// In `libphonenumber-js` all \"local-only\" formats are dropped for simplicity.\r\n\t// // This is safe because there is never an overlap beween the possible lengths\r\n\t// // and the local-only lengths; this is checked at build time.\r\n\t// if (local_lengths && local_lengths.indexOf(nationalNumber.length) >= 0)\r\n\t// {\r\n\t// \treturn 'IS_POSSIBLE_LOCAL_ONLY'\r\n\t// }\r\n\r\n\tconst minimum_length = possible_lengths[0]\r\n\r\n\tif (minimum_length === actual_length) {\r\n\t\treturn 'IS_POSSIBLE'\r\n\t}\r\n\r\n\tif (minimum_length > actual_length) {\r\n\t\treturn 'TOO_SHORT'\r\n\t}\r\n\r\n\tif (possible_lengths[possible_lengths.length - 1] < actual_length) {\r\n\t\treturn 'TOO_LONG'\r\n\t}\r\n\r\n\t// We skip the first element since we've already checked it.\r\n\treturn possible_lengths.indexOf(actual_length, 1) >= 0 ? 'IS_POSSIBLE' : 'INVALID_LENGTH'\r\n}"],"file":"checkNumberLength.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/checkNumberLength.test.js"],"names":["describe","it","checkNumberLength","should","equal","undefined","number","type","country","_metadata","Metadata","metadata"],"mappings":";;AAAA;;AACA;;AACA;;;;AAEAA,QAAQ,CAAC,mBAAD,EAAsB,YAAM;AACnCC,EAAAA,EAAE,CAAC,kCAAD,EAAqC,YAAM;AAC5C;AACAC,IAAAA,iBAAiB,CAAC,WAAD,EAAc,YAAd,EAA4B,IAA5B,CAAjB,CAAmDC,MAAnD,CAA0DC,KAA1D,CAAgE,WAAhE,EAF4C,CAG5C;;AACAF,IAAAA,iBAAiB,CAAC,YAAD,EAAe,YAAf,EAA6B,IAA7B,CAAjB,CAAoDC,MAApD,CAA2DC,KAA3D,CAAiE,aAAjE,EAJ4C,CAK5C;;AACAF,IAAAA,iBAAiB,CAAC,aAAD,EAAgB,YAAhB,EAA8B,IAA9B,CAAjB,CAAqDC,MAArD,CAA4DC,KAA5D,CAAkE,UAAlE,EAN4C,CAQ5C;;AACAF,IAAAA,iBAAiB,CAAC,WAAD,EAAc,MAAd,EAAsB,IAAtB,CAAjB,CAA6CC,MAA7C,CAAoDC,KAApD,CAA0D,gBAA1D,EAT4C,CAU5C;;AACAF,IAAAA,iBAAiB,CAAC,SAAD,EAAYG,SAAZ,EAAuB,IAAvB,CAAjB,CAA8CF,MAA9C,CAAqDC,KAArD,CAA2D,gBAA3D,EAX4C,CAa5C;;AACAF,IAAAA,iBAAiB,CAAC,SAAD,EAAY,sBAAZ,EAAoC,IAApC,CAAjB,CAA2DC,MAA3D,CAAkEC,KAAlE,CAAwE,gBAAxE,EAd4C,CAe5C;;AACAF,IAAAA,iBAAiB,CAAC,MAAD,EAAS,sBAAT,EAAiC,IAAjC,CAAjB,CAAwDC,MAAxD,CAA+DC,KAA/D,CAAqE,aAArE,EAhB4C,CAiB5C;;AACAF,IAAAA,iBAAiB,CAAC,UAAD,EAAa,sBAAb,EAAqC,IAArC,CAAjB,CAA4DC,MAA5D,CAAmEC,KAAnE,CAAyE,aAAzE;AACA,GAnBC,CAAF;AAoBA,CArBO,CAAR;;AAuBA,SAASF,iBAAT,CAA2BI,MAA3B,EAAmCC,IAAnC,EAAyCC,OAAzC,EAAkD;AACjD,MAAMC,SAAS,GAAG,IAAIC,qBAAJ,CAAaC,qBAAb,CAAlB;;AACAF,EAAAA,SAAS,CAACD,OAAV,CAAkBA,OAAlB;;AACA,SAAO,iDAAyBF,MAAzB,EAAiCC,IAAjC,EAAuCE,SAAvC,CAAP;AACA","sourcesContent":["import metadata from '../metadata.full'\r\nimport Metadata from './metadata'\r\nimport { checkNumberLengthForType } from './checkNumberLength'\r\n\r\ndescribe('checkNumberLength', () => {\r\n\tit('should check phone number length', () => {\r\n\t\t// Too short.\r\n\t\tcheckNumberLength('800555353', 'FIXED_LINE', 'RU').should.equal('TOO_SHORT')\r\n\t\t// Normal.\r\n\t\tcheckNumberLength('8005553535', 'FIXED_LINE', 'RU').should.equal('IS_POSSIBLE')\r\n\t\t// Too long.\r\n\t\tcheckNumberLength('80055535355', 'FIXED_LINE', 'RU').should.equal('TOO_LONG')\r\n\r\n\t\t// No such type.\r\n\t\tcheckNumberLength('169454850', 'VOIP', 'AC').should.equal('INVALID_LENGTH')\r\n\t\t// No such possible length.\r\n\t\tcheckNumberLength('1694548', undefined, 'AD').should.equal('INVALID_LENGTH')\r\n\r\n\t\t// FIXED_LINE_OR_MOBILE\r\n\t\tcheckNumberLength('1694548', 'FIXED_LINE_OR_MOBILE', 'AD').should.equal('INVALID_LENGTH')\r\n\t\t// No mobile phones.\r\n\t\tcheckNumberLength('8123', 'FIXED_LINE_OR_MOBILE', 'TA').should.equal('IS_POSSIBLE')\r\n\t\t// No \"possible lengths\" for \"mobile\".\r\n\t\tcheckNumberLength('81234567', 'FIXED_LINE_OR_MOBILE', 'SZ').should.equal('IS_POSSIBLE')\r\n\t})\r\n})\r\n\r\nfunction checkNumberLength(number, type, country) {\r\n\tconst _metadata = new Metadata(metadata)\r\n\t_metadata.country(country)\r\n\treturn checkNumberLengthForType(number, type, _metadata)\r\n}"],"file":"checkNumberLength.test.js"}
|