libphonenumber-js 1.13.6 → 1.13.8
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 +50 -48
- package/AUTHORS +4 -4
- package/CHANGELOG.md +984 -960
- package/CODE_OF_CONDUCT.md +78 -78
- package/LICENSE +21 -21
- package/LICENSE.Apache +175 -175
- package/README.md +2110 -2110
- package/build/AsYouType.js +70 -70
- package/build/AsYouType.js.map +1 -1
- package/build/AsYouType.test.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternMatcher.js +6 -6
- package/build/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternParser.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
- package/build/AsYouTypeFormatter.complete.js.map +1 -1
- package/build/AsYouTypeFormatter.js +11 -11
- package/build/AsYouTypeFormatter.js.map +1 -1
- package/build/AsYouTypeFormatter.util.js.map +1 -1
- package/build/AsYouTypeFormatter.util.test.js.map +1 -1
- package/build/AsYouTypeParser.js +26 -26
- package/build/AsYouTypeParser.js.map +1 -1
- package/build/AsYouTypeState.js +6 -6
- package/build/AsYouTypeState.js.map +1 -1
- package/build/ParseError.js.map +1 -1
- package/build/PhoneNumber.js +5 -5
- package/build/PhoneNumber.js.map +1 -1
- package/build/PhoneNumber.test.js.map +1 -1
- package/build/PhoneNumberMatcher.js +60 -60
- package/build/PhoneNumberMatcher.js.map +1 -1
- package/build/PhoneNumberMatcher.test.js.map +1 -1
- package/build/constants.js.map +1 -1
- package/build/findNumbers/LRUCache.js.map +1 -1
- package/build/findNumbers/Leniency.js +34 -34
- package/build/findNumbers/Leniency.js.map +1 -1
- package/build/findNumbers/RegExpCache.js.map +1 -1
- package/build/findNumbers/isValidCandidate.js +14 -14
- package/build/findNumbers/isValidCandidate.js.map +1 -1
- package/build/findNumbers/isValidPreCandidate.js.map +1 -1
- package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +6 -6
- package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
- package/build/findNumbers/parsePreCandidate.js.map +1 -1
- package/build/findNumbers/utf-8.js +19 -19
- package/build/findNumbers/utf-8.js.map +1 -1
- package/build/findNumbers/util.js +3 -3
- package/build/findNumbers/util.js.map +1 -1
- package/build/findNumbers/util.test.js.map +1 -1
- package/build/findPhoneNumbersInText.js.map +1 -1
- package/build/findPhoneNumbersInText.test.js.map +1 -1
- package/build/format.js +14 -14
- package/build/format.js.map +1 -1
- package/build/format.test.js.map +1 -1
- package/build/formatIncompletePhoneNumber.js +7 -7
- package/build/formatIncompletePhoneNumber.js.map +1 -1
- package/build/formatIncompletePhoneNumber.test.js.map +1 -1
- package/build/formatPhoneNumberForMobileDialing.js +35 -35
- package/build/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/build/getCountries.js.map +1 -1
- package/build/getCountries.test.js.map +1 -1
- package/build/getCountryCallingCode.js.map +1 -1
- package/build/getCountryCallingCode.test.js.map +1 -1
- package/build/getExampleNumber.js.map +1 -1
- package/build/getExampleNumber.test.js.map +1 -1
- package/build/helpers/RFC3966.js +6 -6
- package/build/helpers/RFC3966.js.map +1 -1
- package/build/helpers/RFC3966.test.js.map +1 -1
- package/build/helpers/applyInternationalSeparatorStyle.js.map +1 -1
- package/build/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
- package/build/helpers/checkNumberLength.js +15 -15
- package/build/helpers/checkNumberLength.js.map +1 -1
- package/build/helpers/checkNumberLength.test.js.map +1 -1
- package/build/helpers/extension/createExtensionPattern.js +10 -10
- package/build/helpers/extension/createExtensionPattern.js.map +1 -1
- package/build/helpers/extension/extractExtension.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.js +23 -23
- package/build/helpers/extractCountryCallingCode.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +9 -9
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -1
- package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +4 -4
- package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
- package/build/helpers/extractNationalNumber.js +15 -15
- package/build/helpers/extractNationalNumber.js.map +1 -1
- package/build/helpers/extractNationalNumber.test.js.map +1 -1
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -12
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
- package/build/helpers/extractPhoneContext.js +17 -17
- package/build/helpers/extractPhoneContext.js.map +1 -1
- package/build/helpers/extractPhoneContext.test.js.map +1 -1
- package/build/helpers/formatNationalNumberUsingFormat.js.map +1 -1
- package/build/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -1
- package/build/helpers/getCountryByCallingCode.js +7 -7
- package/build/helpers/getCountryByCallingCode.js.map +1 -1
- package/build/helpers/getCountryByNationalNumber.js +7 -7
- package/build/helpers/getCountryByNationalNumber.js.map +1 -1
- package/build/helpers/getIddPrefix.js +8 -8
- package/build/helpers/getIddPrefix.js.map +1 -1
- package/build/helpers/getNumberType.js.map +1 -1
- package/build/helpers/getNumberType.test.js.map +1 -1
- package/build/helpers/getPossibleCountriesForNumber.js +6 -6
- package/build/helpers/getPossibleCountriesForNumber.js.map +1 -1
- package/build/helpers/isCallingCode.js.map +1 -1
- package/build/helpers/isCallingCode.test.js.map +1 -1
- package/build/helpers/isCountryCode.js.map +1 -1
- package/build/helpers/isCountryCode.test.js.map +1 -1
- package/build/helpers/isObject.js.map +1 -1
- package/build/helpers/isViablePhoneNumber.js.map +1 -1
- package/build/helpers/matchesEntirely.js +4 -4
- package/build/helpers/matchesEntirely.js.map +1 -1
- package/build/helpers/matchesEntirely.test.js.map +1 -1
- package/build/helpers/mergeArrays.js +5 -5
- package/build/helpers/mergeArrays.js.map +1 -1
- package/build/helpers/mergeArrays.test.js.map +1 -1
- package/build/helpers/parseDigits.js +12 -12
- package/build/helpers/parseDigits.js.map +1 -1
- package/build/helpers/parseDigits.test.js.map +1 -1
- package/build/helpers/stripIddPrefix.js.map +1 -1
- package/build/helpers/stripIddPrefix.test.js.map +1 -1
- package/build/isPossible.js +17 -17
- package/build/isPossible.js.map +1 -1
- package/build/isPossible.test.js.map +1 -1
- package/build/isPossiblePhoneNumber.js.map +1 -1
- package/build/isPossiblePhoneNumber.test.js.map +1 -1
- package/build/isValid.js +33 -33
- package/build/isValid.js.map +1 -1
- package/build/isValid.test.js.map +1 -1
- package/build/isValidPhoneNumber.js.map +1 -1
- package/build/isValidPhoneNumber.test.js.map +1 -1
- package/build/legacy/PhoneNumberSearch.js +4 -4
- package/build/legacy/PhoneNumberSearch.js.map +1 -1
- package/build/legacy/findNumbers.js.map +1 -1
- package/build/legacy/findNumbers.test.js.map +1 -1
- package/build/legacy/findPhoneNumbers.js +2 -2
- package/build/legacy/findPhoneNumbers.js.map +1 -1
- package/build/legacy/findPhoneNumbers.test.js.map +1 -1
- package/build/legacy/findPhoneNumbersInitialImplementation.js +16 -16
- package/build/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
- package/build/legacy/format.js.map +1 -1
- package/build/legacy/format.test.js.map +1 -1
- package/build/legacy/getNumberType.js.map +1 -1
- package/build/legacy/getNumberType.test.js.map +1 -1
- package/build/legacy/isPossibleNumber.js +13 -13
- package/build/legacy/isPossibleNumber.js.map +1 -1
- package/build/legacy/isPossibleNumber.test.js.map +1 -1
- package/build/legacy/isValidNumber.js.map +1 -1
- package/build/legacy/isValidNumber.test.js.map +1 -1
- package/build/legacy/isValidNumberForRegion.js.map +1 -1
- package/build/legacy/isValidNumberForRegion.test.js.map +1 -1
- package/build/legacy/isValidNumberForRegion_.js +4 -4
- package/build/legacy/isValidNumberForRegion_.js.map +1 -1
- package/build/legacy/parse.js.map +1 -1
- package/build/legacy/parse.test.js.map +1 -1
- package/build/legacy/searchNumbers.js +2 -2
- package/build/legacy/searchNumbers.js.map +1 -1
- package/build/legacy/searchNumbers.test.js.map +1 -1
- package/build/metadata.js +40 -40
- package/build/metadata.js.map +1 -1
- package/build/metadata.test.js.map +1 -1
- package/build/normalizeArguments.js.map +1 -1
- package/build/parse.js +36 -36
- package/build/parse.js.map +1 -1
- package/build/parse.test.js.map +1 -1
- package/build/parseIncompletePhoneNumber.js +24 -24
- package/build/parseIncompletePhoneNumber.js.map +1 -1
- package/build/parseIncompletePhoneNumber.test.js.map +1 -1
- package/build/parsePhoneNumber.js.map +1 -1
- package/build/parsePhoneNumber.test.js.map +1 -1
- package/build/parsePhoneNumberWithError.js.map +1 -1
- package/build/parsePhoneNumberWithError.test.js.map +1 -1
- package/build/parsePhoneNumberWithError_.js.map +1 -1
- package/build/parsePhoneNumber_.js.map +1 -1
- package/build/searchPhoneNumbersInText.js.map +1 -1
- package/build/searchPhoneNumbersInText.test.js.map +1 -1
- package/build/tools/semver-compare.js.map +1 -1
- package/build/tools/semver-compare.test.js.map +1 -1
- package/build/validatePhoneNumberLength.js.map +1 -1
- package/build/validatePhoneNumberLength.test.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/es6/index.d.cts +2 -2
- package/core/es6/index.d.ts +2 -2
- package/core/es6/index.js +39 -39
- package/core/es6/package.json +12 -12
- package/core/index.cjs +57 -57
- package/core/index.cjs.js +62 -62
- package/core/index.d.cts +150 -150
- package/core/index.d.ts +150 -150
- package/core/index.js +39 -39
- package/core/package.json +14 -14
- package/custom.d.ts +209 -209
- package/custom.js +78 -78
- package/es6/AsYouType.js +70 -70
- package/es6/AsYouType.js.map +1 -1
- package/es6/AsYouType.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternMatcher.js +6 -6
- package/es6/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternParser.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.complete.js.map +1 -1
- package/es6/AsYouTypeFormatter.js +11 -11
- package/es6/AsYouTypeFormatter.js.map +1 -1
- package/es6/AsYouTypeFormatter.util.js.map +1 -1
- package/es6/AsYouTypeFormatter.util.test.js.map +1 -1
- package/es6/AsYouTypeParser.js +26 -26
- package/es6/AsYouTypeParser.js.map +1 -1
- package/es6/AsYouTypeState.js +6 -6
- package/es6/AsYouTypeState.js.map +1 -1
- package/es6/ParseError.js.map +1 -1
- package/es6/PhoneNumber.js +5 -5
- package/es6/PhoneNumber.js.map +1 -1
- package/es6/PhoneNumber.test.js.map +1 -1
- package/es6/PhoneNumberMatcher.js +60 -60
- package/es6/PhoneNumberMatcher.js.map +1 -1
- package/es6/PhoneNumberMatcher.test.js.map +1 -1
- package/es6/constants.js.map +1 -1
- package/es6/findNumbers/LRUCache.js.map +1 -1
- package/es6/findNumbers/Leniency.js +34 -34
- package/es6/findNumbers/Leniency.js.map +1 -1
- package/es6/findNumbers/RegExpCache.js.map +1 -1
- package/es6/findNumbers/isValidCandidate.js +14 -14
- package/es6/findNumbers/isValidCandidate.js.map +1 -1
- package/es6/findNumbers/isValidPreCandidate.js.map +1 -1
- package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +6 -6
- package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
- package/es6/findNumbers/parsePreCandidate.js.map +1 -1
- package/es6/findNumbers/utf-8.js +19 -19
- package/es6/findNumbers/utf-8.js.map +1 -1
- package/es6/findNumbers/util.js +3 -3
- package/es6/findNumbers/util.js.map +1 -1
- package/es6/findNumbers/util.test.js.map +1 -1
- package/es6/findPhoneNumbersInText.js.map +1 -1
- package/es6/findPhoneNumbersInText.test.js.map +1 -1
- package/es6/format.js +14 -14
- package/es6/format.js.map +1 -1
- package/es6/format.test.js.map +1 -1
- package/es6/formatIncompletePhoneNumber.js +7 -7
- package/es6/formatIncompletePhoneNumber.js.map +1 -1
- package/es6/formatIncompletePhoneNumber.test.js.map +1 -1
- package/es6/formatPhoneNumberForMobileDialing.js +35 -35
- package/es6/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/es6/getCountries.js.map +1 -1
- package/es6/getCountries.test.js.map +1 -1
- package/es6/getCountryCallingCode.js.map +1 -1
- package/es6/getCountryCallingCode.test.js.map +1 -1
- package/es6/getExampleNumber.js.map +1 -1
- package/es6/getExampleNumber.test.js.map +1 -1
- package/es6/helpers/RFC3966.js +6 -6
- package/es6/helpers/RFC3966.js.map +1 -1
- package/es6/helpers/RFC3966.test.js.map +1 -1
- package/es6/helpers/applyInternationalSeparatorStyle.js.map +1 -1
- package/es6/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
- package/es6/helpers/checkNumberLength.js +15 -15
- package/es6/helpers/checkNumberLength.js.map +1 -1
- package/es6/helpers/checkNumberLength.test.js.map +1 -1
- package/es6/helpers/extension/createExtensionPattern.js +10 -10
- package/es6/helpers/extension/createExtensionPattern.js.map +1 -1
- package/es6/helpers/extension/extractExtension.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.js +23 -23
- package/es6/helpers/extractCountryCallingCode.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +9 -9
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -1
- package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +4 -4
- package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
- package/es6/helpers/extractNationalNumber.js +15 -15
- package/es6/helpers/extractNationalNumber.js.map +1 -1
- package/es6/helpers/extractNationalNumber.test.js.map +1 -1
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -12
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
- package/es6/helpers/extractPhoneContext.js +17 -17
- package/es6/helpers/extractPhoneContext.js.map +1 -1
- package/es6/helpers/extractPhoneContext.test.js.map +1 -1
- package/es6/helpers/formatNationalNumberUsingFormat.js.map +1 -1
- package/es6/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -1
- package/es6/helpers/getCountryByCallingCode.js +7 -7
- package/es6/helpers/getCountryByCallingCode.js.map +1 -1
- package/es6/helpers/getCountryByNationalNumber.js +7 -7
- package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
- package/es6/helpers/getIddPrefix.js +8 -8
- package/es6/helpers/getIddPrefix.js.map +1 -1
- package/es6/helpers/getNumberType.js.map +1 -1
- package/es6/helpers/getNumberType.test.js.map +1 -1
- package/es6/helpers/getPossibleCountriesForNumber.js +6 -6
- package/es6/helpers/getPossibleCountriesForNumber.js.map +1 -1
- package/es6/helpers/isCallingCode.js.map +1 -1
- package/es6/helpers/isCallingCode.test.js.map +1 -1
- package/es6/helpers/isCountryCode.js.map +1 -1
- package/es6/helpers/isCountryCode.test.js.map +1 -1
- package/es6/helpers/isObject.js.map +1 -1
- package/es6/helpers/isViablePhoneNumber.js.map +1 -1
- package/es6/helpers/matchesEntirely.js +4 -4
- package/es6/helpers/matchesEntirely.js.map +1 -1
- package/es6/helpers/matchesEntirely.test.js.map +1 -1
- package/es6/helpers/mergeArrays.js +5 -5
- package/es6/helpers/mergeArrays.js.map +1 -1
- package/es6/helpers/mergeArrays.test.js.map +1 -1
- package/es6/helpers/parseDigits.js +12 -12
- package/es6/helpers/parseDigits.js.map +1 -1
- package/es6/helpers/parseDigits.test.js.map +1 -1
- package/es6/helpers/stripIddPrefix.js.map +1 -1
- package/es6/helpers/stripIddPrefix.test.js.map +1 -1
- package/es6/isPossible.js +17 -17
- package/es6/isPossible.js.map +1 -1
- package/es6/isPossible.test.js.map +1 -1
- package/es6/isPossiblePhoneNumber.js.map +1 -1
- package/es6/isPossiblePhoneNumber.test.js.map +1 -1
- package/es6/isValid.js +33 -33
- package/es6/isValid.js.map +1 -1
- package/es6/isValid.test.js.map +1 -1
- package/es6/isValidPhoneNumber.js.map +1 -1
- package/es6/isValidPhoneNumber.test.js.map +1 -1
- package/es6/legacy/PhoneNumberSearch.js +4 -4
- package/es6/legacy/PhoneNumberSearch.js.map +1 -1
- package/es6/legacy/findNumbers.js.map +1 -1
- package/es6/legacy/findNumbers.test.js.map +1 -1
- package/es6/legacy/findPhoneNumbers.js +2 -2
- package/es6/legacy/findPhoneNumbers.js.map +1 -1
- package/es6/legacy/findPhoneNumbers.test.js.map +1 -1
- package/es6/legacy/findPhoneNumbersInitialImplementation.js +16 -16
- package/es6/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
- package/es6/legacy/format.js.map +1 -1
- package/es6/legacy/format.test.js.map +1 -1
- package/es6/legacy/getNumberType.js.map +1 -1
- package/es6/legacy/getNumberType.test.js.map +1 -1
- package/es6/legacy/isPossibleNumber.js +13 -13
- package/es6/legacy/isPossibleNumber.js.map +1 -1
- package/es6/legacy/isPossibleNumber.test.js.map +1 -1
- package/es6/legacy/isValidNumber.js.map +1 -1
- package/es6/legacy/isValidNumber.test.js.map +1 -1
- package/es6/legacy/isValidNumberForRegion.js.map +1 -1
- package/es6/legacy/isValidNumberForRegion.test.js.map +1 -1
- package/es6/legacy/isValidNumberForRegion_.js +4 -4
- package/es6/legacy/isValidNumberForRegion_.js.map +1 -1
- package/es6/legacy/parse.js.map +1 -1
- package/es6/legacy/parse.test.js.map +1 -1
- package/es6/legacy/searchNumbers.js +2 -2
- package/es6/legacy/searchNumbers.js.map +1 -1
- package/es6/legacy/searchNumbers.test.js.map +1 -1
- package/es6/metadata.js +40 -40
- package/es6/metadata.js.map +1 -1
- package/es6/metadata.test.js.map +1 -1
- package/es6/normalizeArguments.js.map +1 -1
- package/es6/parse.js +36 -36
- package/es6/parse.js.map +1 -1
- package/es6/parse.test.js.map +1 -1
- package/es6/parseIncompletePhoneNumber.js +24 -24
- package/es6/parseIncompletePhoneNumber.js.map +1 -1
- package/es6/parseIncompletePhoneNumber.test.js.map +1 -1
- package/es6/parsePhoneNumber.js.map +1 -1
- package/es6/parsePhoneNumber.test.js.map +1 -1
- package/es6/parsePhoneNumberWithError.js.map +1 -1
- package/es6/parsePhoneNumberWithError.test.js.map +1 -1
- package/es6/parsePhoneNumberWithError_.js.map +1 -1
- package/es6/parsePhoneNumber_.js.map +1 -1
- package/es6/searchPhoneNumbersInText.js.map +1 -1
- package/es6/searchPhoneNumbersInText.test.js.map +1 -1
- package/es6/tools/semver-compare.js.map +1 -1
- package/es6/tools/semver-compare.test.js.map +1 -1
- package/es6/validatePhoneNumberLength.js.map +1 -1
- package/es6/validatePhoneNumberLength.test.js.map +1 -1
- package/es6-modern/AsYouType.js +70 -70
- package/es6-modern/AsYouType.js.map +1 -1
- package/es6-modern/AsYouType.test.js.map +1 -1
- package/es6-modern/AsYouTypeFormatter.PatternMatcher.js +6 -6
- package/es6-modern/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
- package/es6-modern/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
- package/es6-modern/AsYouTypeFormatter.PatternParser.js.map +1 -1
- package/es6-modern/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
- package/es6-modern/AsYouTypeFormatter.complete.js.map +1 -1
- package/es6-modern/AsYouTypeFormatter.js +11 -11
- package/es6-modern/AsYouTypeFormatter.js.map +1 -1
- package/es6-modern/AsYouTypeFormatter.util.js.map +1 -1
- package/es6-modern/AsYouTypeFormatter.util.test.js.map +1 -1
- package/es6-modern/AsYouTypeParser.js +26 -26
- package/es6-modern/AsYouTypeParser.js.map +1 -1
- package/es6-modern/AsYouTypeState.js +6 -6
- package/es6-modern/AsYouTypeState.js.map +1 -1
- package/es6-modern/ParseError.js.map +1 -1
- package/es6-modern/PhoneNumber.js +5 -5
- package/es6-modern/PhoneNumber.js.map +1 -1
- package/es6-modern/PhoneNumber.test.js.map +1 -1
- package/es6-modern/PhoneNumberMatcher.js +60 -60
- package/es6-modern/PhoneNumberMatcher.js.map +1 -1
- package/es6-modern/PhoneNumberMatcher.test.js.map +1 -1
- package/es6-modern/constants.js.map +1 -1
- package/es6-modern/findNumbers/LRUCache.js.map +1 -1
- package/es6-modern/findNumbers/Leniency.js +34 -34
- package/es6-modern/findNumbers/Leniency.js.map +1 -1
- package/es6-modern/findNumbers/RegExpCache.js.map +1 -1
- package/es6-modern/findNumbers/isValidCandidate.js +14 -14
- package/es6-modern/findNumbers/isValidCandidate.js.map +1 -1
- package/es6-modern/findNumbers/isValidPreCandidate.js.map +1 -1
- package/es6-modern/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +6 -6
- package/es6-modern/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
- package/es6-modern/findNumbers/parsePreCandidate.js.map +1 -1
- package/es6-modern/findNumbers/utf-8.js +19 -19
- package/es6-modern/findNumbers/utf-8.js.map +1 -1
- package/es6-modern/findNumbers/util.js +3 -3
- package/es6-modern/findNumbers/util.js.map +1 -1
- package/es6-modern/findNumbers/util.test.js.map +1 -1
- package/es6-modern/findPhoneNumbersInText.js.map +1 -1
- package/es6-modern/findPhoneNumbersInText.test.js.map +1 -1
- package/es6-modern/format.js +14 -14
- package/es6-modern/format.js.map +1 -1
- package/es6-modern/format.test.js.map +1 -1
- package/es6-modern/formatIncompletePhoneNumber.js +7 -7
- package/es6-modern/formatIncompletePhoneNumber.js.map +1 -1
- package/es6-modern/formatIncompletePhoneNumber.test.js.map +1 -1
- package/es6-modern/formatPhoneNumberForMobileDialing.js +35 -35
- package/es6-modern/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/es6-modern/getCountries.js.map +1 -1
- package/es6-modern/getCountries.test.js.map +1 -1
- package/es6-modern/getCountryCallingCode.js.map +1 -1
- package/es6-modern/getCountryCallingCode.test.js.map +1 -1
- package/es6-modern/getExampleNumber.js.map +1 -1
- package/es6-modern/getExampleNumber.test.js.map +1 -1
- package/es6-modern/helpers/RFC3966.js +6 -6
- package/es6-modern/helpers/RFC3966.js.map +1 -1
- package/es6-modern/helpers/RFC3966.test.js.map +1 -1
- package/es6-modern/helpers/applyInternationalSeparatorStyle.js.map +1 -1
- package/es6-modern/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
- package/es6-modern/helpers/checkNumberLength.js +15 -15
- package/es6-modern/helpers/checkNumberLength.js.map +1 -1
- package/es6-modern/helpers/checkNumberLength.test.js.map +1 -1
- package/es6-modern/helpers/extension/createExtensionPattern.js +10 -10
- package/es6-modern/helpers/extension/createExtensionPattern.js.map +1 -1
- package/es6-modern/helpers/extension/extractExtension.js.map +1 -1
- package/es6-modern/helpers/extractCountryCallingCode.js +23 -23
- package/es6-modern/helpers/extractCountryCallingCode.js.map +1 -1
- package/es6-modern/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +9 -9
- package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -1
- package/es6-modern/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +4 -4
- package/es6-modern/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
- package/es6-modern/helpers/extractNationalNumber.js +15 -15
- package/es6-modern/helpers/extractNationalNumber.js.map +1 -1
- package/es6-modern/helpers/extractNationalNumber.test.js.map +1 -1
- package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -12
- package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
- package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
- package/es6-modern/helpers/extractPhoneContext.js +17 -17
- package/es6-modern/helpers/extractPhoneContext.js.map +1 -1
- package/es6-modern/helpers/extractPhoneContext.test.js.map +1 -1
- package/es6-modern/helpers/formatNationalNumberUsingFormat.js.map +1 -1
- package/es6-modern/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -1
- package/es6-modern/helpers/getCountryByCallingCode.js +7 -7
- package/es6-modern/helpers/getCountryByCallingCode.js.map +1 -1
- package/es6-modern/helpers/getCountryByNationalNumber.js +7 -7
- package/es6-modern/helpers/getCountryByNationalNumber.js.map +1 -1
- package/es6-modern/helpers/getIddPrefix.js +8 -8
- package/es6-modern/helpers/getIddPrefix.js.map +1 -1
- package/es6-modern/helpers/getNumberType.js.map +1 -1
- package/es6-modern/helpers/getNumberType.test.js.map +1 -1
- package/es6-modern/helpers/getPossibleCountriesForNumber.js +6 -6
- package/es6-modern/helpers/getPossibleCountriesForNumber.js.map +1 -1
- package/es6-modern/helpers/isCallingCode.js.map +1 -1
- package/es6-modern/helpers/isCallingCode.test.js.map +1 -1
- package/es6-modern/helpers/isCountryCode.js.map +1 -1
- package/es6-modern/helpers/isCountryCode.test.js.map +1 -1
- package/es6-modern/helpers/isObject.js.map +1 -1
- package/es6-modern/helpers/isViablePhoneNumber.js.map +1 -1
- package/es6-modern/helpers/matchesEntirely.js +4 -4
- package/es6-modern/helpers/matchesEntirely.js.map +1 -1
- package/es6-modern/helpers/matchesEntirely.test.js.map +1 -1
- package/es6-modern/helpers/mergeArrays.js +5 -5
- package/es6-modern/helpers/mergeArrays.js.map +1 -1
- package/es6-modern/helpers/mergeArrays.test.js.map +1 -1
- package/es6-modern/helpers/parseDigits.js +12 -12
- package/es6-modern/helpers/parseDigits.js.map +1 -1
- package/es6-modern/helpers/parseDigits.test.js.map +1 -1
- package/es6-modern/helpers/stripIddPrefix.js.map +1 -1
- package/es6-modern/helpers/stripIddPrefix.test.js.map +1 -1
- package/es6-modern/isPossible.js +17 -17
- package/es6-modern/isPossible.js.map +1 -1
- package/es6-modern/isPossible.test.js.map +1 -1
- package/es6-modern/isPossiblePhoneNumber.js.map +1 -1
- package/es6-modern/isPossiblePhoneNumber.test.js.map +1 -1
- package/es6-modern/isValid.js +33 -33
- package/es6-modern/isValid.js.map +1 -1
- package/es6-modern/isValid.test.js.map +1 -1
- package/es6-modern/isValidPhoneNumber.js.map +1 -1
- package/es6-modern/isValidPhoneNumber.test.js.map +1 -1
- package/es6-modern/legacy/PhoneNumberSearch.js +4 -4
- package/es6-modern/legacy/PhoneNumberSearch.js.map +1 -1
- package/es6-modern/legacy/findNumbers.js.map +1 -1
- package/es6-modern/legacy/findNumbers.test.js.map +1 -1
- package/es6-modern/legacy/findPhoneNumbers.js +2 -2
- package/es6-modern/legacy/findPhoneNumbers.js.map +1 -1
- package/es6-modern/legacy/findPhoneNumbers.test.js.map +1 -1
- package/es6-modern/legacy/findPhoneNumbersInitialImplementation.js +16 -16
- package/es6-modern/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
- package/es6-modern/legacy/format.js.map +1 -1
- package/es6-modern/legacy/format.test.js.map +1 -1
- package/es6-modern/legacy/getNumberType.js.map +1 -1
- package/es6-modern/legacy/getNumberType.test.js.map +1 -1
- package/es6-modern/legacy/isPossibleNumber.js +13 -13
- package/es6-modern/legacy/isPossibleNumber.js.map +1 -1
- package/es6-modern/legacy/isPossibleNumber.test.js.map +1 -1
- package/es6-modern/legacy/isValidNumber.js.map +1 -1
- package/es6-modern/legacy/isValidNumber.test.js.map +1 -1
- package/es6-modern/legacy/isValidNumberForRegion.js.map +1 -1
- package/es6-modern/legacy/isValidNumberForRegion.test.js.map +1 -1
- package/es6-modern/legacy/isValidNumberForRegion_.js +4 -4
- package/es6-modern/legacy/isValidNumberForRegion_.js.map +1 -1
- package/es6-modern/legacy/parse.js.map +1 -1
- package/es6-modern/legacy/parse.test.js.map +1 -1
- package/es6-modern/legacy/searchNumbers.js +2 -2
- package/es6-modern/legacy/searchNumbers.js.map +1 -1
- package/es6-modern/legacy/searchNumbers.test.js.map +1 -1
- package/es6-modern/metadata.js +40 -40
- package/es6-modern/metadata.js.map +1 -1
- package/es6-modern/metadata.test.js.map +1 -1
- package/es6-modern/normalizeArguments.js.map +1 -1
- package/es6-modern/parse.js +36 -36
- package/es6-modern/parse.js.map +1 -1
- package/es6-modern/parse.test.js.map +1 -1
- package/es6-modern/parseIncompletePhoneNumber.js +24 -24
- package/es6-modern/parseIncompletePhoneNumber.js.map +1 -1
- package/es6-modern/parseIncompletePhoneNumber.test.js.map +1 -1
- package/es6-modern/parsePhoneNumber.js.map +1 -1
- package/es6-modern/parsePhoneNumber.test.js.map +1 -1
- package/es6-modern/parsePhoneNumberWithError.js.map +1 -1
- package/es6-modern/parsePhoneNumberWithError.test.js.map +1 -1
- package/es6-modern/parsePhoneNumberWithError_.js.map +1 -1
- package/es6-modern/parsePhoneNumber_.js.map +1 -1
- package/es6-modern/searchPhoneNumbersInText.js.map +1 -1
- package/es6-modern/searchPhoneNumbersInText.test.js.map +1 -1
- package/es6-modern/tools/semver-compare.js.map +1 -1
- package/es6-modern/tools/semver-compare.test.js.map +1 -1
- package/es6-modern/validatePhoneNumberLength.js.map +1 -1
- package/es6-modern/validatePhoneNumberLength.test.js.map +1 -1
- package/examples.mobile.json.d.cts +3 -3
- package/examples.mobile.json.d.ts +3 -3
- package/index.cjs +129 -129
- package/index.cjs.js +135 -135
- package/index.d.cts +232 -232
- package/index.d.ts +232 -232
- package/index.es6.exports/PhoneNumberSearch.js +13 -13
- package/index.es6.exports/findPhoneNumbers.js +7 -7
- package/index.es6.exports/format.js +7 -7
- package/index.es6.exports/getNumberType.js +7 -7
- package/index.es6.exports/isPossibleNumber.js +9 -9
- package/index.es6.exports/isValidNumber.js +9 -9
- package/index.es6.exports/isValidNumberForRegion.js +7 -7
- package/index.es6.exports/parse.js +7 -7
- package/index.es6.exports/searchPhoneNumbers.js +7 -7
- package/index.es6.js +5 -5
- package/index.js +72 -72
- package/max/es6/exports/AsYouType.js +11 -11
- package/max/es6/exports/Metadata.js +11 -11
- package/max/es6/exports/PhoneNumber.js +11 -11
- package/max/es6/exports/PhoneNumberMatcher.js +11 -11
- package/max/es6/exports/findNumbers.js +5 -5
- package/max/es6/exports/findPhoneNumbersInText.js +5 -5
- package/max/es6/exports/formatIncompletePhoneNumber.js +5 -5
- package/max/es6/exports/getCountries.js +5 -5
- package/max/es6/exports/getCountryCallingCode.js +5 -5
- package/max/es6/exports/getExampleNumber.js +5 -5
- package/max/es6/exports/getExtPrefix.js +5 -5
- package/max/es6/exports/isPossiblePhoneNumber.js +5 -5
- package/max/es6/exports/isSupportedCountry.js +5 -5
- package/max/es6/exports/isValidPhoneNumber.js +5 -5
- package/max/es6/exports/parsePhoneNumber.js +6 -6
- package/max/es6/exports/parsePhoneNumberWithError.js +7 -7
- package/max/es6/exports/searchNumbers.js +5 -5
- package/max/es6/exports/searchPhoneNumbersInText.js +5 -5
- package/max/es6/exports/validatePhoneNumberLength.js +5 -5
- package/max/es6/exports/withMetadataArgument.js +12 -12
- package/max/es6/index.d.cts +2 -2
- package/max/es6/index.d.ts +2 -2
- package/max/es6/index.js +44 -44
- package/max/es6/package.json +12 -12
- package/max/exports/AsYouType.js +11 -11
- package/max/exports/Metadata.js +11 -11
- package/max/exports/PhoneNumber.js +21 -21
- package/max/exports/PhoneNumberMatcher.js +11 -11
- package/max/exports/findNumbers.js +5 -5
- package/max/exports/findPhoneNumbersInText.js +5 -5
- package/max/exports/formatIncompletePhoneNumber.js +5 -5
- package/max/exports/getCountries.js +5 -5
- package/max/exports/getCountryCallingCode.js +5 -5
- package/max/exports/getExampleNumber.js +5 -5
- package/max/exports/getExtPrefix.js +5 -5
- package/max/exports/isPossiblePhoneNumber.js +5 -5
- package/max/exports/isSupportedCountry.js +5 -5
- package/max/exports/isValidPhoneNumber.js +5 -5
- package/max/exports/parsePhoneNumber.js +5 -5
- package/max/exports/parsePhoneNumberWithError.js +6 -6
- package/max/exports/searchNumbers.js +5 -5
- package/max/exports/searchPhoneNumbersInText.js +5 -5
- package/max/exports/validatePhoneNumberLength.js +5 -5
- package/max/exports/withMetadataArgument.js +8 -8
- package/max/index.cjs +113 -113
- package/max/index.cjs.js +118 -118
- package/max/index.d.cts +137 -137
- package/max/index.d.ts +137 -137
- package/max/index.js +44 -44
- package/max/metadata/metadata.max.json +1 -1
- package/max/metadata/metadata.max.json.d.cts +4 -4
- package/max/metadata/metadata.max.json.d.ts +4 -4
- package/max/metadata/metadata.max.json.js +1 -1
- package/max/metadata/package.json +16 -16
- package/max/package.json +14 -14
- package/metadata.full.json +1 -1
- package/metadata.full.json.d.cts +4 -4
- package/metadata.full.json.d.ts +4 -4
- package/metadata.full.json.js +1 -1
- package/metadata.max.json +1 -1
- package/metadata.max.json.d.cts +4 -4
- package/metadata.max.json.d.ts +4 -4
- package/metadata.max.json.js +1 -1
- package/metadata.min.json +1 -1
- package/metadata.min.json.d.cts +4 -4
- package/metadata.min.json.d.ts +4 -4
- package/metadata.min.json.js +1 -1
- package/metadata.mobile.json +1 -1
- package/metadata.mobile.json.d.cts +4 -4
- package/metadata.mobile.json.d.ts +4 -4
- package/metadata.mobile.json.js +1 -1
- package/min/es6/exports/AsYouType.js +11 -11
- package/min/es6/exports/Metadata.js +11 -11
- package/min/es6/exports/PhoneNumber.js +11 -11
- package/min/es6/exports/PhoneNumberMatcher.js +11 -11
- package/min/es6/exports/findNumbers.js +5 -5
- package/min/es6/exports/findPhoneNumbersInText.js +5 -5
- package/min/es6/exports/formatIncompletePhoneNumber.js +5 -5
- package/min/es6/exports/getCountries.js +5 -5
- package/min/es6/exports/getCountryCallingCode.js +5 -5
- package/min/es6/exports/getExampleNumber.js +5 -5
- package/min/es6/exports/getExtPrefix.js +5 -5
- package/min/es6/exports/isPossiblePhoneNumber.js +5 -5
- package/min/es6/exports/isSupportedCountry.js +5 -5
- package/min/es6/exports/isValidPhoneNumber.js +5 -5
- package/min/es6/exports/parsePhoneNumber.js +6 -6
- package/min/es6/exports/parsePhoneNumberWithError.js +7 -7
- package/min/es6/exports/searchNumbers.js +5 -5
- package/min/es6/exports/searchPhoneNumbersInText.js +5 -5
- package/min/es6/exports/validatePhoneNumberLength.js +5 -5
- package/min/es6/exports/withMetadataArgument.js +12 -12
- package/min/es6/index.d.cts +2 -2
- package/min/es6/index.d.ts +2 -2
- package/min/es6/index.js +44 -44
- package/min/es6/package.json +12 -12
- package/min/exports/AsYouType.js +11 -11
- package/min/exports/Metadata.js +11 -11
- package/min/exports/PhoneNumber.js +21 -21
- package/min/exports/PhoneNumberMatcher.js +11 -11
- package/min/exports/findNumbers.js +5 -5
- package/min/exports/findPhoneNumbersInText.js +5 -5
- package/min/exports/formatIncompletePhoneNumber.js +5 -5
- package/min/exports/getCountries.js +5 -5
- package/min/exports/getCountryCallingCode.js +5 -5
- package/min/exports/getExampleNumber.js +5 -5
- package/min/exports/getExtPrefix.js +5 -5
- package/min/exports/isPossiblePhoneNumber.js +5 -5
- package/min/exports/isSupportedCountry.js +5 -5
- package/min/exports/isValidPhoneNumber.js +5 -5
- package/min/exports/parsePhoneNumber.js +5 -5
- package/min/exports/parsePhoneNumberWithError.js +6 -6
- package/min/exports/searchNumbers.js +5 -5
- package/min/exports/searchPhoneNumbersInText.js +5 -5
- package/min/exports/validatePhoneNumberLength.js +5 -5
- package/min/exports/withMetadataArgument.js +8 -8
- package/min/index.cjs +124 -124
- package/min/index.cjs.js +129 -129
- package/min/index.d.cts +137 -137
- package/min/index.d.ts +137 -137
- package/min/index.js +43 -43
- package/min/metadata/metadata.min.json +1 -1
- package/min/metadata/metadata.min.json.d.cts +4 -4
- package/min/metadata/metadata.min.json.d.ts +4 -4
- package/min/metadata/metadata.min.json.js +1 -1
- package/min/metadata/package.json +16 -16
- package/min/package.json +14 -14
- package/mobile/es6/exports/AsYouType.js +11 -11
- package/mobile/es6/exports/Metadata.js +11 -11
- package/mobile/es6/exports/PhoneNumber.js +11 -11
- package/mobile/es6/exports/PhoneNumberMatcher.js +11 -11
- package/mobile/es6/exports/findNumbers.js +5 -5
- package/mobile/es6/exports/findPhoneNumbersInText.js +5 -5
- package/mobile/es6/exports/formatIncompletePhoneNumber.js +5 -5
- package/mobile/es6/exports/getCountries.js +5 -5
- package/mobile/es6/exports/getCountryCallingCode.js +5 -5
- package/mobile/es6/exports/getExampleNumber.js +5 -5
- package/mobile/es6/exports/getExtPrefix.js +5 -5
- package/mobile/es6/exports/isPossiblePhoneNumber.js +5 -5
- package/mobile/es6/exports/isSupportedCountry.js +5 -5
- package/mobile/es6/exports/isValidPhoneNumber.js +5 -5
- package/mobile/es6/exports/parsePhoneNumber.js +6 -6
- package/mobile/es6/exports/parsePhoneNumberWithError.js +7 -7
- package/mobile/es6/exports/searchNumbers.js +5 -5
- package/mobile/es6/exports/searchPhoneNumbersInText.js +5 -5
- package/mobile/es6/exports/validatePhoneNumberLength.js +5 -5
- package/mobile/es6/exports/withMetadataArgument.js +12 -12
- package/mobile/es6/index.d.cts +2 -2
- package/mobile/es6/index.d.ts +2 -2
- package/mobile/es6/index.js +44 -44
- package/mobile/es6/package.json +12 -12
- package/mobile/examples/examples.mobile.json.d.cts +3 -3
- package/mobile/examples/examples.mobile.json.d.ts +3 -3
- package/mobile/examples/package.json +16 -16
- package/mobile/exports/AsYouType.js +11 -11
- package/mobile/exports/Metadata.js +11 -11
- package/mobile/exports/PhoneNumber.js +21 -21
- package/mobile/exports/PhoneNumberMatcher.js +11 -11
- package/mobile/exports/findNumbers.js +5 -5
- package/mobile/exports/findPhoneNumbersInText.js +5 -5
- package/mobile/exports/formatIncompletePhoneNumber.js +5 -5
- package/mobile/exports/getCountries.js +5 -5
- package/mobile/exports/getCountryCallingCode.js +5 -5
- package/mobile/exports/getExampleNumber.js +5 -5
- package/mobile/exports/getExtPrefix.js +5 -5
- package/mobile/exports/isPossiblePhoneNumber.js +5 -5
- package/mobile/exports/isSupportedCountry.js +5 -5
- package/mobile/exports/isValidPhoneNumber.js +5 -5
- package/mobile/exports/parsePhoneNumber.js +5 -5
- package/mobile/exports/parsePhoneNumberWithError.js +6 -6
- package/mobile/exports/searchNumbers.js +5 -5
- package/mobile/exports/searchPhoneNumbersInText.js +5 -5
- package/mobile/exports/validatePhoneNumberLength.js +5 -5
- package/mobile/exports/withMetadataArgument.js +8 -8
- package/mobile/index.cjs +113 -113
- package/mobile/index.cjs.js +118 -118
- package/mobile/index.d.cts +137 -137
- package/mobile/index.d.ts +137 -137
- package/mobile/index.js +44 -44
- package/mobile/metadata/metadata.mobile.json +1 -1
- package/mobile/metadata/metadata.mobile.json.d.cts +4 -4
- package/mobile/metadata/metadata.mobile.json.d.ts +4 -4
- package/mobile/metadata/metadata.mobile.json.js +1 -1
- package/mobile/metadata/package.json +16 -16
- package/mobile/package.json +14 -14
- package/package.json +202 -202
- package/source/AsYouType.js +539 -539
- package/source/AsYouTypeFormatter.PatternMatcher.d.ts +66 -66
- package/source/AsYouTypeFormatter.PatternMatcher.js +196 -196
- package/source/AsYouTypeFormatter.PatternParser.d.ts +58 -58
- package/source/AsYouTypeFormatter.PatternParser.js +213 -213
- package/source/AsYouTypeFormatter.complete.js +134 -134
- package/source/AsYouTypeFormatter.js +713 -713
- package/source/AsYouTypeFormatter.util.js +99 -99
- package/source/AsYouTypeParser.js +519 -519
- package/source/AsYouTypeState.js +123 -123
- package/source/ParseError.js +13 -13
- package/source/PhoneNumber.js +161 -161
- package/source/PhoneNumberMatcher.js +398 -398
- package/source/constants.js +30 -30
- package/source/findNumbers/LRUCache.js +106 -106
- package/source/findNumbers/Leniency.js +407 -407
- package/source/findNumbers/RegExpCache.js +19 -19
- package/source/findNumbers/isValidCandidate.js +85 -85
- package/source/findNumbers/isValidPreCandidate.js +28 -28
- package/source/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +63 -63
- package/source/findNumbers/parsePreCandidate.js +18 -18
- package/source/findNumbers/utf-8.js +81 -81
- package/source/findNumbers/util.js +33 -33
- package/source/findPhoneNumbersInText.js +11 -11
- package/source/format.js +235 -235
- package/source/formatIncompletePhoneNumber.js +16 -16
- package/source/formatPhoneNumberForMobileDialing.js +224 -224
- package/source/getCountries.js +4 -4
- package/source/getCountryCallingCode.js +1 -1
- package/source/getExampleNumber.js +6 -6
- package/source/helpers/RFC3966.js +58 -58
- package/source/helpers/applyInternationalSeparatorStyle.js +34 -34
- package/source/helpers/checkNumberLength.js +133 -133
- package/source/helpers/extension/createExtensionPattern.js +111 -111
- package/source/helpers/extension/extractExtension.js +28 -28
- package/source/helpers/extractCountryCallingCode.js +160 -160
- package/source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +83 -83
- package/source/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +73 -73
- package/source/helpers/extractNationalNumber.js +123 -123
- package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +103 -103
- package/source/helpers/extractPhoneContext.js +102 -102
- package/source/helpers/formatNationalNumberUsingFormat.js +45 -45
- package/source/helpers/getCountryAndCallingCodeFromOneOfThem.js +30 -30
- package/source/helpers/getCountryByCallingCode.js +32 -32
- package/source/helpers/getCountryByNationalNumber.js +75 -75
- package/source/helpers/getIddPrefix.js +25 -25
- package/source/helpers/getNumberType.js +101 -101
- package/source/helpers/getPossibleCountriesForNumber.js +24 -24
- package/source/helpers/isCallingCode.js +5 -5
- package/source/helpers/isCountryCode.js +5 -5
- package/source/helpers/isObject.js +5 -5
- package/source/helpers/isViablePhoneNumber.js +107 -107
- package/source/helpers/matchesEntirely.js +10 -10
- package/source/helpers/mergeArrays.js +23 -23
- package/source/helpers/parseDigits.js +81 -81
- package/source/helpers/stripIddPrefix.js +35 -35
- package/source/isPossible.js +84 -84
- package/source/isPossiblePhoneNumber.js +11 -11
- package/source/isValid.js +58 -58
- package/source/isValidPhoneNumber.js +11 -11
- package/source/legacy/PhoneNumberSearch.js +121 -121
- package/source/legacy/findNumbers.js +11 -11
- package/source/legacy/findPhoneNumbers.js +19 -19
- package/source/legacy/findPhoneNumbersInitialImplementation.js +81 -81
- package/source/legacy/format.js +116 -116
- package/source/legacy/getNumberType.js +120 -120
- package/source/legacy/isPossibleNumber.js +24 -24
- package/source/legacy/isValidNumber.js +11 -11
- package/source/legacy/isValidNumberForRegion.js +61 -61
- package/source/legacy/isValidNumberForRegion_.js +12 -12
- package/source/legacy/parse.js +6 -6
- package/source/legacy/searchNumbers.js +30 -30
- package/source/metadata.js +580 -580
- package/source/normalizeArguments.js +54 -54
- package/source/parse.js +403 -403
- package/source/parseIncompletePhoneNumber.js +68 -68
- package/source/parsePhoneNumber.js +7 -7
- package/source/parsePhoneNumberWithError.js +6 -6
- package/source/parsePhoneNumberWithError_.js +4 -4
- package/source/parsePhoneNumber_.js +24 -24
- package/source/searchPhoneNumbersInText.js +23 -23
- package/source/tools/semver-compare.js +25 -25
- package/source/validatePhoneNumberLength.js +30 -30
- package/types.d.cts +181 -181
- package/types.d.ts +181 -181
package/source/metadata.js
CHANGED
|
@@ -1,581 +1,581 @@
|
|
|
1
|
-
import compare from './tools/semver-compare.js'
|
|
2
|
-
import isObject from './helpers/isObject.js'
|
|
3
|
-
import isCallingCode from './helpers/isCallingCode.js'
|
|
4
|
-
|
|
5
|
-
// Added "possibleLengths" and renamed
|
|
6
|
-
// "country_phone_code_to_countries" to "country_calling_codes".
|
|
7
|
-
const V2 = '1.0.18'
|
|
8
|
-
|
|
9
|
-
// Added "idd_prefix" and "default_idd_prefix".
|
|
10
|
-
const V3 = '1.2.0'
|
|
11
|
-
|
|
12
|
-
// Moved `001` country code to "nonGeographic" section of metadata.
|
|
13
|
-
const V4 = '1.7.35'
|
|
14
|
-
|
|
15
|
-
const DEFAULT_EXT_PREFIX = ' ext. '
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* See: https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md
|
|
19
|
-
*/
|
|
20
|
-
export default class Metadata {
|
|
21
|
-
/**
|
|
22
|
-
* @param {object} metadata — Metadata JSON.
|
|
23
|
-
*/
|
|
24
|
-
constructor(metadata) {
|
|
25
|
-
validateMetadata(metadata)
|
|
26
|
-
this.metadata = metadata
|
|
27
|
-
setVersion.call(this, metadata)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getCountries() {
|
|
31
|
-
return Object.keys(this.metadata.countries).filter(_ => _ !== '001')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getCountryMetadata(countryCode) {
|
|
35
|
-
return this.metadata.countries[countryCode]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
nonGeographic() {
|
|
39
|
-
if (this.v1 || this.v2 || this.v3) return
|
|
40
|
-
// `nonGeographical` was a typo.
|
|
41
|
-
// It's present in metadata generated from `1.7.35` to `1.7.37`.
|
|
42
|
-
// The test case could be found by searching for "nonGeographical".
|
|
43
|
-
return this.metadata.nonGeographic || this.metadata.nonGeographical
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
hasCountry(country) {
|
|
47
|
-
return this.getCountryMetadata(country) !== undefined
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
hasCallingCode(callingCode) {
|
|
51
|
-
if (this.getCountryCodesForCallingCode(callingCode)) {
|
|
52
|
-
return true
|
|
53
|
-
}
|
|
54
|
-
if (this.nonGeographic()) {
|
|
55
|
-
if (this.nonGeographic()[callingCode]) {
|
|
56
|
-
return true
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
// A hacky workaround for old custom metadata (generated before V4).
|
|
60
|
-
const countryCodes = this.countryCallingCodes()[callingCode]
|
|
61
|
-
if (countryCodes && countryCodes.length === 1 && countryCodes[0] === '001') {
|
|
62
|
-
return true
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
isNonGeographicCallingCode(callingCode) {
|
|
68
|
-
if (this.nonGeographic()) {
|
|
69
|
-
return this.nonGeographic()[callingCode] ? true : false
|
|
70
|
-
} else {
|
|
71
|
-
return this.getCountryCodesForCallingCode(callingCode) ? false : true
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Deprecated.
|
|
76
|
-
country(countryCode) {
|
|
77
|
-
return this.selectNumberingPlan(countryCode)
|
|
78
|
-
}
|
|
79
|
-
|
|
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
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Select a telephone numbering plan.
|
|
103
|
-
if (countryCode && countryCode !== '001') {
|
|
104
|
-
const countryMetadata = this.getCountryMetadata(countryCode)
|
|
105
|
-
if (!countryMetadata) {
|
|
106
|
-
throw new Error(`Unknown country: ${countryCode}`)
|
|
107
|
-
}
|
|
108
|
-
this.numberingPlan = new NumberingPlan(countryMetadata, this)
|
|
109
|
-
} else if (callingCode) {
|
|
110
|
-
if (!this.hasCallingCode(callingCode)) {
|
|
111
|
-
throw new Error(`Unknown calling code: ${callingCode}`)
|
|
112
|
-
}
|
|
113
|
-
this.numberingPlan = new NumberingPlan(this.getNumberingPlanMetadata(callingCode), this)
|
|
114
|
-
} else {
|
|
115
|
-
this.numberingPlan = undefined
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return this
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
getCountryCodesForCallingCode(callingCode) {
|
|
122
|
-
const countryCodes = this.countryCallingCodes()[callingCode]
|
|
123
|
-
if (countryCodes) {
|
|
124
|
-
// Metadata before V4 included "non-geographic entity" calling codes
|
|
125
|
-
// inside `country_calling_codes` (for example, `"881":["001"]`).
|
|
126
|
-
// Now the semantics of `country_calling_codes` has changed:
|
|
127
|
-
// it's specifically for "countries" now.
|
|
128
|
-
// Older versions of custom metadata will simply skip parsing
|
|
129
|
-
// "non-geographic entity" phone numbers with new versions
|
|
130
|
-
// of this library: it's not considered a bug,
|
|
131
|
-
// because such numbers are extremely rare,
|
|
132
|
-
// and developers extremely rarely use custom metadata.
|
|
133
|
-
if (countryCodes.length === 1 && countryCodes[0].length === 3) {
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
return countryCodes
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
getCountryCodeForCallingCode(callingCode) {
|
|
141
|
-
const countryCodes = this.getCountryCodesForCallingCode(callingCode)
|
|
142
|
-
if (countryCodes) {
|
|
143
|
-
return countryCodes[0]
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
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.
|
|
152
|
-
const countryCode = this.getCountryCodeForCallingCode(callingCode)
|
|
153
|
-
if (countryCode) {
|
|
154
|
-
return this.getCountryMetadata(countryCode)
|
|
155
|
-
}
|
|
156
|
-
if (this.nonGeographic()) {
|
|
157
|
-
const metadata = this.nonGeographic()[callingCode]
|
|
158
|
-
if (metadata) {
|
|
159
|
-
return metadata
|
|
160
|
-
}
|
|
161
|
-
} else {
|
|
162
|
-
// A hacky workaround for old custom metadata (generated before V4).
|
|
163
|
-
// In that metadata, there was no concept of "non-geographic" metadata
|
|
164
|
-
// so metadata for `001` country code was stored along with other countries.
|
|
165
|
-
// The test case can be found by searching for:
|
|
166
|
-
// "should work around `nonGeographic` metadata not existing".
|
|
167
|
-
const countryCodes = this.countryCallingCodes()[callingCode]
|
|
168
|
-
if (countryCodes && countryCodes.length === 1 && countryCodes[0] === '001') {
|
|
169
|
-
return this.metadata.countries['001']
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Deprecated.
|
|
175
|
-
countryCallingCode() {
|
|
176
|
-
return this.numberingPlan.callingCode()
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Deprecated.
|
|
180
|
-
IDDPrefix() {
|
|
181
|
-
return this.numberingPlan.IDDPrefix()
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Deprecated.
|
|
185
|
-
defaultIDDPrefix() {
|
|
186
|
-
return this.numberingPlan.defaultIDDPrefix()
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Deprecated.
|
|
190
|
-
nationalNumberPattern() {
|
|
191
|
-
return this.numberingPlan.nationalNumberPattern()
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Deprecated.
|
|
195
|
-
possibleLengths() {
|
|
196
|
-
return this.numberingPlan.possibleLengths()
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Deprecated.
|
|
200
|
-
formats() {
|
|
201
|
-
return this.numberingPlan.formats()
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Deprecated.
|
|
205
|
-
nationalPrefixForParsing() {
|
|
206
|
-
return this.numberingPlan.nationalPrefixForParsing()
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Deprecated.
|
|
210
|
-
nationalPrefixTransformRule() {
|
|
211
|
-
return this.numberingPlan.nationalPrefixTransformRule()
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Deprecated.
|
|
215
|
-
leadingDigits() {
|
|
216
|
-
return this.numberingPlan.leadingDigits()
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Deprecated.
|
|
220
|
-
hasTypes() {
|
|
221
|
-
return this.numberingPlan.hasTypes()
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Deprecated.
|
|
225
|
-
type(type) {
|
|
226
|
-
return this.numberingPlan.type(type)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Deprecated.
|
|
230
|
-
ext() {
|
|
231
|
-
return this.numberingPlan.ext()
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
countryCallingCodes() {
|
|
235
|
-
if (this.v1) return this.metadata.country_phone_code_to_countries
|
|
236
|
-
return this.metadata.country_calling_codes
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Deprecated.
|
|
240
|
-
chooseCountryByCountryCallingCode(callingCode) {
|
|
241
|
-
return this.selectNumberingPlan(callingCode)
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
hasSelectedNumberingPlan() {
|
|
245
|
-
return this.numberingPlan !== undefined
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
class NumberingPlan {
|
|
250
|
-
constructor(metadata, globalMetadataObject) {
|
|
251
|
-
this.globalMetadataObject = globalMetadataObject
|
|
252
|
-
this.metadata = metadata
|
|
253
|
-
setVersion.call(this, globalMetadataObject.metadata)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
callingCode() {
|
|
257
|
-
return this.metadata[0]
|
|
258
|
-
}
|
|
259
|
-
|
|
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() {
|
|
273
|
-
return this.globalMetadataObject.getNumberingPlanMetadata(this.callingCode())
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Deprecated.
|
|
277
|
-
getDefaultCountryMetadataForRegion() {
|
|
278
|
-
return this._getDefaultCountryMetadataForThisCallingCode()
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Is always present.
|
|
282
|
-
IDDPrefix() {
|
|
283
|
-
if (this.v1 || this.v2) return
|
|
284
|
-
return this.metadata[1]
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// Is only present when a country supports multiple IDD prefixes.
|
|
288
|
-
defaultIDDPrefix() {
|
|
289
|
-
if (this.v1 || this.v2) return
|
|
290
|
-
return this.metadata[12]
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
nationalNumberPattern() {
|
|
294
|
-
if (this.v1 || this.v2) return this.metadata[1]
|
|
295
|
-
return this.metadata[2]
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// "possible length" data is always present in Google's metadata.
|
|
299
|
-
possibleLengths() {
|
|
300
|
-
if (this.v1) return
|
|
301
|
-
return this.metadata[this.v2 ? 2 : 3]
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
_getFormats(metadata) {
|
|
305
|
-
return metadata[this.v1 ? 2 : this.v2 ? 3 : 4]
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// For countries of the same region (e.g. NANPA)
|
|
309
|
-
// formats are all stored in the "main" country for that region.
|
|
310
|
-
// E.g. "RU" and "KZ", "US" and "CA".
|
|
311
|
-
formats() {
|
|
312
|
-
const formats = this._getFormats(this.metadata) || this._getFormats(this._getDefaultCountryMetadataForThisCallingCode()) || []
|
|
313
|
-
return formats.map(_ => new Format(_, this))
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
nationalPrefix() {
|
|
317
|
-
return this.metadata[this.v1 ? 3 : this.v2 ? 4 : 5]
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
_getNationalPrefixFormattingRule(metadata) {
|
|
321
|
-
return metadata[this.v1 ? 4 : this.v2 ? 5 : 6]
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// For countries of the same region (e.g. NANPA)
|
|
325
|
-
// national prefix formatting rule is stored in the "main" country for that region.
|
|
326
|
-
// E.g. "RU" and "KZ", "US" and "CA".
|
|
327
|
-
nationalPrefixFormattingRule() {
|
|
328
|
-
return this._getNationalPrefixFormattingRule(this.metadata) || this._getNationalPrefixFormattingRule(this._getDefaultCountryMetadataForThisCallingCode())
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
_nationalPrefixForParsing() {
|
|
332
|
-
return this.metadata[this.v1 ? 5 : this.v2 ? 6 : 7]
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
nationalPrefixForParsing() {
|
|
336
|
-
// If `national_prefix_for_parsing` is not set explicitly,
|
|
337
|
-
// then infer it from `national_prefix` (if any)
|
|
338
|
-
return this._nationalPrefixForParsing() || this.nationalPrefix()
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
nationalPrefixTransformRule() {
|
|
342
|
-
return this.metadata[this.v1 ? 6 : this.v2 ? 7 : 8]
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
_getNationalPrefixIsOptionalWhenFormatting() {
|
|
346
|
-
return !!this.metadata[this.v1 ? 7 : this.v2 ? 8 : 9]
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// For countries of the same region (e.g. NANPA)
|
|
350
|
-
// "national prefix is optional when formatting" flag is
|
|
351
|
-
// stored in the "main" country for that region.
|
|
352
|
-
// E.g. "RU" and "KZ", "US" and "CA".
|
|
353
|
-
nationalPrefixIsOptionalWhenFormattingInNationalFormat() {
|
|
354
|
-
return this._getNationalPrefixIsOptionalWhenFormatting(this.metadata) ||
|
|
355
|
-
this._getNationalPrefixIsOptionalWhenFormatting(this._getDefaultCountryMetadataForThisCallingCode())
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
leadingDigits() {
|
|
359
|
-
return this.metadata[this.v1 ? 8 : this.v2 ? 9 : 10]
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
types() {
|
|
363
|
-
return this.metadata[this.v1 ? 9 : this.v2 ? 10 : 11]
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
hasTypes() {
|
|
367
|
-
// Versions 1.2.0 - 1.2.4: can be `[]`.
|
|
368
|
-
/* istanbul ignore next */
|
|
369
|
-
if (this.types() && this.types().length === 0) {
|
|
370
|
-
return false
|
|
371
|
-
}
|
|
372
|
-
// Versions <= 1.2.4: can be `undefined`.
|
|
373
|
-
// Version >= 1.2.5: can be `0`.
|
|
374
|
-
return !!this.types()
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
type(type) {
|
|
378
|
-
if (this.hasTypes() && getType(this.types(), type)) {
|
|
379
|
-
return new Type(getType(this.types(), type), this)
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
ext() {
|
|
384
|
-
if (this.v1 || this.v2) return DEFAULT_EXT_PREFIX
|
|
385
|
-
return this.metadata[13] || DEFAULT_EXT_PREFIX
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
class Format {
|
|
390
|
-
constructor(format, metadata) {
|
|
391
|
-
this._format = format
|
|
392
|
-
this.metadata = metadata
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
pattern() {
|
|
396
|
-
return this._format[0]
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
format() {
|
|
400
|
-
return this._format[1]
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
leadingDigitsPatterns() {
|
|
404
|
-
return this._format[2] || []
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
nationalPrefixFormattingRule() {
|
|
408
|
-
return this._format[3] || this.metadata.nationalPrefixFormattingRule()
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
nationalPrefixIsOptionalWhenFormattingInNationalFormat() {
|
|
412
|
-
return !!this._format[4] || this.metadata.nationalPrefixIsOptionalWhenFormattingInNationalFormat()
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
nationalPrefixIsMandatoryWhenFormattingInNationalFormat() {
|
|
416
|
-
// National prefix is omitted if there's no national prefix formatting rule
|
|
417
|
-
// set for this country, or when the national prefix formatting rule
|
|
418
|
-
// contains no national prefix itself, or when this rule is set but
|
|
419
|
-
// national prefix is optional for this phone number format
|
|
420
|
-
// (and it is not enforced explicitly)
|
|
421
|
-
return this.usesNationalPrefix() && !this.nationalPrefixIsOptionalWhenFormattingInNationalFormat()
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// Checks whether national prefix formatting rule contains national prefix.
|
|
425
|
-
usesNationalPrefix() {
|
|
426
|
-
return this.nationalPrefixFormattingRule() &&
|
|
427
|
-
// Check that national prefix formatting rule is not a "dummy" one.
|
|
428
|
-
!FIRST_GROUP_ONLY_PREFIX_PATTERN.test(this.nationalPrefixFormattingRule())
|
|
429
|
-
// In compressed metadata, `this.nationalPrefixFormattingRule()` is `0`
|
|
430
|
-
// when `national_prefix_formatting_rule` is not present.
|
|
431
|
-
// So, `true` or `false` are returned explicitly here, so that
|
|
432
|
-
// `0` number isn't returned.
|
|
433
|
-
? true
|
|
434
|
-
: false
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
internationalFormat() {
|
|
438
|
-
return this._format[5] || this.format()
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* A pattern that is used to determine if the national prefix formatting rule
|
|
444
|
-
* has the first group only, i.e., does not start with the national prefix.
|
|
445
|
-
* Note that the pattern explicitly allows for unbalanced parentheses.
|
|
446
|
-
*/
|
|
447
|
-
const FIRST_GROUP_ONLY_PREFIX_PATTERN = /^\(?\$1\)?$/
|
|
448
|
-
|
|
449
|
-
class Type {
|
|
450
|
-
constructor(type, metadata) {
|
|
451
|
-
this.type = type
|
|
452
|
-
this.metadata = metadata
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
pattern() {
|
|
456
|
-
if (this.metadata.v1) return this.type
|
|
457
|
-
return this.type[0]
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
possibleLengths() {
|
|
461
|
-
if (this.metadata.v1) return
|
|
462
|
-
return this.type[1] || this.metadata.possibleLengths()
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
function getType(types, type) {
|
|
467
|
-
switch (type) {
|
|
468
|
-
case 'FIXED_LINE':
|
|
469
|
-
return types[0]
|
|
470
|
-
case 'MOBILE':
|
|
471
|
-
return types[1]
|
|
472
|
-
case 'TOLL_FREE':
|
|
473
|
-
return types[2]
|
|
474
|
-
case 'PREMIUM_RATE':
|
|
475
|
-
return types[3]
|
|
476
|
-
case 'PERSONAL_NUMBER':
|
|
477
|
-
return types[4]
|
|
478
|
-
case 'VOICEMAIL':
|
|
479
|
-
return types[5]
|
|
480
|
-
case 'UAN':
|
|
481
|
-
return types[6]
|
|
482
|
-
case 'PAGER':
|
|
483
|
-
return types[7]
|
|
484
|
-
case 'VOIP':
|
|
485
|
-
return types[8]
|
|
486
|
-
case 'SHARED_COST':
|
|
487
|
-
return types[9]
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
export function validateMetadata(metadata) {
|
|
492
|
-
if (!metadata) {
|
|
493
|
-
throw new Error('[libphonenumber-js] `metadata` argument not passed. Check your arguments.')
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// `country_phone_code_to_countries` was renamed to `country_calling_codes` in `1.0.18`.
|
|
497
|
-
// For that reason, it's not used in this detection algorithm.
|
|
498
|
-
// Instead, it detects by `countries: {}` property existence.
|
|
499
|
-
if (!isObject(metadata) || !isObject(metadata.countries)) {
|
|
500
|
-
throw new Error(`[libphonenumber-js] \`metadata\` argument was passed but it's not a valid metadata. Must be an object having \`.countries\` child object property. Got ${isObject(metadata) ? 'an object of shape: { ' + Object.keys(metadata).join(', ') + ' }' : 'a ' + typeOf(metadata) + ': ' + metadata}.`)
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
// Babel transforms `typeof` into some "branches"
|
|
505
|
-
// so istanbul will show this as "branch not covered".
|
|
506
|
-
/* istanbul ignore next */
|
|
507
|
-
const typeOf = _ => typeof _
|
|
508
|
-
|
|
509
|
-
/**
|
|
510
|
-
* Returns extension prefix for a country.
|
|
511
|
-
* @param {string} country
|
|
512
|
-
* @param {object} metadata
|
|
513
|
-
* @return {string?}
|
|
514
|
-
* @example
|
|
515
|
-
* // Returns " ext. "
|
|
516
|
-
* getExtPrefix("US")
|
|
517
|
-
*/
|
|
518
|
-
export function getExtPrefix(country, metadataJson) {
|
|
519
|
-
const metadata = new Metadata(metadataJson)
|
|
520
|
-
if (metadata.hasCountry(country)) {
|
|
521
|
-
return metadata.selectNumberingPlan(country).ext()
|
|
522
|
-
}
|
|
523
|
-
return DEFAULT_EXT_PREFIX
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Returns "country calling code" for a country.
|
|
528
|
-
* Throws an error if the country doesn't exist or isn't supported by this library.
|
|
529
|
-
* @param {string} country
|
|
530
|
-
* @param {object} metadataJson
|
|
531
|
-
* @return {string}
|
|
532
|
-
* @example
|
|
533
|
-
* // Returns "44"
|
|
534
|
-
* getCountryCallingCode("GB")
|
|
535
|
-
*/
|
|
536
|
-
export function getCountryCallingCode(country, metadataJson) {
|
|
537
|
-
const metadata = new Metadata(metadataJson)
|
|
538
|
-
if (metadata.hasCountry(country)) {
|
|
539
|
-
return metadata.selectNumberingPlan(country).countryCallingCode()
|
|
540
|
-
}
|
|
541
|
-
throw new Error(`Unknown country: ${country}`)
|
|
542
|
-
}
|
|
543
|
-
|
|
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)
|
|
555
|
-
// return metadata.hasCountry(country)
|
|
556
|
-
return metadataJson.countries.hasOwnProperty(country)
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Sets `v1`/`v2`/`v3`/`v4` properties on `this` object.
|
|
561
|
-
* @param {object} metadata — Metadata JSON
|
|
562
|
-
*/
|
|
563
|
-
function setVersion(metadata) {
|
|
564
|
-
const { version } = metadata
|
|
565
|
-
if (typeof version === 'number') {
|
|
566
|
-
this.v1 = version === 1
|
|
567
|
-
this.v2 = version === 2
|
|
568
|
-
this.v3 = version === 3
|
|
569
|
-
this.v4 = version === 4
|
|
570
|
-
} else {
|
|
571
|
-
if (!version) {
|
|
572
|
-
this.v1 = true
|
|
573
|
-
} else if (compare(version, V3) === -1) {
|
|
574
|
-
this.v2 = true
|
|
575
|
-
} else if (compare(version, V4) === -1) {
|
|
576
|
-
this.v3 = true
|
|
577
|
-
} else {
|
|
578
|
-
this.v4 = true
|
|
579
|
-
}
|
|
580
|
-
}
|
|
1
|
+
import compare from './tools/semver-compare.js'
|
|
2
|
+
import isObject from './helpers/isObject.js'
|
|
3
|
+
import isCallingCode from './helpers/isCallingCode.js'
|
|
4
|
+
|
|
5
|
+
// Added "possibleLengths" and renamed
|
|
6
|
+
// "country_phone_code_to_countries" to "country_calling_codes".
|
|
7
|
+
const V2 = '1.0.18'
|
|
8
|
+
|
|
9
|
+
// Added "idd_prefix" and "default_idd_prefix".
|
|
10
|
+
const V3 = '1.2.0'
|
|
11
|
+
|
|
12
|
+
// Moved `001` country code to "nonGeographic" section of metadata.
|
|
13
|
+
const V4 = '1.7.35'
|
|
14
|
+
|
|
15
|
+
const DEFAULT_EXT_PREFIX = ' ext. '
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* See: https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md
|
|
19
|
+
*/
|
|
20
|
+
export default class Metadata {
|
|
21
|
+
/**
|
|
22
|
+
* @param {object} metadata — Metadata JSON.
|
|
23
|
+
*/
|
|
24
|
+
constructor(metadata) {
|
|
25
|
+
validateMetadata(metadata)
|
|
26
|
+
this.metadata = metadata
|
|
27
|
+
setVersion.call(this, metadata)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getCountries() {
|
|
31
|
+
return Object.keys(this.metadata.countries).filter(_ => _ !== '001')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getCountryMetadata(countryCode) {
|
|
35
|
+
return this.metadata.countries[countryCode]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
nonGeographic() {
|
|
39
|
+
if (this.v1 || this.v2 || this.v3) return
|
|
40
|
+
// `nonGeographical` was a typo.
|
|
41
|
+
// It's present in metadata generated from `1.7.35` to `1.7.37`.
|
|
42
|
+
// The test case could be found by searching for "nonGeographical".
|
|
43
|
+
return this.metadata.nonGeographic || this.metadata.nonGeographical
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
hasCountry(country) {
|
|
47
|
+
return this.getCountryMetadata(country) !== undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
hasCallingCode(callingCode) {
|
|
51
|
+
if (this.getCountryCodesForCallingCode(callingCode)) {
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
if (this.nonGeographic()) {
|
|
55
|
+
if (this.nonGeographic()[callingCode]) {
|
|
56
|
+
return true
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
// A hacky workaround for old custom metadata (generated before V4).
|
|
60
|
+
const countryCodes = this.countryCallingCodes()[callingCode]
|
|
61
|
+
if (countryCodes && countryCodes.length === 1 && countryCodes[0] === '001') {
|
|
62
|
+
return true
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
isNonGeographicCallingCode(callingCode) {
|
|
68
|
+
if (this.nonGeographic()) {
|
|
69
|
+
return this.nonGeographic()[callingCode] ? true : false
|
|
70
|
+
} else {
|
|
71
|
+
return this.getCountryCodesForCallingCode(callingCode) ? false : true
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Deprecated.
|
|
76
|
+
country(countryCode) {
|
|
77
|
+
return this.selectNumberingPlan(countryCode)
|
|
78
|
+
}
|
|
79
|
+
|
|
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
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Select a telephone numbering plan.
|
|
103
|
+
if (countryCode && countryCode !== '001') {
|
|
104
|
+
const countryMetadata = this.getCountryMetadata(countryCode)
|
|
105
|
+
if (!countryMetadata) {
|
|
106
|
+
throw new Error(`Unknown country: ${countryCode}`)
|
|
107
|
+
}
|
|
108
|
+
this.numberingPlan = new NumberingPlan(countryMetadata, this)
|
|
109
|
+
} else if (callingCode) {
|
|
110
|
+
if (!this.hasCallingCode(callingCode)) {
|
|
111
|
+
throw new Error(`Unknown calling code: ${callingCode}`)
|
|
112
|
+
}
|
|
113
|
+
this.numberingPlan = new NumberingPlan(this.getNumberingPlanMetadata(callingCode), this)
|
|
114
|
+
} else {
|
|
115
|
+
this.numberingPlan = undefined
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return this
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
getCountryCodesForCallingCode(callingCode) {
|
|
122
|
+
const countryCodes = this.countryCallingCodes()[callingCode]
|
|
123
|
+
if (countryCodes) {
|
|
124
|
+
// Metadata before V4 included "non-geographic entity" calling codes
|
|
125
|
+
// inside `country_calling_codes` (for example, `"881":["001"]`).
|
|
126
|
+
// Now the semantics of `country_calling_codes` has changed:
|
|
127
|
+
// it's specifically for "countries" now.
|
|
128
|
+
// Older versions of custom metadata will simply skip parsing
|
|
129
|
+
// "non-geographic entity" phone numbers with new versions
|
|
130
|
+
// of this library: it's not considered a bug,
|
|
131
|
+
// because such numbers are extremely rare,
|
|
132
|
+
// and developers extremely rarely use custom metadata.
|
|
133
|
+
if (countryCodes.length === 1 && countryCodes[0].length === 3) {
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
return countryCodes
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
getCountryCodeForCallingCode(callingCode) {
|
|
141
|
+
const countryCodes = this.getCountryCodesForCallingCode(callingCode)
|
|
142
|
+
if (countryCodes) {
|
|
143
|
+
return countryCodes[0]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
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.
|
|
152
|
+
const countryCode = this.getCountryCodeForCallingCode(callingCode)
|
|
153
|
+
if (countryCode) {
|
|
154
|
+
return this.getCountryMetadata(countryCode)
|
|
155
|
+
}
|
|
156
|
+
if (this.nonGeographic()) {
|
|
157
|
+
const metadata = this.nonGeographic()[callingCode]
|
|
158
|
+
if (metadata) {
|
|
159
|
+
return metadata
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
// A hacky workaround for old custom metadata (generated before V4).
|
|
163
|
+
// In that metadata, there was no concept of "non-geographic" metadata
|
|
164
|
+
// so metadata for `001` country code was stored along with other countries.
|
|
165
|
+
// The test case can be found by searching for:
|
|
166
|
+
// "should work around `nonGeographic` metadata not existing".
|
|
167
|
+
const countryCodes = this.countryCallingCodes()[callingCode]
|
|
168
|
+
if (countryCodes && countryCodes.length === 1 && countryCodes[0] === '001') {
|
|
169
|
+
return this.metadata.countries['001']
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Deprecated.
|
|
175
|
+
countryCallingCode() {
|
|
176
|
+
return this.numberingPlan.callingCode()
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Deprecated.
|
|
180
|
+
IDDPrefix() {
|
|
181
|
+
return this.numberingPlan.IDDPrefix()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Deprecated.
|
|
185
|
+
defaultIDDPrefix() {
|
|
186
|
+
return this.numberingPlan.defaultIDDPrefix()
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Deprecated.
|
|
190
|
+
nationalNumberPattern() {
|
|
191
|
+
return this.numberingPlan.nationalNumberPattern()
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Deprecated.
|
|
195
|
+
possibleLengths() {
|
|
196
|
+
return this.numberingPlan.possibleLengths()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Deprecated.
|
|
200
|
+
formats() {
|
|
201
|
+
return this.numberingPlan.formats()
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Deprecated.
|
|
205
|
+
nationalPrefixForParsing() {
|
|
206
|
+
return this.numberingPlan.nationalPrefixForParsing()
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Deprecated.
|
|
210
|
+
nationalPrefixTransformRule() {
|
|
211
|
+
return this.numberingPlan.nationalPrefixTransformRule()
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Deprecated.
|
|
215
|
+
leadingDigits() {
|
|
216
|
+
return this.numberingPlan.leadingDigits()
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Deprecated.
|
|
220
|
+
hasTypes() {
|
|
221
|
+
return this.numberingPlan.hasTypes()
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Deprecated.
|
|
225
|
+
type(type) {
|
|
226
|
+
return this.numberingPlan.type(type)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Deprecated.
|
|
230
|
+
ext() {
|
|
231
|
+
return this.numberingPlan.ext()
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
countryCallingCodes() {
|
|
235
|
+
if (this.v1) return this.metadata.country_phone_code_to_countries
|
|
236
|
+
return this.metadata.country_calling_codes
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Deprecated.
|
|
240
|
+
chooseCountryByCountryCallingCode(callingCode) {
|
|
241
|
+
return this.selectNumberingPlan(callingCode)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
hasSelectedNumberingPlan() {
|
|
245
|
+
return this.numberingPlan !== undefined
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
class NumberingPlan {
|
|
250
|
+
constructor(metadata, globalMetadataObject) {
|
|
251
|
+
this.globalMetadataObject = globalMetadataObject
|
|
252
|
+
this.metadata = metadata
|
|
253
|
+
setVersion.call(this, globalMetadataObject.metadata)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
callingCode() {
|
|
257
|
+
return this.metadata[0]
|
|
258
|
+
}
|
|
259
|
+
|
|
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() {
|
|
273
|
+
return this.globalMetadataObject.getNumberingPlanMetadata(this.callingCode())
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Deprecated.
|
|
277
|
+
getDefaultCountryMetadataForRegion() {
|
|
278
|
+
return this._getDefaultCountryMetadataForThisCallingCode()
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Is always present.
|
|
282
|
+
IDDPrefix() {
|
|
283
|
+
if (this.v1 || this.v2) return
|
|
284
|
+
return this.metadata[1]
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Is only present when a country supports multiple IDD prefixes.
|
|
288
|
+
defaultIDDPrefix() {
|
|
289
|
+
if (this.v1 || this.v2) return
|
|
290
|
+
return this.metadata[12]
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
nationalNumberPattern() {
|
|
294
|
+
if (this.v1 || this.v2) return this.metadata[1]
|
|
295
|
+
return this.metadata[2]
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// "possible length" data is always present in Google's metadata.
|
|
299
|
+
possibleLengths() {
|
|
300
|
+
if (this.v1) return
|
|
301
|
+
return this.metadata[this.v2 ? 2 : 3]
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
_getFormats(metadata) {
|
|
305
|
+
return metadata[this.v1 ? 2 : this.v2 ? 3 : 4]
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// For countries of the same region (e.g. NANPA)
|
|
309
|
+
// formats are all stored in the "main" country for that region.
|
|
310
|
+
// E.g. "RU" and "KZ", "US" and "CA".
|
|
311
|
+
formats() {
|
|
312
|
+
const formats = this._getFormats(this.metadata) || this._getFormats(this._getDefaultCountryMetadataForThisCallingCode()) || []
|
|
313
|
+
return formats.map(_ => new Format(_, this))
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
nationalPrefix() {
|
|
317
|
+
return this.metadata[this.v1 ? 3 : this.v2 ? 4 : 5]
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
_getNationalPrefixFormattingRule(metadata) {
|
|
321
|
+
return metadata[this.v1 ? 4 : this.v2 ? 5 : 6]
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// For countries of the same region (e.g. NANPA)
|
|
325
|
+
// national prefix formatting rule is stored in the "main" country for that region.
|
|
326
|
+
// E.g. "RU" and "KZ", "US" and "CA".
|
|
327
|
+
nationalPrefixFormattingRule() {
|
|
328
|
+
return this._getNationalPrefixFormattingRule(this.metadata) || this._getNationalPrefixFormattingRule(this._getDefaultCountryMetadataForThisCallingCode())
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
_nationalPrefixForParsing() {
|
|
332
|
+
return this.metadata[this.v1 ? 5 : this.v2 ? 6 : 7]
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
nationalPrefixForParsing() {
|
|
336
|
+
// If `national_prefix_for_parsing` is not set explicitly,
|
|
337
|
+
// then infer it from `national_prefix` (if any)
|
|
338
|
+
return this._nationalPrefixForParsing() || this.nationalPrefix()
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
nationalPrefixTransformRule() {
|
|
342
|
+
return this.metadata[this.v1 ? 6 : this.v2 ? 7 : 8]
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
_getNationalPrefixIsOptionalWhenFormatting() {
|
|
346
|
+
return !!this.metadata[this.v1 ? 7 : this.v2 ? 8 : 9]
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// For countries of the same region (e.g. NANPA)
|
|
350
|
+
// "national prefix is optional when formatting" flag is
|
|
351
|
+
// stored in the "main" country for that region.
|
|
352
|
+
// E.g. "RU" and "KZ", "US" and "CA".
|
|
353
|
+
nationalPrefixIsOptionalWhenFormattingInNationalFormat() {
|
|
354
|
+
return this._getNationalPrefixIsOptionalWhenFormatting(this.metadata) ||
|
|
355
|
+
this._getNationalPrefixIsOptionalWhenFormatting(this._getDefaultCountryMetadataForThisCallingCode())
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
leadingDigits() {
|
|
359
|
+
return this.metadata[this.v1 ? 8 : this.v2 ? 9 : 10]
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
types() {
|
|
363
|
+
return this.metadata[this.v1 ? 9 : this.v2 ? 10 : 11]
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
hasTypes() {
|
|
367
|
+
// Versions 1.2.0 - 1.2.4: can be `[]`.
|
|
368
|
+
/* istanbul ignore next */
|
|
369
|
+
if (this.types() && this.types().length === 0) {
|
|
370
|
+
return false
|
|
371
|
+
}
|
|
372
|
+
// Versions <= 1.2.4: can be `undefined`.
|
|
373
|
+
// Version >= 1.2.5: can be `0`.
|
|
374
|
+
return !!this.types()
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
type(type) {
|
|
378
|
+
if (this.hasTypes() && getType(this.types(), type)) {
|
|
379
|
+
return new Type(getType(this.types(), type), this)
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
ext() {
|
|
384
|
+
if (this.v1 || this.v2) return DEFAULT_EXT_PREFIX
|
|
385
|
+
return this.metadata[13] || DEFAULT_EXT_PREFIX
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
class Format {
|
|
390
|
+
constructor(format, metadata) {
|
|
391
|
+
this._format = format
|
|
392
|
+
this.metadata = metadata
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
pattern() {
|
|
396
|
+
return this._format[0]
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
format() {
|
|
400
|
+
return this._format[1]
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
leadingDigitsPatterns() {
|
|
404
|
+
return this._format[2] || []
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
nationalPrefixFormattingRule() {
|
|
408
|
+
return this._format[3] || this.metadata.nationalPrefixFormattingRule()
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
nationalPrefixIsOptionalWhenFormattingInNationalFormat() {
|
|
412
|
+
return !!this._format[4] || this.metadata.nationalPrefixIsOptionalWhenFormattingInNationalFormat()
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
nationalPrefixIsMandatoryWhenFormattingInNationalFormat() {
|
|
416
|
+
// National prefix is omitted if there's no national prefix formatting rule
|
|
417
|
+
// set for this country, or when the national prefix formatting rule
|
|
418
|
+
// contains no national prefix itself, or when this rule is set but
|
|
419
|
+
// national prefix is optional for this phone number format
|
|
420
|
+
// (and it is not enforced explicitly)
|
|
421
|
+
return this.usesNationalPrefix() && !this.nationalPrefixIsOptionalWhenFormattingInNationalFormat()
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Checks whether national prefix formatting rule contains national prefix.
|
|
425
|
+
usesNationalPrefix() {
|
|
426
|
+
return this.nationalPrefixFormattingRule() &&
|
|
427
|
+
// Check that national prefix formatting rule is not a "dummy" one.
|
|
428
|
+
!FIRST_GROUP_ONLY_PREFIX_PATTERN.test(this.nationalPrefixFormattingRule())
|
|
429
|
+
// In compressed metadata, `this.nationalPrefixFormattingRule()` is `0`
|
|
430
|
+
// when `national_prefix_formatting_rule` is not present.
|
|
431
|
+
// So, `true` or `false` are returned explicitly here, so that
|
|
432
|
+
// `0` number isn't returned.
|
|
433
|
+
? true
|
|
434
|
+
: false
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
internationalFormat() {
|
|
438
|
+
return this._format[5] || this.format()
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* A pattern that is used to determine if the national prefix formatting rule
|
|
444
|
+
* has the first group only, i.e., does not start with the national prefix.
|
|
445
|
+
* Note that the pattern explicitly allows for unbalanced parentheses.
|
|
446
|
+
*/
|
|
447
|
+
const FIRST_GROUP_ONLY_PREFIX_PATTERN = /^\(?\$1\)?$/
|
|
448
|
+
|
|
449
|
+
class Type {
|
|
450
|
+
constructor(type, metadata) {
|
|
451
|
+
this.type = type
|
|
452
|
+
this.metadata = metadata
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
pattern() {
|
|
456
|
+
if (this.metadata.v1) return this.type
|
|
457
|
+
return this.type[0]
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
possibleLengths() {
|
|
461
|
+
if (this.metadata.v1) return
|
|
462
|
+
return this.type[1] || this.metadata.possibleLengths()
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function getType(types, type) {
|
|
467
|
+
switch (type) {
|
|
468
|
+
case 'FIXED_LINE':
|
|
469
|
+
return types[0]
|
|
470
|
+
case 'MOBILE':
|
|
471
|
+
return types[1]
|
|
472
|
+
case 'TOLL_FREE':
|
|
473
|
+
return types[2]
|
|
474
|
+
case 'PREMIUM_RATE':
|
|
475
|
+
return types[3]
|
|
476
|
+
case 'PERSONAL_NUMBER':
|
|
477
|
+
return types[4]
|
|
478
|
+
case 'VOICEMAIL':
|
|
479
|
+
return types[5]
|
|
480
|
+
case 'UAN':
|
|
481
|
+
return types[6]
|
|
482
|
+
case 'PAGER':
|
|
483
|
+
return types[7]
|
|
484
|
+
case 'VOIP':
|
|
485
|
+
return types[8]
|
|
486
|
+
case 'SHARED_COST':
|
|
487
|
+
return types[9]
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export function validateMetadata(metadata) {
|
|
492
|
+
if (!metadata) {
|
|
493
|
+
throw new Error('[libphonenumber-js] `metadata` argument not passed. Check your arguments.')
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// `country_phone_code_to_countries` was renamed to `country_calling_codes` in `1.0.18`.
|
|
497
|
+
// For that reason, it's not used in this detection algorithm.
|
|
498
|
+
// Instead, it detects by `countries: {}` property existence.
|
|
499
|
+
if (!isObject(metadata) || !isObject(metadata.countries)) {
|
|
500
|
+
throw new Error(`[libphonenumber-js] \`metadata\` argument was passed but it's not a valid metadata. Must be an object having \`.countries\` child object property. Got ${isObject(metadata) ? 'an object of shape: { ' + Object.keys(metadata).join(', ') + ' }' : 'a ' + typeOf(metadata) + ': ' + metadata}.`)
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// Babel transforms `typeof` into some "branches"
|
|
505
|
+
// so istanbul will show this as "branch not covered".
|
|
506
|
+
/* istanbul ignore next */
|
|
507
|
+
const typeOf = _ => typeof _
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Returns extension prefix for a country.
|
|
511
|
+
* @param {string} country
|
|
512
|
+
* @param {object} metadata
|
|
513
|
+
* @return {string?}
|
|
514
|
+
* @example
|
|
515
|
+
* // Returns " ext. "
|
|
516
|
+
* getExtPrefix("US")
|
|
517
|
+
*/
|
|
518
|
+
export function getExtPrefix(country, metadataJson) {
|
|
519
|
+
const metadata = new Metadata(metadataJson)
|
|
520
|
+
if (metadata.hasCountry(country)) {
|
|
521
|
+
return metadata.selectNumberingPlan(country).ext()
|
|
522
|
+
}
|
|
523
|
+
return DEFAULT_EXT_PREFIX
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Returns "country calling code" for a country.
|
|
528
|
+
* Throws an error if the country doesn't exist or isn't supported by this library.
|
|
529
|
+
* @param {string} country
|
|
530
|
+
* @param {object} metadataJson
|
|
531
|
+
* @return {string}
|
|
532
|
+
* @example
|
|
533
|
+
* // Returns "44"
|
|
534
|
+
* getCountryCallingCode("GB")
|
|
535
|
+
*/
|
|
536
|
+
export function getCountryCallingCode(country, metadataJson) {
|
|
537
|
+
const metadata = new Metadata(metadataJson)
|
|
538
|
+
if (metadata.hasCountry(country)) {
|
|
539
|
+
return metadata.selectNumberingPlan(country).countryCallingCode()
|
|
540
|
+
}
|
|
541
|
+
throw new Error(`Unknown country: ${country}`)
|
|
542
|
+
}
|
|
543
|
+
|
|
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)
|
|
555
|
+
// return metadata.hasCountry(country)
|
|
556
|
+
return metadataJson.countries.hasOwnProperty(country)
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Sets `v1`/`v2`/`v3`/`v4` properties on `this` object.
|
|
561
|
+
* @param {object} metadata — Metadata JSON
|
|
562
|
+
*/
|
|
563
|
+
function setVersion(metadata) {
|
|
564
|
+
const { version } = metadata
|
|
565
|
+
if (typeof version === 'number') {
|
|
566
|
+
this.v1 = version === 1
|
|
567
|
+
this.v2 = version === 2
|
|
568
|
+
this.v3 = version === 3
|
|
569
|
+
this.v4 = version === 4
|
|
570
|
+
} else {
|
|
571
|
+
if (!version) {
|
|
572
|
+
this.v1 = true
|
|
573
|
+
} else if (compare(version, V3) === -1) {
|
|
574
|
+
this.v2 = true
|
|
575
|
+
} else if (compare(version, V4) === -1) {
|
|
576
|
+
this.v3 = true
|
|
577
|
+
} else {
|
|
578
|
+
this.v4 = true
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
581
|
}
|