libphonenumber-js 1.9.53 → 1.10.2
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/.babelrc +20 -0
- package/.gitlab-ci.yml +1 -1
- package/CHANGELOG.md +5 -0
- package/build/AsYouType.js +19 -15
- package/build/AsYouType.js.map +1 -1
- package/build/AsYouType.test.js +26 -12
- package/build/AsYouType.test.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternMatcher.js +13 -33
- package/build/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternMatcher.test.js +30 -30
- package/build/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
- package/build/AsYouTypeFormatter.complete.js +4 -4
- package/build/AsYouTypeFormatter.complete.js.map +1 -1
- package/build/AsYouTypeFormatter.js +125 -129
- package/build/AsYouTypeFormatter.js.map +1 -1
- package/build/AsYouTypeFormatter.util.js +17 -32
- package/build/AsYouTypeFormatter.util.js.map +1 -1
- package/build/AsYouTypeFormatter.util.test.js +7 -7
- package/build/AsYouTypeFormatter.util.test.js.map +1 -1
- package/build/AsYouTypeParser.js +25 -17
- package/build/AsYouTypeParser.js.map +1 -1
- package/build/AsYouTypeState.js +10 -15
- package/build/AsYouTypeState.js.map +1 -1
- package/build/ParseError.js +49 -8
- package/build/ParseError.js.map +1 -1
- package/build/PhoneNumber.js +12 -12
- package/build/PhoneNumber.js.map +1 -1
- package/build/PhoneNumber.test.js +1 -1
- package/build/PhoneNumber.test.js.map +1 -1
- package/build/PhoneNumberMatcher.js +44 -37
- package/build/PhoneNumberMatcher.js.map +1 -1
- package/build/PhoneNumberMatcher.test.js +1 -1
- package/build/PhoneNumberMatcher.test.js.map +1 -1
- package/build/constants.js +1 -1
- package/build/constants.js.map +1 -1
- package/build/findNumbers/LRUCache.js +5 -7
- package/build/findNumbers/LRUCache.js.map +1 -1
- package/build/findNumbers/Leniency.js +11 -16
- package/build/findNumbers/Leniency.js.map +1 -1
- package/build/findNumbers/Leniency.test.js +3 -9
- package/build/findNumbers/Leniency.test.js.map +1 -1
- package/build/findNumbers/RegExpCache.js +3 -5
- package/build/findNumbers/RegExpCache.js.map +1 -1
- package/build/findNumbers/isValidCandidate.js +4 -4
- package/build/findNumbers/isValidCandidate.js.map +1 -1
- package/build/findNumbers/isValidPreCandidate.js.map +1 -1
- package/build/findNumbers/parsePreCandidate.js +1 -1
- package/build/findNumbers/parsePreCandidate.js.map +1 -1
- package/build/findNumbers/utf-8.js +3 -2
- package/build/findNumbers/utf-8.js.map +1 -1
- package/build/findNumbers/util.js +2 -2
- package/build/findNumbers/util.js.map +1 -1
- package/build/findNumbers/util.test.js +1 -1
- package/build/findNumbers/util.test.js.map +1 -1
- package/build/findNumbers.js +2 -2
- package/build/findNumbers.js.map +1 -1
- package/build/findNumbers.test.js +1 -1
- package/build/findNumbers.test.js.map +1 -1
- package/build/findNumbers_.js +1 -1
- package/build/findNumbers_.js.map +1 -1
- package/build/findPhoneNumbers.js +7 -3
- package/build/findPhoneNumbers.js.map +1 -1
- package/build/findPhoneNumbers.test.js +15 -18
- package/build/findPhoneNumbers.test.js.map +1 -1
- package/build/findPhoneNumbersInText.js +7 -5
- package/build/findPhoneNumbersInText.js.map +1 -1
- package/build/findPhoneNumbersInText.test.js +1 -1
- package/build/findPhoneNumbersInText.test.js.map +1 -1
- package/build/findPhoneNumbers_.js +13 -16
- package/build/findPhoneNumbers_.js.map +1 -1
- package/build/format.js +31 -27
- package/build/format.js.map +1 -1
- package/build/format.test.js +11 -1
- package/build/format.test.js.map +1 -1
- package/build/formatIncompletePhoneNumber.js +1 -1
- package/build/formatIncompletePhoneNumber.js.map +1 -1
- package/build/formatIncompletePhoneNumber.test.js +1 -1
- package/build/formatIncompletePhoneNumber.test.js.map +1 -1
- package/build/formatNumberForMobileDialing.js +5 -5
- package/build/formatNumberForMobileDialing.js.map +1 -1
- package/build/formatNumberForMobileDialing.test.js.map +1 -1
- package/build/format_.js +39 -37
- package/build/format_.js.map +1 -1
- package/build/getCountries.js +1 -1
- package/build/getCountries.js.map +1 -1
- package/build/getCountries.test.js +1 -1
- package/build/getCountries.test.js.map +1 -1
- package/build/getCountryCallingCode.js +1 -1
- package/build/getCountryCallingCode.js.map +1 -1
- package/build/getCountryCallingCode.test.js +1 -1
- package/build/getCountryCallingCode.test.js.map +1 -1
- package/build/getExampleNumber.js +1 -1
- package/build/getExampleNumber.js.map +1 -1
- package/build/getExampleNumber.test.js +1 -1
- package/build/getExampleNumber.test.js.map +1 -1
- package/build/getNumberType.js +35 -31
- package/build/getNumberType.js.map +1 -1
- package/build/getNumberType.test.js +3 -3
- package/build/getNumberType.test.js.map +1 -1
- package/build/helpers/RFC3966.js +16 -21
- package/build/helpers/RFC3966.js.map +1 -1
- package/build/helpers/RFC3966.test.js +1 -1
- package/build/helpers/RFC3966.test.js.map +1 -1
- package/build/helpers/applyInternationalSeparatorStyle.js +1 -1
- package/build/helpers/applyInternationalSeparatorStyle.js.map +1 -1
- package/build/helpers/applyInternationalSeparatorStyle.test.js +1 -1
- package/build/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
- package/build/helpers/checkNumberLength.js +4 -4
- package/build/helpers/checkNumberLength.js.map +1 -1
- package/build/helpers/checkNumberLength.test.js +11 -2
- package/build/helpers/checkNumberLength.test.js.map +1 -1
- package/build/helpers/extension/createExtensionPattern.js +1 -1
- package/build/helpers/extension/createExtensionPattern.js.map +1 -1
- package/build/helpers/extension/extractExtension.js +1 -1
- package/build/helpers/extension/extractExtension.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.js +4 -4
- package/build/helpers/extractCountryCallingCode.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.test.js +1 -1
- package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +5 -5
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/build/helpers/extractNationalNumber.js +3 -3
- package/build/helpers/extractNationalNumber.js.map +1 -1
- package/build/helpers/extractNationalNumber.test.js +23 -0
- package/build/helpers/extractNationalNumber.test.js.map +1 -0
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -12
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -2
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
- package/build/helpers/formatNationalNumberUsingFormat.js +2 -2
- package/build/helpers/formatNationalNumberUsingFormat.js.map +1 -1
- package/build/helpers/getCountryByCallingCode.js +15 -20
- package/build/helpers/getCountryByCallingCode.js.map +1 -1
- package/build/helpers/getIddPrefix.js +1 -1
- package/build/helpers/getIddPrefix.js.map +1 -1
- package/build/helpers/getNumberType.js +17 -7
- package/build/helpers/getNumberType.js.map +1 -1
- package/build/helpers/getNumberType.test.js +21 -0
- package/build/helpers/getNumberType.test.js.map +1 -0
- package/build/helpers/isViablePhoneNumber.js +3 -3
- package/build/helpers/isViablePhoneNumber.js.map +1 -1
- package/build/helpers/matchesEntirely.js.map +1 -1
- package/build/helpers/matchesEntirely.test.js +1 -1
- package/build/helpers/matchesEntirely.test.js.map +1 -1
- package/build/helpers/mergeArrays.js +8 -13
- package/build/helpers/mergeArrays.js.map +1 -1
- package/build/helpers/mergeArrays.test.js +1 -1
- package/build/helpers/mergeArrays.test.js.map +1 -1
- package/build/helpers/parseDigits.js +11 -15
- package/build/helpers/parseDigits.js.map +1 -1
- package/build/helpers/parseDigits.test.js +1 -1
- package/build/helpers/parseDigits.test.js.map +1 -1
- package/build/helpers/stripIddPrefix.js +2 -2
- package/build/helpers/stripIddPrefix.js.map +1 -1
- package/build/helpers/stripIddPrefix.test.js +1 -1
- package/build/helpers/stripIddPrefix.test.js.map +1 -1
- package/build/isPossibleNumber.js +2 -2
- package/build/isPossibleNumber.js.map +1 -1
- package/build/isPossibleNumber.test.js +1 -1
- package/build/isPossibleNumber.test.js.map +1 -1
- package/build/isPossibleNumber_.js +4 -3
- package/build/isPossibleNumber_.js.map +1 -1
- package/build/isPossiblePhoneNumber.js +6 -4
- package/build/isPossiblePhoneNumber.js.map +1 -1
- package/build/isPossiblePhoneNumber.test.js +9 -1
- package/build/isPossiblePhoneNumber.test.js.map +1 -1
- package/build/isValidNumberForRegion.js +3 -3
- package/build/isValidNumberForRegion.js.map +1 -1
- package/build/isValidNumberForRegion.test.js +2 -2
- package/build/isValidNumberForRegion.test.js.map +1 -1
- package/build/isValidNumberForRegion_.js +1 -1
- package/build/isValidNumberForRegion_.js.map +1 -1
- package/build/isValidPhoneNumber.js +6 -4
- package/build/isValidPhoneNumber.js.map +1 -1
- package/build/isValidPhoneNumber.test.js +1 -1
- package/build/isValidPhoneNumber.test.js.map +1 -1
- package/build/metadata.js +17 -20
- package/build/metadata.js.map +1 -1
- package/build/metadata.test.js +74 -3
- package/build/metadata.test.js.map +1 -1
- package/build/package.json +1 -0
- package/build/parse.js +2 -2
- package/build/parse.js.map +1 -1
- package/build/parse.test.js +2 -2
- package/build/parse.test.js.map +1 -1
- package/build/parseIncompletePhoneNumber.js +9 -14
- package/build/parseIncompletePhoneNumber.js.map +1 -1
- package/build/parseIncompletePhoneNumber.test.js +6 -2
- package/build/parseIncompletePhoneNumber.test.js.map +1 -1
- package/build/parsePhoneNumber.js +19 -13
- package/build/parsePhoneNumber.js.map +1 -1
- package/build/parsePhoneNumber.test.js +1 -1
- package/build/parsePhoneNumber.test.js.map +1 -1
- package/build/parsePhoneNumberFromString.js +2 -2
- package/build/parsePhoneNumberFromString.js.map +1 -1
- package/build/parsePhoneNumberFromString.test.js +1 -1
- package/build/parsePhoneNumberFromString.test.js.map +1 -1
- package/build/parsePhoneNumberFromString_.js +7 -5
- package/build/parsePhoneNumberFromString_.js.map +1 -1
- package/build/parsePhoneNumber_.js +5 -3
- package/build/parsePhoneNumber_.js.map +1 -1
- package/build/parse_.js +33 -29
- package/build/parse_.js.map +1 -1
- package/build/searchNumbers.js +2 -2
- package/build/searchNumbers.js.map +1 -1
- package/build/searchNumbers.test.js +9 -14
- package/build/searchNumbers.test.js.map +1 -1
- package/build/searchPhoneNumbersInText.js +2 -2
- package/build/searchPhoneNumbersInText.js.map +1 -1
- package/build/searchPhoneNumbersInText.test.js +11 -27
- package/build/searchPhoneNumbersInText.test.js.map +1 -1
- package/build/tools/semver-compare.js.map +1 -1
- package/build/tools/semver-compare.test.js +1 -1
- package/build/tools/semver-compare.test.js.map +1 -1
- package/build/validate.js +2 -2
- package/build/validate.js.map +1 -1
- package/build/validate.test.js +1 -1
- package/build/validate.test.js.map +1 -1
- package/build/validatePhoneNumberLength.js +11 -10
- package/build/validatePhoneNumberLength.js.map +1 -1
- package/build/validatePhoneNumberLength.test.js +1 -1
- package/build/validatePhoneNumberLength.test.js.map +1 -1
- package/build/validate_.js +3 -3
- 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 → index.cjs} +25 -25
- package/core/index.js +20 -20
- package/core/package.json +9 -1
- package/custom.js +34 -34
- package/es6/AsYouType.js +16 -14
- package/es6/AsYouType.js.map +1 -1
- package/es6/AsYouType.test.js +26 -12
- package/es6/AsYouType.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternMatcher.js +13 -33
- package/es6/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js +1 -1
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.complete.js +3 -3
- package/es6/AsYouTypeFormatter.complete.js.map +1 -1
- package/es6/AsYouTypeFormatter.js +105 -113
- package/es6/AsYouTypeFormatter.js.map +1 -1
- package/es6/AsYouTypeFormatter.util.js +12 -28
- package/es6/AsYouTypeFormatter.util.js.map +1 -1
- package/es6/AsYouTypeFormatter.util.test.js +1 -1
- package/es6/AsYouTypeFormatter.util.test.js.map +1 -1
- package/es6/AsYouTypeParser.js +24 -16
- package/es6/AsYouTypeParser.js.map +1 -1
- package/es6/AsYouTypeState.js +10 -15
- package/es6/AsYouTypeState.js.map +1 -1
- package/es6/ParseError.js +49 -8
- package/es6/ParseError.js.map +1 -1
- package/es6/PhoneNumber.js +12 -12
- package/es6/PhoneNumber.js.map +1 -1
- package/es6/PhoneNumber.test.js +1 -1
- package/es6/PhoneNumber.test.js.map +1 -1
- package/es6/PhoneNumberMatcher.js +39 -36
- package/es6/PhoneNumberMatcher.js.map +1 -1
- package/es6/PhoneNumberMatcher.test.js +1 -1
- package/es6/PhoneNumberMatcher.test.js.map +1 -1
- package/es6/constants.js.map +1 -1
- package/es6/findNumbers/LRUCache.js +4 -6
- package/es6/findNumbers/LRUCache.js.map +1 -1
- package/es6/findNumbers/Leniency.js +11 -16
- package/es6/findNumbers/Leniency.js.map +1 -1
- package/es6/findNumbers/Leniency.test.js +3 -9
- package/es6/findNumbers/Leniency.test.js.map +1 -1
- package/es6/findNumbers/RegExpCache.js +3 -5
- package/es6/findNumbers/RegExpCache.js.map +1 -1
- package/es6/findNumbers/isValidCandidate.js +3 -3
- package/es6/findNumbers/isValidCandidate.js.map +1 -1
- package/es6/findNumbers/isValidPreCandidate.js.map +1 -1
- package/es6/findNumbers/parsePreCandidate.js +1 -1
- package/es6/findNumbers/parsePreCandidate.js.map +1 -1
- package/es6/findNumbers/utf-8.js.map +1 -1
- package/es6/findNumbers/util.js.map +1 -1
- package/es6/findNumbers/util.test.js +1 -1
- package/es6/findNumbers/util.test.js.map +1 -1
- package/es6/findNumbers.js +2 -2
- package/es6/findNumbers.js.map +1 -1
- package/es6/findNumbers.test.js +1 -1
- package/es6/findNumbers.test.js.map +1 -1
- package/es6/findNumbers_.js +1 -1
- package/es6/findNumbers_.js.map +1 -1
- package/es6/findPhoneNumbers.js +2 -2
- package/es6/findPhoneNumbers.js.map +1 -1
- package/es6/findPhoneNumbers.test.js +10 -15
- package/es6/findPhoneNumbers.test.js.map +1 -1
- package/es6/findPhoneNumbersInText.js +7 -5
- package/es6/findPhoneNumbersInText.js.map +1 -1
- package/es6/findPhoneNumbersInText.test.js +1 -1
- package/es6/findPhoneNumbersInText.test.js.map +1 -1
- package/es6/findPhoneNumbers_.js +12 -15
- package/es6/findPhoneNumbers_.js.map +1 -1
- package/es6/format.js +31 -27
- package/es6/format.js.map +1 -1
- package/es6/format.test.js +11 -1
- package/es6/format.test.js.map +1 -1
- package/es6/formatIncompletePhoneNumber.js +1 -1
- package/es6/formatIncompletePhoneNumber.js.map +1 -1
- package/es6/formatIncompletePhoneNumber.test.js +1 -1
- package/es6/formatIncompletePhoneNumber.test.js.map +1 -1
- package/es6/formatNumberForMobileDialing.js +5 -5
- package/es6/formatNumberForMobileDialing.js.map +1 -1
- package/es6/formatNumberForMobileDialing.test.js.map +1 -1
- package/es6/format_.js +35 -36
- package/es6/format_.js.map +1 -1
- package/es6/getCountries.js +1 -1
- package/es6/getCountries.js.map +1 -1
- package/es6/getCountries.test.js +1 -1
- package/es6/getCountries.test.js.map +1 -1
- package/es6/getCountryCallingCode.js +1 -1
- package/es6/getCountryCallingCode.js.map +1 -1
- package/es6/getCountryCallingCode.test.js +1 -1
- package/es6/getCountryCallingCode.test.js.map +1 -1
- package/es6/getExampleNumber.js +1 -1
- package/es6/getExampleNumber.js.map +1 -1
- package/es6/getExampleNumber.test.js +1 -1
- package/es6/getExampleNumber.test.js.map +1 -1
- package/es6/getNumberType.js +35 -31
- package/es6/getNumberType.js.map +1 -1
- package/es6/getNumberType.test.js +3 -3
- package/es6/getNumberType.test.js.map +1 -1
- package/es6/helpers/RFC3966.js +15 -20
- package/es6/helpers/RFC3966.js.map +1 -1
- package/es6/helpers/RFC3966.test.js +1 -1
- package/es6/helpers/RFC3966.test.js.map +1 -1
- package/es6/helpers/applyInternationalSeparatorStyle.js +1 -1
- package/es6/helpers/applyInternationalSeparatorStyle.js.map +1 -1
- package/es6/helpers/applyInternationalSeparatorStyle.test.js +1 -1
- package/es6/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
- package/es6/helpers/checkNumberLength.js +3 -3
- package/es6/helpers/checkNumberLength.js.map +1 -1
- package/es6/helpers/checkNumberLength.test.js +10 -2
- package/es6/helpers/checkNumberLength.test.js.map +1 -1
- package/es6/helpers/extension/createExtensionPattern.js +1 -1
- package/es6/helpers/extension/createExtensionPattern.js.map +1 -1
- package/es6/helpers/extension/extractExtension.js +1 -1
- package/es6/helpers/extension/extractExtension.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.js +4 -4
- package/es6/helpers/extractCountryCallingCode.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.test.js +1 -1
- package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +5 -5
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/es6/helpers/extractNationalNumber.js +3 -3
- package/es6/helpers/extractNationalNumber.js.map +1 -1
- package/es6/helpers/extractNationalNumber.test.js +16 -0
- package/es6/helpers/extractNationalNumber.test.js.map +1 -0
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -12
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -2
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
- package/es6/helpers/formatNationalNumberUsingFormat.js +1 -1
- package/es6/helpers/formatNationalNumberUsingFormat.js.map +1 -1
- package/es6/helpers/getCountryByCallingCode.js +15 -20
- package/es6/helpers/getCountryByCallingCode.js.map +1 -1
- package/es6/helpers/getIddPrefix.js +1 -1
- package/es6/helpers/getIddPrefix.js.map +1 -1
- package/es6/helpers/getNumberType.js +17 -7
- package/es6/helpers/getNumberType.js.map +1 -1
- package/es6/helpers/getNumberType.test.js +14 -0
- package/es6/helpers/getNumberType.test.js.map +1 -0
- package/es6/helpers/isViablePhoneNumber.js +2 -2
- package/es6/helpers/isViablePhoneNumber.js.map +1 -1
- package/es6/helpers/matchesEntirely.js.map +1 -1
- package/es6/helpers/matchesEntirely.test.js +1 -1
- package/es6/helpers/matchesEntirely.test.js.map +1 -1
- package/es6/helpers/mergeArrays.js +8 -13
- package/es6/helpers/mergeArrays.js.map +1 -1
- package/es6/helpers/mergeArrays.test.js +1 -1
- package/es6/helpers/mergeArrays.test.js.map +1 -1
- package/es6/helpers/parseDigits.js +8 -13
- package/es6/helpers/parseDigits.js.map +1 -1
- package/es6/helpers/parseDigits.test.js +1 -1
- package/es6/helpers/parseDigits.test.js.map +1 -1
- package/es6/helpers/stripIddPrefix.js +2 -2
- package/es6/helpers/stripIddPrefix.js.map +1 -1
- package/es6/helpers/stripIddPrefix.test.js +1 -1
- package/es6/helpers/stripIddPrefix.test.js.map +1 -1
- package/es6/isPossibleNumber.js +2 -2
- package/es6/isPossibleNumber.js.map +1 -1
- package/es6/isPossibleNumber.test.js +1 -1
- package/es6/isPossibleNumber.test.js.map +1 -1
- package/es6/isPossibleNumber_.js +4 -3
- package/es6/isPossibleNumber_.js.map +1 -1
- package/es6/isPossiblePhoneNumber.js +6 -4
- package/es6/isPossiblePhoneNumber.js.map +1 -1
- package/es6/isPossiblePhoneNumber.test.js +9 -1
- package/es6/isPossiblePhoneNumber.test.js.map +1 -1
- package/es6/isValidNumberForRegion.js +3 -3
- package/es6/isValidNumberForRegion.js.map +1 -1
- package/es6/isValidNumberForRegion.test.js +2 -2
- package/es6/isValidNumberForRegion.test.js.map +1 -1
- package/es6/isValidNumberForRegion_.js +1 -1
- package/es6/isValidNumberForRegion_.js.map +1 -1
- package/es6/isValidPhoneNumber.js +6 -4
- package/es6/isValidPhoneNumber.js.map +1 -1
- package/es6/isValidPhoneNumber.test.js +1 -1
- package/es6/isValidPhoneNumber.test.js.map +1 -1
- package/es6/metadata.js +13 -16
- package/es6/metadata.js.map +1 -1
- package/es6/metadata.test.js +67 -2
- package/es6/metadata.test.js.map +1 -1
- package/es6/parse.js +2 -2
- package/es6/parse.js.map +1 -1
- package/es6/parse.test.js +2 -2
- package/es6/parse.test.js.map +1 -1
- package/es6/parseIncompletePhoneNumber.js +9 -14
- package/es6/parseIncompletePhoneNumber.js.map +1 -1
- package/es6/parseIncompletePhoneNumber.test.js +1 -1
- package/es6/parseIncompletePhoneNumber.test.js.map +1 -1
- package/es6/parsePhoneNumber.js +19 -13
- package/es6/parsePhoneNumber.js.map +1 -1
- package/es6/parsePhoneNumber.test.js +1 -1
- package/es6/parsePhoneNumber.test.js.map +1 -1
- package/es6/parsePhoneNumberFromString.js +2 -2
- package/es6/parsePhoneNumberFromString.js.map +1 -1
- package/es6/parsePhoneNumberFromString.test.js +1 -1
- package/es6/parsePhoneNumberFromString.test.js.map +1 -1
- package/es6/parsePhoneNumberFromString_.js +7 -5
- package/es6/parsePhoneNumberFromString_.js.map +1 -1
- package/es6/parsePhoneNumber_.js +5 -3
- package/es6/parsePhoneNumber_.js.map +1 -1
- package/es6/parse_.js +28 -28
- package/es6/parse_.js.map +1 -1
- package/es6/searchNumbers.js +2 -2
- package/es6/searchNumbers.js.map +1 -1
- package/es6/searchNumbers.test.js +9 -14
- package/es6/searchNumbers.test.js.map +1 -1
- package/es6/searchPhoneNumbersInText.js +2 -2
- package/es6/searchPhoneNumbersInText.js.map +1 -1
- package/es6/searchPhoneNumbersInText.test.js +11 -27
- package/es6/searchPhoneNumbersInText.test.js.map +1 -1
- package/es6/tools/semver-compare.js.map +1 -1
- package/es6/tools/semver-compare.test.js +1 -1
- package/es6/tools/semver-compare.test.js.map +1 -1
- package/es6/validate.js +2 -2
- package/es6/validate.js.map +1 -1
- package/es6/validate.test.js +1 -1
- package/es6/validate.test.js.map +1 -1
- package/es6/validatePhoneNumberLength.js +11 -10
- package/es6/validatePhoneNumberLength.js.map +1 -1
- package/es6/validatePhoneNumberLength.test.js +1 -1
- package/es6/validatePhoneNumberLength.test.js.map +1 -1
- package/es6/validate_.js +3 -3
- package/es6/validate_.js.map +1 -1
- package/index.cjs +124 -0
- package/index.common.js +14 -11
- package/index.es6.exports/PhoneNumberSearch.js +2 -2
- package/index.es6.exports/findPhoneNumbers.js +2 -2
- package/index.es6.exports/format.js +2 -2
- package/index.es6.exports/getNumberType.js +2 -2
- package/index.es6.exports/isPossibleNumber.js +2 -2
- package/index.es6.exports/isValidNumber.js +2 -2
- package/index.es6.exports/isValidNumberForRegion.js +2 -2
- package/index.es6.exports/parse.js +2 -2
- package/index.es6.exports/searchPhoneNumbers.js +2 -2
- package/index.es6.js +5 -66
- package/index.js +67 -0
- package/max/exports/AsYouType.js +2 -2
- package/max/exports/Metadata.js +2 -2
- package/max/exports/PhoneNumberMatcher.js +2 -2
- package/max/exports/findNumbers.js +2 -2
- package/max/exports/findPhoneNumbersInText.js +2 -2
- package/max/exports/formatIncompletePhoneNumber.js +2 -2
- package/max/exports/getCountries.js +2 -2
- package/max/exports/getCountryCallingCode.js +2 -2
- package/max/exports/getExampleNumber.js +2 -2
- package/max/exports/getExtPrefix.js +2 -2
- package/max/exports/isPossiblePhoneNumber.js +2 -2
- package/max/exports/isSupportedCountry.js +2 -2
- package/max/exports/isValidPhoneNumber.js +2 -2
- package/max/exports/parsePhoneNumberFromString.js +2 -2
- package/max/exports/parsePhoneNumberWithError.js +2 -2
- package/max/exports/searchNumbers.js +2 -2
- package/max/exports/searchPhoneNumbersInText.js +2 -2
- package/max/exports/validatePhoneNumberLength.js +2 -2
- package/max/{index.commonjs.js → index.cjs} +1 -1
- package/max/index.js +19 -19
- package/max/package.json +9 -1
- package/min/exports/AsYouType.js +2 -2
- package/min/exports/Metadata.js +2 -2
- package/min/exports/PhoneNumberMatcher.js +2 -2
- package/min/exports/findNumbers.js +2 -2
- package/min/exports/findPhoneNumbersInText.js +2 -2
- package/min/exports/formatIncompletePhoneNumber.js +2 -2
- package/min/exports/getCountries.js +2 -2
- package/min/exports/getCountryCallingCode.js +2 -2
- package/min/exports/getExampleNumber.js +2 -2
- package/min/exports/getExtPrefix.js +2 -2
- package/min/exports/isPossiblePhoneNumber.js +2 -2
- package/min/exports/isSupportedCountry.js +2 -2
- package/min/exports/isValidPhoneNumber.js +2 -2
- package/min/exports/parsePhoneNumberFromString.js +2 -2
- package/min/exports/parsePhoneNumberWithError.js +2 -2
- package/min/exports/searchNumbers.js +2 -2
- package/min/exports/searchPhoneNumbersInText.js +2 -2
- package/min/exports/validatePhoneNumberLength.js +2 -2
- package/min/{index.commonjs.js → index.cjs} +1 -1
- package/min/index.js +19 -19
- package/min/package.json +9 -1
- package/mobile/exports/AsYouType.js +2 -2
- package/mobile/exports/Metadata.js +2 -2
- package/mobile/exports/PhoneNumberMatcher.js +2 -2
- package/mobile/exports/findNumbers.js +2 -2
- package/mobile/exports/findPhoneNumbersInText.js +2 -2
- package/mobile/exports/formatIncompletePhoneNumber.js +2 -2
- package/mobile/exports/getCountries.js +2 -2
- package/mobile/exports/getCountryCallingCode.js +2 -2
- package/mobile/exports/getExampleNumber.js +2 -2
- package/mobile/exports/getExtPrefix.js +2 -2
- package/mobile/exports/isPossiblePhoneNumber.js +2 -2
- package/mobile/exports/isSupportedCountry.js +2 -2
- package/mobile/exports/isValidPhoneNumber.js +2 -2
- package/mobile/exports/parsePhoneNumberFromString.js +2 -2
- package/mobile/exports/parsePhoneNumberWithError.js +2 -2
- package/mobile/exports/searchNumbers.js +2 -2
- package/mobile/exports/searchPhoneNumbersInText.js +2 -2
- package/mobile/exports/validatePhoneNumberLength.js +2 -2
- package/mobile/{index.commonjs.js → index.cjs} +1 -1
- package/mobile/index.js +19 -19
- package/mobile/package.json +9 -1
- package/package.json +124 -42
- package/{rollup.config.js → rollup.config.mjs} +0 -0
- package/runnable/create-commonjs-package-json.js +11 -0
- package/runnable/generate.js +6 -0
- package/runnable/metadata-branch.js +1 -1
- package/runnable/metadata-update-and-push-and-pull-request.js +3 -3
- package/runnable/metadata-update-and-push.js +3 -3
- package/runnable/metadata-update-and-release.js +3 -3
- package/runnable/modules/commit.js +2 -2
- package/runnable/modules/exec.js +2 -2
- package/runnable/modules/update-metadata.js +2 -2
- package/source/AsYouType.js +6 -6
- package/source/AsYouType.test.js +8 -1
- package/source/AsYouTypeFormatter.PatternMatcher.test.js +1 -1
- package/source/AsYouTypeFormatter.complete.js +3 -3
- package/source/AsYouTypeFormatter.js +26 -12
- package/source/AsYouTypeFormatter.util.test.js +1 -1
- package/source/AsYouTypeParser.js +15 -9
- package/source/AsYouTypeState.js +1 -1
- package/source/ParseError.js +10 -7
- package/source/PhoneNumber.js +6 -6
- package/source/PhoneNumber.test.js +1 -1
- package/source/PhoneNumberMatcher.js +25 -24
- package/source/PhoneNumberMatcher.test.js +1 -1
- package/source/findNumbers/Leniency.js +3 -3
- package/source/findNumbers/Leniency.test.js +3 -9
- package/source/findNumbers/RegExpCache.js +1 -1
- package/source/findNumbers/isValidCandidate.js +3 -3
- package/source/findNumbers/parsePreCandidate.js +1 -1
- package/source/findNumbers/util.test.js +2 -4
- package/source/findNumbers.js +2 -2
- package/source/findNumbers.test.js +1 -1
- package/source/findNumbers_.js +1 -1
- package/source/findPhoneNumbers.js +2 -2
- package/source/findPhoneNumbers.test.js +2 -2
- package/source/findPhoneNumbersInText.js +1 -1
- package/source/findPhoneNumbersInText.test.js +1 -1
- package/source/findPhoneNumbers_.js +10 -10
- package/source/format.js +2 -2
- package/source/format.test.js +10 -1
- package/source/formatIncompletePhoneNumber.js +1 -1
- package/source/formatIncompletePhoneNumber.test.js +1 -1
- package/source/formatNumberForMobileDialing.js +5 -5
- package/source/format_.js +8 -6
- package/source/getCountries.js +1 -1
- package/source/getCountries.test.js +1 -1
- package/source/getCountryCallingCode.js +1 -1
- package/source/getCountryCallingCode.test.js +1 -1
- package/source/getExampleNumber.js +1 -1
- package/source/getExampleNumber.test.js +1 -1
- package/source/getNumberType.js +3 -3
- package/source/getNumberType.test.js +2 -2
- package/source/helpers/RFC3966.js +1 -1
- package/source/helpers/RFC3966.test.js +1 -1
- package/source/helpers/applyInternationalSeparatorStyle.js +1 -1
- package/source/helpers/applyInternationalSeparatorStyle.test.js +1 -1
- package/source/helpers/checkNumberLength.js +1 -1
- package/source/helpers/checkNumberLength.test.js +10 -2
- package/source/helpers/extension/createExtensionPattern.js +1 -1
- package/source/helpers/extension/extractExtension.js +1 -1
- package/source/helpers/extractCountryCallingCode.js +4 -4
- package/source/helpers/extractCountryCallingCode.test.js +1 -1
- package/source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +5 -5
- package/source/helpers/extractNationalNumber.js +3 -3
- package/source/helpers/extractNationalNumber.test.js +15 -0
- package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -2
- package/source/helpers/formatNationalNumberUsingFormat.js +1 -1
- package/source/helpers/getCountryByCallingCode.js +2 -2
- package/source/helpers/getIddPrefix.js +1 -1
- package/source/helpers/getNumberType.js +9 -5
- package/source/helpers/getNumberType.test.js +19 -0
- package/source/helpers/isViablePhoneNumber.js +2 -2
- package/source/helpers/matchesEntirely.test.js +1 -1
- package/source/helpers/mergeArrays.test.js +1 -1
- package/source/helpers/parseDigits.test.js +1 -1
- package/source/helpers/stripIddPrefix.js +2 -2
- package/source/helpers/stripIddPrefix.test.js +1 -1
- package/source/isPossibleNumber.js +2 -2
- package/source/isPossibleNumber.test.js +1 -1
- package/source/isPossibleNumber_.js +3 -2
- package/source/isPossiblePhoneNumber.js +2 -2
- package/source/isPossiblePhoneNumber.test.js +8 -1
- package/source/isValidNumberForRegion.js +3 -3
- package/source/isValidNumberForRegion.test.js +2 -2
- package/source/isValidNumberForRegion_.js +1 -1
- package/source/isValidPhoneNumber.js +2 -2
- package/source/isValidPhoneNumber.test.js +1 -1
- package/source/metadata.js +7 -2
- package/source/metadata.test.js +82 -1
- package/source/parse.js +2 -2
- package/source/parse.test.js +2 -2
- package/source/parseIncompletePhoneNumber.js +1 -1
- package/source/parseIncompletePhoneNumber.test.js +1 -1
- package/source/parsePhoneNumber.js +1 -1
- package/source/parsePhoneNumber.test.js +1 -1
- package/source/parsePhoneNumberFromString.js +2 -2
- package/source/parsePhoneNumberFromString.test.js +1 -1
- package/source/parsePhoneNumberFromString_.js +3 -3
- package/source/parsePhoneNumber_.js +1 -1
- package/source/parse_.js +16 -16
- package/source/searchNumbers.js +2 -2
- package/source/searchNumbers.test.js +1 -1
- package/source/searchPhoneNumbersInText.js +2 -2
- package/source/searchPhoneNumbersInText.test.js +1 -1
- package/source/tools/semver-compare.test.js +1 -1
- package/source/validate.js +2 -2
- package/source/validate.test.js +1 -1
- package/source/validatePhoneNumberLength.js +5 -5
- package/source/validatePhoneNumberLength.test.js +1 -1
- package/source/validate_.js +3 -3
- package/exports/README.md +0 -98
- package/exports/examples.mobile.json/index.js +0 -1
- package/exports/metadata.max.json/index.js +0 -1
- package/exports/metadata.min.json/index.js +0 -1
- package/exports/metadata.mobile.json/index.js +0 -1
- package/exports/package.exports.json +0 -55
|
@@ -1,19 +1,23 @@
|
|
|
1
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
2
|
+
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
|
|
5
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
6
|
+
|
|
1
7
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
8
|
|
|
3
9
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
4
10
|
|
|
5
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
import { VALID_PUNCTUATION } from './constants';
|
|
16
|
-
import applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle'; // Used in phone number format template creation.
|
|
13
|
+
import { DIGIT_PLACEHOLDER, countOccurences, repeat, cutAndStripNonPairedParens, closeNonPairedParens, stripNonPairedParens, populateTemplateWithDigits } from './AsYouTypeFormatter.util.js';
|
|
14
|
+
import formatCompleteNumber, { canFormatCompleteNumber } from './AsYouTypeFormatter.complete.js';
|
|
15
|
+
import PatternMatcher from './AsYouTypeFormatter.PatternMatcher.js';
|
|
16
|
+
import parseDigits from './helpers/parseDigits.js';
|
|
17
|
+
export { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util.js';
|
|
18
|
+
import { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat.js';
|
|
19
|
+
import { VALID_PUNCTUATION } from './constants.js';
|
|
20
|
+
import applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle.js'; // Used in phone number format template creation.
|
|
17
21
|
// Could be any digit, I guess.
|
|
18
22
|
|
|
19
23
|
var DUMMY_DIGIT = '9'; // I don't know why is it exactly `15`
|
|
@@ -90,57 +94,13 @@ var NON_ALTERING_FORMAT_REG_EXP = new RegExp('[' + VALID_PUNCTUATION + ']*' + //
|
|
|
90
94
|
|
|
91
95
|
var MIN_LEADING_DIGITS_LENGTH = 3;
|
|
92
96
|
|
|
93
|
-
var AsYouTypeFormatter =
|
|
94
|
-
/*#__PURE__*/
|
|
95
|
-
function () {
|
|
97
|
+
var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
96
98
|
function AsYouTypeFormatter(_ref) {
|
|
97
|
-
var _this = this;
|
|
98
|
-
|
|
99
99
|
var state = _ref.state,
|
|
100
100
|
metadata = _ref.metadata;
|
|
101
101
|
|
|
102
102
|
_classCallCheck(this, AsYouTypeFormatter);
|
|
103
103
|
|
|
104
|
-
_defineProperty(this, "getSeparatorAfterNationalPrefix", function (format) {
|
|
105
|
-
// `US` metadata doesn't have a `national_prefix_formatting_rule`,
|
|
106
|
-
// so the `if` condition below doesn't apply to `US`,
|
|
107
|
-
// but in reality there shoudl be a separator
|
|
108
|
-
// between a national prefix and a national (significant) number.
|
|
109
|
-
// So `US` national prefix separator is a "special" "hardcoded" case.
|
|
110
|
-
if (_this.isNANP) {
|
|
111
|
-
return ' ';
|
|
112
|
-
} // If a `format` has a `national_prefix_formatting_rule`
|
|
113
|
-
// and that rule has a separator after a national prefix,
|
|
114
|
-
// then it means that there should be a separator
|
|
115
|
-
// between a national prefix and a national (significant) number.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (format && format.nationalPrefixFormattingRule() && NATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {
|
|
119
|
-
return ' ';
|
|
120
|
-
} // At this point, there seems to be no clear evidence that
|
|
121
|
-
// there should be a separator between a national prefix
|
|
122
|
-
// and a national (significant) number. So don't insert one.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return '';
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
_defineProperty(this, "shouldTryNationalPrefixFormattingRule", function (format, _ref2) {
|
|
129
|
-
var international = _ref2.international,
|
|
130
|
-
nationalPrefix = _ref2.nationalPrefix;
|
|
131
|
-
|
|
132
|
-
if (format.nationalPrefixFormattingRule()) {
|
|
133
|
-
// In some countries, `national_prefix_formatting_rule` is `($1)`,
|
|
134
|
-
// so it applies even if the user hasn't input a national prefix.
|
|
135
|
-
// `format.usesNationalPrefix()` detects such cases.
|
|
136
|
-
var usesNationalPrefix = format.usesNationalPrefix();
|
|
137
|
-
|
|
138
|
-
if (usesNationalPrefix && nationalPrefix || !usesNationalPrefix && !international) {
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
|
|
144
104
|
this.metadata = metadata;
|
|
145
105
|
this.resetFormat();
|
|
146
106
|
}
|
|
@@ -181,7 +141,7 @@ function () {
|
|
|
181
141
|
}, {
|
|
182
142
|
key: "format",
|
|
183
143
|
value: function format(nextDigits, state) {
|
|
184
|
-
var
|
|
144
|
+
var _this = this;
|
|
185
145
|
|
|
186
146
|
// See if the phone number digits can be formatted as a complete phone number.
|
|
187
147
|
// If not, use the results from `formatNationalNumberWithNextDigits()`,
|
|
@@ -198,28 +158,19 @@ function () {
|
|
|
198
158
|
// whose leadingDigitsPattern also matches the input."
|
|
199
159
|
//
|
|
200
160
|
if (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {
|
|
201
|
-
for (var _iterator = this.matchingFormats,
|
|
202
|
-
var
|
|
203
|
-
|
|
204
|
-
if (_isArray) {
|
|
205
|
-
if (_i >= _iterator.length) break;
|
|
206
|
-
_ref3 = _iterator[_i++];
|
|
207
|
-
} else {
|
|
208
|
-
_i = _iterator.next();
|
|
209
|
-
if (_i.done) break;
|
|
210
|
-
_ref3 = _i.value;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
var format = _ref3;
|
|
161
|
+
for (var _iterator = _createForOfIteratorHelperLoose(this.matchingFormats), _step; !(_step = _iterator()).done;) {
|
|
162
|
+
var format = _step.value;
|
|
214
163
|
var formattedCompleteNumber = formatCompleteNumber(state, format, {
|
|
215
164
|
metadata: this.metadata,
|
|
216
165
|
shouldTryNationalPrefixFormattingRule: function shouldTryNationalPrefixFormattingRule(format) {
|
|
217
|
-
return
|
|
166
|
+
return _this.shouldTryNationalPrefixFormattingRule(format, {
|
|
218
167
|
international: state.international,
|
|
219
168
|
nationalPrefix: state.nationalPrefix
|
|
220
169
|
});
|
|
221
170
|
},
|
|
222
|
-
getSeparatorAfterNationalPrefix:
|
|
171
|
+
getSeparatorAfterNationalPrefix: function getSeparatorAfterNationalPrefix(format) {
|
|
172
|
+
return _this.getSeparatorAfterNationalPrefix(format);
|
|
173
|
+
}
|
|
223
174
|
});
|
|
224
175
|
|
|
225
176
|
if (formattedCompleteNumber) {
|
|
@@ -264,12 +215,12 @@ function () {
|
|
|
264
215
|
}
|
|
265
216
|
}, {
|
|
266
217
|
key: "narrowDownMatchingFormats",
|
|
267
|
-
value: function narrowDownMatchingFormats(
|
|
268
|
-
var
|
|
218
|
+
value: function narrowDownMatchingFormats(_ref2) {
|
|
219
|
+
var _this2 = this;
|
|
269
220
|
|
|
270
|
-
var nationalSignificantNumber =
|
|
271
|
-
nationalPrefix =
|
|
272
|
-
international =
|
|
221
|
+
var nationalSignificantNumber = _ref2.nationalSignificantNumber,
|
|
222
|
+
nationalPrefix = _ref2.nationalPrefix,
|
|
223
|
+
international = _ref2.international;
|
|
273
224
|
var leadingDigits = nationalSignificantNumber; // "leading digits" pattern list starts with a
|
|
274
225
|
// "leading digits" pattern fitting a maximum of 3 leading digits.
|
|
275
226
|
// So, after a user inputs 3 digits of a national (significant) phone number
|
|
@@ -289,7 +240,7 @@ function () {
|
|
|
289
240
|
}
|
|
290
241
|
|
|
291
242
|
this.matchingFormats = this.matchingFormats.filter(function (format) {
|
|
292
|
-
return
|
|
243
|
+
return _this2.formatSuits(format, international, nationalPrefix) && _this2.formatMatches(format, leadingDigits, leadingDigitsPatternIndex);
|
|
293
244
|
}); // If there was a phone number format chosen
|
|
294
245
|
// and it no longer holds given the new leading digits then reset it.
|
|
295
246
|
// The test for this `if` condition is marked as:
|
|
@@ -336,6 +287,7 @@ function () {
|
|
|
336
287
|
value: function formatMatches(format, leadingDigits, leadingDigitsPatternIndex) {
|
|
337
288
|
var leadingDigitsPatternsCount = format.leadingDigitsPatterns().length; // If this format is not restricted to a certain
|
|
338
289
|
// leading digits pattern then it fits.
|
|
290
|
+
// The test case could be found by searching for "leadingDigitsPatternsCount === 0".
|
|
339
291
|
|
|
340
292
|
if (leadingDigitsPatternsCount === 0) {
|
|
341
293
|
return true;
|
|
@@ -409,23 +361,14 @@ function () {
|
|
|
409
361
|
}, {
|
|
410
362
|
key: "chooseFormat",
|
|
411
363
|
value: function chooseFormat(state) {
|
|
412
|
-
var
|
|
413
|
-
|
|
414
|
-
var _loop2 = function _loop2() {
|
|
415
|
-
if (_isArray2) {
|
|
416
|
-
if (_i2 >= _iterator2.length) return "break";
|
|
417
|
-
_ref5 = _iterator2[_i2++];
|
|
418
|
-
} else {
|
|
419
|
-
_i2 = _iterator2.next();
|
|
420
|
-
if (_i2.done) return "break";
|
|
421
|
-
_ref5 = _i2.value;
|
|
422
|
-
}
|
|
364
|
+
var _this3 = this;
|
|
423
365
|
|
|
424
|
-
|
|
366
|
+
var _loop = function _loop() {
|
|
367
|
+
var format = _step2.value;
|
|
425
368
|
|
|
426
369
|
// If this format is currently being used
|
|
427
370
|
// and is still suitable, then stick to it.
|
|
428
|
-
if (
|
|
371
|
+
if (_this3.chosenFormat === format) {
|
|
429
372
|
return "break";
|
|
430
373
|
} // Sometimes, a formatting rule inserts additional digits in a phone number,
|
|
431
374
|
// and "as you type" formatter can't do that: it should only use the digits
|
|
@@ -469,36 +412,43 @@ function () {
|
|
|
469
412
|
/* istanbul ignore if */
|
|
470
413
|
|
|
471
414
|
|
|
472
|
-
if (!NON_ALTERING_FORMAT_REG_EXP.test(
|
|
415
|
+
if (!NON_ALTERING_FORMAT_REG_EXP.test(_this3.getFormatFormat(format, state.international))) {
|
|
473
416
|
return "continue";
|
|
474
417
|
}
|
|
475
418
|
|
|
476
|
-
if (!
|
|
419
|
+
if (!_this3.createTemplateForFormat(format, state)) {
|
|
477
420
|
// Remove the format if it can't generate a template.
|
|
478
|
-
|
|
421
|
+
_this3.matchingFormats = _this3.matchingFormats.filter(function (_) {
|
|
479
422
|
return _ !== format;
|
|
480
423
|
});
|
|
481
424
|
return "continue";
|
|
482
425
|
}
|
|
483
426
|
|
|
484
|
-
|
|
427
|
+
_this3.chosenFormat = format;
|
|
485
428
|
return "break";
|
|
486
429
|
};
|
|
487
430
|
|
|
488
431
|
// When there are multiple available formats, the formatter uses the first
|
|
489
432
|
// format where a formatting template could be created.
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
433
|
+
//
|
|
434
|
+
// For some weird reason, `istanbul` says "else path not taken"
|
|
435
|
+
// for the `for of` line below. Supposedly that means that
|
|
436
|
+
// the loop doesn't ever go over the last element in the list.
|
|
437
|
+
// That's true because there always is `this.chosenFormat`
|
|
438
|
+
// when `this.matchingFormats` is non-empty.
|
|
439
|
+
// And, for some weird reason, it doesn't think that the case
|
|
440
|
+
// with empty `this.matchingFormats` qualifies for a valid "else" path.
|
|
441
|
+
// So simply muting this `istanbul` warning.
|
|
442
|
+
// It doesn't skip the contents of the `for of` loop,
|
|
443
|
+
// it just skips the `for of` line.
|
|
444
|
+
//
|
|
494
445
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
446
|
+
/* istanbul ignore next */
|
|
447
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(this.matchingFormats.slice()), _step2; !(_step2 = _iterator2()).done;) {
|
|
448
|
+
var _ret = _loop();
|
|
498
449
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}
|
|
450
|
+
if (_ret === "break") break;
|
|
451
|
+
if (_ret === "continue") continue;
|
|
502
452
|
}
|
|
503
453
|
|
|
504
454
|
if (!this.chosenFormat) {
|
|
@@ -529,11 +479,36 @@ function () {
|
|
|
529
479
|
return true;
|
|
530
480
|
}
|
|
531
481
|
}
|
|
482
|
+
}, {
|
|
483
|
+
key: "getSeparatorAfterNationalPrefix",
|
|
484
|
+
value: function getSeparatorAfterNationalPrefix(format) {
|
|
485
|
+
// `US` metadata doesn't have a `national_prefix_formatting_rule`,
|
|
486
|
+
// so the `if` condition below doesn't apply to `US`,
|
|
487
|
+
// but in reality there shoudl be a separator
|
|
488
|
+
// between a national prefix and a national (significant) number.
|
|
489
|
+
// So `US` national prefix separator is a "special" "hardcoded" case.
|
|
490
|
+
if (this.isNANP) {
|
|
491
|
+
return ' ';
|
|
492
|
+
} // If a `format` has a `national_prefix_formatting_rule`
|
|
493
|
+
// and that rule has a separator after a national prefix,
|
|
494
|
+
// then it means that there should be a separator
|
|
495
|
+
// between a national prefix and a national (significant) number.
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
if (format && format.nationalPrefixFormattingRule() && NATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {
|
|
499
|
+
return ' ';
|
|
500
|
+
} // At this point, there seems to be no clear evidence that
|
|
501
|
+
// there should be a separator between a national prefix
|
|
502
|
+
// and a national (significant) number. So don't insert one.
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
return '';
|
|
506
|
+
}
|
|
532
507
|
}, {
|
|
533
508
|
key: "getInternationalPrefixBeforeCountryCallingCode",
|
|
534
|
-
value: function getInternationalPrefixBeforeCountryCallingCode(
|
|
535
|
-
var IDDPrefix =
|
|
536
|
-
missingPlus =
|
|
509
|
+
value: function getInternationalPrefixBeforeCountryCallingCode(_ref3, options) {
|
|
510
|
+
var IDDPrefix = _ref3.IDDPrefix,
|
|
511
|
+
missingPlus = _ref3.missingPlus;
|
|
537
512
|
|
|
538
513
|
if (IDDPrefix) {
|
|
539
514
|
return options && options.spacing === false ? IDDPrefix : IDDPrefix + ' ';
|
|
@@ -597,11 +572,11 @@ function () {
|
|
|
597
572
|
|
|
598
573
|
}, {
|
|
599
574
|
key: "getTemplateForFormat",
|
|
600
|
-
value: function getTemplateForFormat(format,
|
|
601
|
-
var nationalSignificantNumber =
|
|
602
|
-
international =
|
|
603
|
-
nationalPrefix =
|
|
604
|
-
complexPrefixBeforeNationalSignificantNumber =
|
|
575
|
+
value: function getTemplateForFormat(format, _ref4) {
|
|
576
|
+
var nationalSignificantNumber = _ref4.nationalSignificantNumber,
|
|
577
|
+
international = _ref4.international,
|
|
578
|
+
nationalPrefix = _ref4.nationalPrefix,
|
|
579
|
+
complexPrefixBeforeNationalSignificantNumber = _ref4.complexPrefixBeforeNationalSignificantNumber;
|
|
605
580
|
var pattern = format.pattern();
|
|
606
581
|
/* istanbul ignore else */
|
|
607
582
|
|
|
@@ -746,6 +721,23 @@ function () {
|
|
|
746
721
|
// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)
|
|
747
722
|
// .replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')
|
|
748
723
|
}
|
|
724
|
+
}, {
|
|
725
|
+
key: "shouldTryNationalPrefixFormattingRule",
|
|
726
|
+
value: function shouldTryNationalPrefixFormattingRule(format, _ref5) {
|
|
727
|
+
var international = _ref5.international,
|
|
728
|
+
nationalPrefix = _ref5.nationalPrefix;
|
|
729
|
+
|
|
730
|
+
if (format.nationalPrefixFormattingRule()) {
|
|
731
|
+
// In some countries, `national_prefix_formatting_rule` is `($1)`,
|
|
732
|
+
// so it applies even if the user hasn't input a national prefix.
|
|
733
|
+
// `format.usesNationalPrefix()` detects such cases.
|
|
734
|
+
var usesNationalPrefix = format.usesNationalPrefix();
|
|
735
|
+
|
|
736
|
+
if (usesNationalPrefix && nationalPrefix || !usesNationalPrefix && !international) {
|
|
737
|
+
return true;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
749
741
|
}]);
|
|
750
742
|
|
|
751
743
|
return AsYouTypeFormatter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/AsYouTypeFormatter.js"],"names":["DIGIT_PLACEHOLDER","countOccurences","repeat","cutAndStripNonPairedParens","closeNonPairedParens","stripNonPairedParens","populateTemplateWithDigits","formatCompleteNumber","canFormatCompleteNumber","PatternMatcher","parseDigits","FIRST_GROUP_PATTERN","VALID_PUNCTUATION","applyInternationalSeparatorStyle","DUMMY_DIGIT","LONGEST_NATIONAL_PHONE_NUMBER_LENGTH","LONGEST_DUMMY_PHONE_NUMBER","NATIONAL_PREFIX_SEPARATORS_PATTERN","SUPPORT_LEGACY_FORMATTING_PATTERNS","CREATE_CHARACTER_CLASS_PATTERN","CREATE_STANDALONE_DIGIT_PATTERN","NON_ALTERING_FORMAT_REG_EXP","RegExp","MIN_LEADING_DIGITS_LENGTH","AsYouTypeFormatter","state","metadata","format","isNANP","nationalPrefixFormattingRule","test","international","nationalPrefix","usesNationalPrefix","resetFormat","chosenFormat","undefined","template","nationalNumberTemplate","populatedNationalNumberTemplate","populatedNationalNumberTemplatePosition","numberingPlan","callingCode","matchingFormats","formats","nationalSignificantNumber","narrowDownMatchingFormats","nextDigits","formattedCompleteNumber","shouldTryNationalPrefixFormattingRule","getSeparatorAfterNationalPrefix","setNationalNumberTemplate","replace","lastIndexOf","formatNationalNumberWithNextDigits","previouslyChosenFormat","newlyChosenFormat","chooseFormat","formatNextNationalNumberDigits","getNationalDigits","leadingDigits","leadingDigitsPatternIndex","length","filter","formatSuits","formatMatches","indexOf","nationalPrefixIsOptionalWhenFormattingInNationalFormat","nationalPrefixIsMandatoryWhenFormattingInNationalFormat","leadingDigitsPatternsCount","leadingDigitsPatterns","Math","min","leadingDigitsPattern","match","allowOverflow","error","console","internationalFormat","getFormatFormat","createTemplateForFormat","_","slice","pattern","getTemplateForFormat","options","IDDPrefix","missingPlus","spacing","index","i","internationalPrefix","getInternationalPrefixBeforeCountryCallingCode","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","digits","strictPattern","nationalNumberDummyDigits","numberFormat","nationalPrefixIncludedInTemplate","numberFormatWithNationalPrefix","result"],"mappings":";;;;;;;;AAAA,SACCA,iBADD,EAECC,eAFD,EAGCC,MAHD,EAICC,0BAJD,EAKCC,oBALD,EAMCC,oBAND,EAOCC,0BAPD,QAQO,2BARP;AAUA,OAAOC,oBAAP,IACCC,uBADD,QAEO,+BAFP;AAIA,OAAOC,cAAP,MAA2B,qCAA3B;AAEA,OAAOC,WAAP,MAAwB,uBAAxB;AACA,SAASV,iBAAT,QAAkC,2BAAlC;AACA,SAASW,mBAAT,QAAoC,2CAApC;AACA,SAASC,iBAAT,QAAkC,aAAlC;AACA,OAAOC,gCAAP,MAA6C,4CAA7C,C,CAEA;AACA;;AACA,IAAMC,WAAW,GAAG,GAApB,C,CACA;;AACA,IAAMC,oCAAoC,GAAG,EAA7C,C,CACA;AACA;;AACA,IAAMC,0BAA0B,GAAGd,MAAM,CAACY,WAAD,EAAcC,oCAAd,CAAzC,C,CAEA;AACA;;AACA,IAAME,kCAAkC,GAAG,MAA3C,C,CAEA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,kCAAkC,GAAG,IAA3C,C,CAEA;AACA;;AACA,IAAMC,8BAA8B,GAAGD,kCAAkC,IAAK;AAAA,SAAM,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AkHF;AACA;AACA;AACA;;AACA,UAAI,CAACmG,gCAAL,EAAuC;AACtC,YAAIL,4CAAJ,EAAkD;AACjD;AACAzD,UAAAA,QAAQ,GAAGnC,MAAM,CAACF,iBAAD,EAAoB8F,4CAA4C,CAAChC,MAAjE,CAAN,GACV,GADU,GAEVzB,QAFD;AAGA,SALD,MAKO,IAAIL,cAAJ,EAAoB;AAC1B;AACAK,UAAAA,QAAQ,GAAGnC,MAAM,CAACF,iBAAD,EAAoBgC,cAAc,CAAC8B,MAAnC,CAAN,GACV,KAAKZ,+BAAL,CAAqCvB,MAArC,CADU,GAEVU,QAFD;AAGA;AACD;;AAED,UAAIN,aAAJ,EAAmB;AAClBM,QAAAA,QAAQ,GAAGxB,gCAAgC,CAACwB,QAAD,CAA3C;AACA;;AAED,aAAOA,QAAP;AACA;;;mDAE8B0D,M,EAAQ;AACtC,UAAMM,MAAM,GAAG/F,0BAA0B,CACxC,KAAKiC,+BADmC,EAExC,KAAKC,uCAFmC,EAGxCuD,MAHwC,CAAzC;;AAMA,UAAI,CAACM,MAAL,EAAa;AACZ;AACA,aAAKnE,WAAL;AACA;AACA;;AAED,WAAKK,+BAAL,GAAuC8D,MAAM,CAAC,CAAD,CAA7C;AACA,WAAK7D,uCAAL,GAA+C6D,MAAM,CAAC,CAAD,CAArD,CAdsC,CAgBtC;;AACA,aAAOlG,0BAA0B,CAAC,KAAKoC,+BAAN,EAAuC,KAAKC,uCAAL,GAA+C,CAAtF,CAAjC,CAjBsC,CAmBtC;AACA;AACA;AACA;AACA;;;;;;SAnkBmBhB,kB","sourcesContent":["import {\r\n\tDIGIT_PLACEHOLDER,\r\n\tcountOccurences,\r\n\trepeat,\r\n\tcutAndStripNonPairedParens,\r\n\tcloseNonPairedParens,\r\n\tstripNonPairedParens,\r\n\tpopulateTemplateWithDigits\r\n} from './AsYouTypeFormatter.util'\r\n\r\nimport formatCompleteNumber, {\r\n\tcanFormatCompleteNumber\r\n} from './AsYouTypeFormatter.complete'\r\n\r\nimport PatternMatcher from './AsYouTypeFormatter.PatternMatcher'\r\n\r\nimport parseDigits from './helpers/parseDigits'\r\nexport { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util'\r\nimport { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat'\r\nimport { VALID_PUNCTUATION } from './constants'\r\nimport applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle'\r\n\r\n// Used in phone number format template creation.\r\n// Could be any digit, I guess.\r\nconst DUMMY_DIGIT = '9'\r\n// I don't know why is it exactly `15`\r\nconst LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15\r\n// Create a phone number consisting only of the digit 9 that matches the\r\n// `number_pattern` by applying the pattern to the \"longest phone number\" string.\r\nconst LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH)\r\n\r\n// A set of characters that, if found in a national prefix formatting rules, are an indicator to\r\n// us that we should separate the national prefix from the number when formatting.\r\nconst NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/\r\n\r\n// Deprecated: Google has removed some formatting pattern related code from their repo.\r\n// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c\r\n// \"We no longer have numbers in formatting matching patterns, only \\d.\"\r\n// Because this library supports generating custom metadata\r\n// some users may still be using old metadata so the relevant\r\n// code seems to stay until some next major version update.\r\nconst SUPPORT_LEGACY_FORMATTING_PATTERNS = true\r\n\r\n// A pattern that is used to match character classes in regular expressions.\r\n// An example of a character class is \"[1-4]\".\r\nconst CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\[([^\\[\\]])*\\]/g)\r\n\r\n// Any digit in a regular expression that actually denotes a digit. For\r\n// example, in the regular expression \"80[0-2]\\d{6,10}\", the first 2 digits\r\n// (8 and 0) are standalone digits, but the rest are not.\r\n// Two look-aheads are needed because the number following \\\\d could be a\r\n// two-digit number, since the phone number can be as long as 15 digits.\r\nconst CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\d(?=[^,}][^,}])/g)\r\n\r\n// A regular expression that is used to determine if a `format` is\r\n// suitable to be used in the \"as you type formatter\".\r\n// A `format` is suitable when the resulting formatted number has\r\n// the same digits as the user has entered.\r\n//\r\n// In the simplest case, that would mean that the format\r\n// doesn't add any additional digits when formatting a number.\r\n// Google says that it also shouldn't add \"star\" (`*`) characters,\r\n// like it does in some Israeli formats.\r\n// Such basic format would only contain \"valid punctuation\"\r\n// and \"captured group\" identifiers ($1, $2, etc).\r\n//\r\n// An example of a format that adds additional digits:\r\n//\r\n// Country: `AR` (Argentina).\r\n// Format:\r\n// {\r\n// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n// \"leading_digits_patterns\": [\"91\"],\r\n// \"national_prefix_formatting_rule\": \"0$1\",\r\n// \"format\": \"$2 15-$3-$4\",\r\n// \"international_format\": \"$1 $2 $3-$4\"\r\n// }\r\n//\r\n// In the format above, the `format` adds `15` to the digits when formatting a number.\r\n// A sidenote: this format actually is suitable because `national_prefix_for_parsing`\r\n// has previously removed `15` from a national number, so re-adding `15` in `format`\r\n// doesn't actually result in any extra digits added to user's input.\r\n// But verifying that would be a complex procedure, so the code chooses a simpler path:\r\n// it simply filters out all `format`s that contain anything but \"captured group\" ids.\r\n//\r\n// This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's\r\n// `libphonenumber` code.\r\n//\r\nconst NON_ALTERING_FORMAT_REG_EXP = new RegExp(\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t// Google developers say:\r\n\t// \"We require that the first matching group is present in the\r\n\t// output pattern to ensure no data is lost while formatting.\"\r\n\t'\\\\$1' +\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t'(\\\\$\\\\d[' + VALID_PUNCTUATION + ']*)*' +\r\n\t'$'\r\n)\r\n\r\n// This is the minimum length of the leading digits of a phone number\r\n// to guarantee the first \"leading digits pattern\" for a phone number format\r\n// to be preemptive.\r\nconst MIN_LEADING_DIGITS_LENGTH = 3\r\n\r\nexport default class AsYouTypeFormatter {\r\n\tconstructor({\r\n\t\tstate,\r\n\t\tmetadata\r\n\t}) {\r\n\t\tthis.metadata = metadata\r\n\t\tthis.resetFormat()\r\n\t}\r\n\r\n\tresetFormat() {\r\n\t\tthis.chosenFormat = undefined\r\n\t\tthis.template = undefined\r\n\t\tthis.nationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t}\r\n\r\n\treset(numberingPlan, state) {\r\n\t\tthis.resetFormat()\r\n\t\tif (numberingPlan) {\r\n\t\t\tthis.isNANP = numberingPlan.callingCode() === '1'\r\n\t\t\tthis.matchingFormats = numberingPlan.formats()\r\n\t\t\tif (state.nationalSignificantNumber) {\r\n\t\t\t\tthis.narrowDownMatchingFormats(state)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tthis.isNANP = undefined\r\n\t\t\tthis.matchingFormats = []\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Formats an updated phone number.\r\n\t * @param {string} nextDigits — Additional phone number digits.\r\n\t * @param {object} state — `AsYouType` state.\r\n\t * @return {[string]} Returns undefined if the updated phone number can't be formatted using any of the available formats.\r\n\t */\r\n\tformat(nextDigits, state) {\r\n\t\t// See if the phone number digits can be formatted as a complete phone number.\r\n\t\t// If not, use the results from `formatNationalNumberWithNextDigits()`,\r\n\t\t// which formats based on the chosen formatting pattern.\r\n\t\t//\r\n\t\t// Attempting to format complete phone number first is how it's done\r\n\t\t// in Google's `libphonenumber`, so this library just follows it.\r\n\t\t// Google's `libphonenumber` code doesn't explain in detail why does it\r\n\t\t// attempt to format digits as a complete phone number\r\n\t\t// instead of just going with a previoulsy (or newly) chosen `format`:\r\n\t\t//\r\n\t\t// \"Checks to see if there is an exact pattern match for these digits.\r\n\t\t// If so, we should use this instead of any other formatting template\r\n\t\t// whose leadingDigitsPattern also matches the input.\"\r\n\t\t//\r\n\t\tif (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {\r\n\t\t\tfor (const format of this.matchingFormats) {\r\n\t\t\t\tconst formattedCompleteNumber = formatCompleteNumber(\r\n\t\t\t\t\tstate,\r\n\t\t\t\t\tformat,\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmetadata: this.metadata,\r\n\t\t\t\t\t\tshouldTryNationalPrefixFormattingRule: format => this.shouldTryNationalPrefixFormattingRule(format, {\r\n\t\t\t\t\t\t\tinternational: state.international,\r\n\t\t\t\t\t\t\tnationalPrefix: state.nationalPrefix\r\n\t\t\t\t\t\t}),\r\n\t\t\t\t\t\tgetSeparatorAfterNationalPrefix: this.getSeparatorAfterNationalPrefix\r\n\t\t\t\t\t}\r\n\t\t\t\t)\r\n\t\t\t\tif (formattedCompleteNumber) {\r\n\t\t\t\t\tthis.resetFormat()\r\n\t\t\t\t\tthis.chosenFormat = format\r\n\t\t\t\t\tthis.setNationalNumberTemplate(formattedCompleteNumber.replace(/\\d/g, DIGIT_PLACEHOLDER), state)\r\n\t\t\t\t\tthis.populatedNationalNumberTemplate = formattedCompleteNumber\r\n\t\t\t\t\t// With a new formatting template, the matched position\r\n\t\t\t\t\t// using the old template needs to be reset.\r\n\t\t\t\t\tthis.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(DIGIT_PLACEHOLDER)\r\n\t\t\t\t\treturn formattedCompleteNumber\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Format the digits as a partial (incomplete) phone number\r\n\t\t// using the previously chosen formatting pattern (or a newly chosen one).\r\n\t\treturn this.formatNationalNumberWithNextDigits(nextDigits, state)\r\n\t}\r\n\r\n\t// Formats the next phone number digits.\r\n\tformatNationalNumberWithNextDigits(nextDigits, state) {\r\n\t\tconst previouslyChosenFormat = this.chosenFormat\r\n\t\t// Choose a format from the list of matching ones.\r\n\t\tconst newlyChosenFormat = this.chooseFormat(state)\r\n\t\tif (newlyChosenFormat) {\r\n\t\t\tif (newlyChosenFormat === previouslyChosenFormat) {\r\n\t\t\t\t// If it can format the next (current) digits\r\n\t\t\t\t// using the previously chosen phone number format\r\n\t\t\t\t// then return the updated formatted number.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(nextDigits)\r\n\t\t\t} else {\r\n\t\t\t\t// If a more appropriate phone number format\r\n\t\t\t\t// has been chosen for these \"leading digits\",\r\n\t\t\t\t// then re-format the national phone number part\r\n\t\t\t\t// using the newly selected format.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(state.getNationalDigits())\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tnarrowDownMatchingFormats({\r\n\t\tnationalSignificantNumber,\r\n\t\tnationalPrefix,\r\n\t\tinternational\r\n\t}) {\r\n\t\tconst leadingDigits = nationalSignificantNumber\r\n\r\n\t\t// \"leading digits\" pattern list starts with a\r\n\t\t// \"leading digits\" pattern fitting a maximum of 3 leading digits.\r\n\t\t// So, after a user inputs 3 digits of a national (significant) phone number\r\n\t\t// this national (significant) number can already be formatted.\r\n\t\t// The next \"leading digits\" pattern is for 4 leading digits max,\r\n\t\t// and the \"leading digits\" pattern after it is for 5 leading digits max, etc.\r\n\r\n\t\t// This implementation is different from Google's\r\n\t\t// in that it searches for a fitting format\r\n\t\t// even if the user has entered less than\r\n\t\t// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.\r\n\t\t// Because some leading digit patterns already match for a single first digit.\r\n\t\tlet leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH\r\n\t\tif (leadingDigitsPatternIndex < 0) {\r\n\t\t\tleadingDigitsPatternIndex = 0\r\n\t\t}\r\n\r\n\t\tthis.matchingFormats = this.matchingFormats.filter(\r\n\t\t\tformat => this.formatSuits(format, international, nationalPrefix)\r\n\t\t\t\t&& this.formatMatches(format, leadingDigits, leadingDigitsPatternIndex)\r\n\t\t)\r\n\r\n\t\t// If there was a phone number format chosen\r\n\t\t// and it no longer holds given the new leading digits then reset it.\r\n\t\t// The test for this `if` condition is marked as:\r\n\t\t// \"Reset a chosen format when it no longer holds given the new leading digits\".\r\n\t\t// To construct a valid test case for this one can find a country\r\n\t\t// in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`\r\n\t\t// and yielding another format for 4 `<leadingDigits>` (Australia in this case).\r\n\t\tif (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t}\r\n\r\n\tformatSuits(format, international, nationalPrefix) {\r\n\t\t// When a prefix before a national (significant) number is\r\n\t\t// simply a national prefix, then it's parsed as `this.nationalPrefix`.\r\n\t\t// In more complex cases, a prefix before national (significant) number\r\n\t\t// could include a national prefix as well as some \"capturing groups\",\r\n\t\t// and in that case there's no info whether a national prefix has been parsed.\r\n\t\t// If national prefix is not used when formatting a phone number\r\n\t\t// using this format, but a national prefix has been entered by the user,\r\n\t\t// and was extracted, then discard such phone number format.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184\r\n\t\tif (nationalPrefix &&\r\n\t\t\t!format.usesNationalPrefix() &&\r\n\t\t\t// !format.domesticCarrierCodeFormattingRule() &&\r\n\t\t\t!format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\t// If national prefix is mandatory for this phone number format\r\n\t\t// and there're no guarantees that a national prefix is present in user input\r\n\t\t// then discard this phone number format as not suitable.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193\r\n\t\tif (!international &&\r\n\t\t\t!nationalPrefix &&\r\n\t\t\tformat.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n\r\n\tformatMatches(format, leadingDigits, leadingDigitsPatternIndex) {\r\n\t\tconst leadingDigitsPatternsCount = format.leadingDigitsPatterns().length\r\n\r\n\t\t// If this format is not restricted to a certain\r\n\t\t// leading digits pattern then it fits.\r\n\t\tif (leadingDigitsPatternsCount === 0) {\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\t// Start narrowing down the list of possible formats based on the leading digits.\r\n\t\t// (only previously matched formats take part in the narrowing down process)\r\n\r\n\t\t// `leading_digits_patterns` start with 3 digits min\r\n\t\t// and then go up from there one digit at a time.\r\n\t\tleadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1)\r\n\t\tconst leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]\r\n\r\n\t\t// Google imposes a requirement on the leading digits\r\n\t\t// to be minimum 3 digits long in order to be eligible\r\n\t\t// for checking those with a leading digits pattern.\r\n\t\t//\r\n\t\t// Since `leading_digits_patterns` start with 3 digits min,\r\n\t\t// Google's original `libphonenumber` library only starts\r\n\t\t// excluding any non-matching formats only when the\r\n\t\t// national number entered so far is at least 3 digits long,\r\n\t\t// otherwise format matching would give false negatives.\r\n\t\t//\r\n\t\t// For example, when the digits entered so far are `2`\r\n\t\t// and the leading digits pattern is `21` –\r\n\t\t// it's quite obvious in this case that the format could be the one\r\n\t\t// but due to the absence of further digits it would give false negative.\r\n\t\t//\r\n\t\t// Also, `leading_digits_patterns` doesn't always correspond to a single\r\n\t\t// digits count. For example, `60|8` pattern would already match `8`\r\n\t\t// but the `60` part would require having at least two leading digits,\r\n\t\t// so the whole pattern would require inputting two digits first in order to\r\n\t\t// decide on whether it matches the input, even when the input is \"80\".\r\n\t\t//\r\n\t\t// This library — `libphonenumber-js` — allows filtering by `leading_digits_patterns`\r\n\t\t// even when there's only 1 or 2 digits of the national (significant) number.\r\n\t\t// To do that, it uses a non-strict pattern matcher written specifically for that.\r\n\t\t//\r\n\t\tif (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {\r\n\t\t\t// Before leading digits < 3 matching was implemented:\r\n\t\t\t// return true\r\n\t\t\t//\r\n\t\t\t// After leading digits < 3 matching was implemented:\r\n\t\t\ttry {\r\n\t\t\t\treturn new PatternMatcher(leadingDigitsPattern).match(leadingDigits, { allowOverflow: true }) !== undefined\r\n\t\t\t} catch (error) /* istanbul ignore next */ {\r\n\t\t\t\t// There's a slight possibility that there could be some undiscovered bug\r\n\t\t\t\t// in the pattern matcher code. Since the \"leading digits < 3 matching\"\r\n\t\t\t\t// feature is not \"essential\" for operation, it can fall back to the old way\r\n\t\t\t\t// in case of any issues rather than halting the application's execution.\r\n\t\t\t\tconsole.error(error)\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are\r\n\t\t// available then use the usual regular expression matching.\r\n\t\t//\r\n\t\t// The whole pattern is wrapped in round brackets (`()`) because\r\n\t\t// the pattern can use \"or\" operator (`|`) at the top level of the pattern.\r\n\t\t//\r\n\t\treturn new RegExp(`^(${leadingDigitsPattern})`).test(leadingDigits)\r\n\t}\r\n\r\n\tgetFormatFormat(format, international) {\r\n\t\treturn international ? format.internationalFormat() : format.format()\r\n\t}\r\n\r\n\tchooseFormat(state) {\r\n\t\t// When there are multiple available formats, the formatter uses the first\r\n\t\t// format where a formatting template could be created.\r\n\t\tfor (const format of this.matchingFormats.slice()) {\r\n\t\t\t// If this format is currently being used\r\n\t\t\t// and is still suitable, then stick to it.\r\n\t\t\tif (this.chosenFormat === format) {\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\t// Sometimes, a formatting rule inserts additional digits in a phone number,\r\n\t\t\t// and \"as you type\" formatter can't do that: it should only use the digits\r\n\t\t\t// that the user has input.\r\n\t\t\t//\r\n\t\t\t// For example, in Argentina, there's a format for mobile phone numbers:\r\n\t\t\t//\r\n\t\t\t// {\r\n\t\t\t// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n\t\t\t// \"leading_digits_patterns\": [\"91\"],\r\n\t\t\t// \"national_prefix_formatting_rule\": \"0$1\",\r\n\t\t\t// \"format\": \"$2 15-$3-$4\",\r\n\t\t\t// \"international_format\": \"$1 $2 $3-$4\"\r\n\t\t\t// }\r\n\t\t\t//\r\n\t\t\t// In that format, `international_format` is used instead of `format`\r\n\t\t\t// because `format` inserts `15` in the formatted number,\r\n\t\t\t// and `AsYouType` formatter should only use the digits\r\n\t\t\t// the user has actually input, without adding any extra digits.\r\n\t\t\t// In this case, it wouldn't make a difference, because the `15`\r\n\t\t\t// is first stripped when applying `national_prefix_for_parsing`\r\n\t\t\t// and then re-added when using `format`, so in reality it doesn't\r\n\t\t\t// add any new digits to the number, but to detect that, the code\r\n\t\t\t// would have to be more complex: it would have to try formatting\r\n\t\t\t// the digits using the format and then see if any digits have\r\n\t\t\t// actually been added or removed, and then, every time a new digit\r\n\t\t\t// is input, it should re-check whether the chosen format doesn't\r\n\t\t\t// alter the digits.\r\n\t\t\t//\r\n\t\t\t// Google's code doesn't go that far, and so does this library:\r\n\t\t\t// it simply requires that a `format` doesn't add any additonal\r\n\t\t\t// digits to user's input.\r\n\t\t\t//\r\n\t\t\t// Also, people in general should move from inputting phone numbers\r\n\t\t\t// in national format (possibly with national prefixes)\r\n\t\t\t// and use international phone number format instead:\r\n\t\t\t// it's a logical thing in the modern age of mobile phones,\r\n\t\t\t// globalization and the internet.\r\n\t\t\t//\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (!NON_ALTERING_FORMAT_REG_EXP.test(this.getFormatFormat(format, state.international))) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tif (!this.createTemplateForFormat(format, state)) {\r\n\t\t\t\t// Remove the format if it can't generate a template.\r\n\t\t\t\tthis.matchingFormats = this.matchingFormats.filter(_ => _ !== format)\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tthis.chosenFormat = format\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tif (!this.chosenFormat) {\r\n\t\t\t// No format matches the national (significant) phone number.\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t\treturn this.chosenFormat\r\n\t}\r\n\r\n\tcreateTemplateForFormat(format, state) {\r\n\t\t// The formatter doesn't format numbers when numberPattern contains '|', e.g.\r\n\t\t// (20|3)\\d{4}. In those cases we quickly return.\r\n\t\t// (Though there's no such format in current metadata)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Get formatting template for this phone number format\r\n\t\tconst template = this.getTemplateForFormat(format, state)\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (template) {\r\n\t\t\tthis.setNationalNumberTemplate(template, state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\tgetSeparatorAfterNationalPrefix = (format) => {\r\n\t\t// `US` metadata doesn't have a `national_prefix_formatting_rule`,\r\n\t\t// so the `if` condition below doesn't apply to `US`,\r\n\t\t// but in reality there shoudl be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\t// So `US` national prefix separator is a \"special\" \"hardcoded\" case.\r\n\t\tif (this.isNANP) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// If a `format` has a `national_prefix_formatting_rule`\r\n\t\t// and that rule has a separator after a national prefix,\r\n\t\t// then it means that there should be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\tif (format &&\r\n\t\t\tformat.nationalPrefixFormattingRule() &&\r\n\t\t\tNATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// At this point, there seems to be no clear evidence that\r\n\t\t// there should be a separator between a national prefix\r\n\t\t// and a national (significant) number. So don't insert one.\r\n\t\treturn ''\r\n\t}\r\n\r\n\tgetInternationalPrefixBeforeCountryCallingCode({ IDDPrefix, missingPlus }, options) {\r\n\t\tif (IDDPrefix) {\r\n\t\t\treturn options && options.spacing === false ? IDDPrefix : IDDPrefix + ' '\r\n\t\t}\r\n\t\tif (missingPlus) {\r\n\t\t\treturn ''\r\n\t\t}\r\n\t\treturn '+'\r\n\t}\r\n\r\n\tgetTemplate(state) {\r\n\t\tif (!this.template) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// `this.template` holds the template for a \"complete\" phone number.\r\n\t\t// The currently entered phone number is most likely not \"complete\",\r\n\t\t// so trim all non-populated digits.\r\n\t\tlet index = -1\r\n\t\tlet i = 0\r\n\t\tconst internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, { spacing: false }) : ''\r\n\t\twhile (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {\r\n\t\t\tindex = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn cutAndStripNonPairedParens(this.template, index + 1)\r\n\t}\r\n\r\n\tsetNationalNumberTemplate(template, state) {\r\n\t\tthis.nationalNumberTemplate = template\r\n\t\tthis.populatedNationalNumberTemplate = template\r\n\t\t// With a new formatting template, the matched position\r\n\t\t// using the old template needs to be reset.\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t\t// For convenience, the public `.template` property\r\n\t\t// contains the whole international number\r\n\t\t// if the phone number being input is international:\r\n\t\t// 'x' for the '+' sign, 'x'es for the country phone code,\r\n\t\t// a spacebar and then the template for the formatted national number.\r\n\t\tif (state.international) {\r\n\t\t\tthis.template =\r\n\t\t\t\tthis.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER) +\r\n\t\t\t\trepeat(DIGIT_PLACEHOLDER, state.callingCode.length) +\r\n\t\t\t\t' ' +\r\n\t\t\t\ttemplate\r\n\t\t} else {\r\n\t\t\tthis.template = template\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Generates formatting template for a national phone number,\r\n\t * optionally containing a national prefix, for a format.\r\n\t * @param {Format} format\r\n\t * @param {string} nationalPrefix\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplateForFormat(format, {\r\n\t\tnationalSignificantNumber,\r\n\t\tinternational,\r\n\t\tnationalPrefix,\r\n\t\tcomplexPrefixBeforeNationalSignificantNumber\r\n\t}) {\r\n\t\tlet pattern = format.pattern()\r\n\r\n\t\t/* istanbul ignore else */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS) {\r\n\t\t\tpattern = pattern\r\n\t\t\t\t// Replace anything in the form of [..] with \\d\r\n\t\t\t\t.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\\\d')\r\n\t\t\t\t// Replace any standalone digit (not the one in `{}`) with \\d\r\n\t\t\t\t.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\\\d')\r\n\t\t}\r\n\r\n\t\t// Generate a dummy national number (consisting of `9`s)\r\n\t\t// that fits this format's `pattern`.\r\n\t\t//\r\n\t\t// This match will always succeed,\r\n\t\t// because the \"longest dummy phone number\"\r\n\t\t// has enough length to accomodate any possible\r\n\t\t// national phone number format pattern.\r\n\t\t//\r\n\t\tlet digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]\r\n\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (nationalSignificantNumber.length > digits.length) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// Get a formatting template which can be used to efficiently format\r\n\t\t// a partial number where digits are added one by one.\r\n\r\n\t\t// Below `strictPattern` is used for the\r\n\t\t// regular expression (with `^` and `$`).\r\n\t\t// This wasn't originally in Google's `libphonenumber`\r\n\t\t// and I guess they don't really need it\r\n\t\t// because they're not using \"templates\" to format phone numbers\r\n\t\t// but I added `strictPattern` after encountering\r\n\t\t// South Korean phone number formatting bug.\r\n\t\t//\r\n\t\t// Non-strict regular expression bug demonstration:\r\n\t\t//\r\n\t\t// this.nationalSignificantNumber : `111111111` (9 digits)\r\n\t\t//\r\n\t\t// pattern : (\\d{2})(\\d{3,4})(\\d{4})\r\n\t\t// format : `$1 $2 $3`\r\n\t\t// digits : `9999999999` (10 digits)\r\n\t\t//\r\n\t\t// '9999999999'.replace(new RegExp(/(\\d{2})(\\d{3,4})(\\d{4})/g), '$1 $2 $3') = \"99 9999 9999\"\r\n\t\t//\r\n\t\t// template : xx xxxx xxxx\r\n\t\t//\r\n\t\t// But the correct template in this case is `xx xxx xxxx`.\r\n\t\t// The template was generated incorrectly because of the\r\n\t\t// `{3,4}` variability in the `pattern`.\r\n\t\t//\r\n\t\t// The fix is, if `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then `this.nationalSignificantNumber`\r\n\t\t// is used instead of `digits`.\r\n\r\n\t\tconst strictPattern = new RegExp('^' + pattern + '$')\r\n\t\tconst nationalNumberDummyDigits = nationalSignificantNumber.replace(/\\d/g, DUMMY_DIGIT)\r\n\r\n\t\t// If `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then use it\r\n\t\t// instead of `digits`.\r\n\t\tif (strictPattern.test(nationalNumberDummyDigits)) {\r\n\t\t\tdigits = nationalNumberDummyDigits\r\n\t\t}\r\n\r\n\t\tlet numberFormat = this.getFormatFormat(format, international)\r\n\t\tlet nationalPrefixIncludedInTemplate\r\n\r\n\t\t// If a user did input a national prefix (and that's guaranteed),\r\n\t\t// and if a `format` does have a national prefix formatting rule,\r\n\t\t// then see if that national prefix formatting rule\r\n\t\t// prepends exactly the same national prefix the user has input.\r\n\t\t// If that's the case, then use the `format` with the national prefix formatting rule.\r\n\t\t// Otherwise, use the `format` without the national prefix formatting rule,\r\n\t\t// and prepend a national prefix manually to it.\r\n\t\tif (this.shouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix })) {\r\n\t\t\tconst numberFormatWithNationalPrefix = numberFormat.replace(\r\n\t\t\t\tFIRST_GROUP_PATTERN,\r\n\t\t\t\tformat.nationalPrefixFormattingRule()\r\n\t\t\t)\r\n\t\t\t// If `national_prefix_formatting_rule` of a `format` simply prepends\r\n\t\t\t// national prefix at the start of a national (significant) number,\r\n\t\t\t// then such formatting can be used with `AsYouType` formatter.\r\n\t\t\t// There seems to be no `else` case: everywhere in metadata,\r\n\t\t\t// national prefix formatting rule is national prefix + $1,\r\n\t\t\t// or `($1)`, in which case such format isn't even considered\r\n\t\t\t// when the user has input a national prefix.\r\n\t\t\t/* istanbul ignore else */\r\n\t\t\tif (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {\r\n\t\t\t\tnumberFormat = numberFormatWithNationalPrefix\r\n\t\t\t\tnationalPrefixIncludedInTemplate = true\r\n\t\t\t\t// Replace all digits of the national prefix in the formatting template\r\n\t\t\t\t// with `DIGIT_PLACEHOLDER`s.\r\n\t\t\t\tif (nationalPrefix) {\r\n\t\t\t\t\tlet i = nationalPrefix.length\r\n\t\t\t\t\twhile (i > 0) {\r\n\t\t\t\t\t\tnumberFormat = numberFormat.replace(/\\d/, DIGIT_PLACEHOLDER)\r\n\t\t\t\t\t\ti--\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Generate formatting template for this phone number format.\r\n\t\tlet template = digits\r\n\t\t\t// Format the dummy phone number according to the format.\r\n\t\t\t.replace(new RegExp(pattern), numberFormat)\r\n\t\t\t// Replace each dummy digit with a DIGIT_PLACEHOLDER.\r\n\t\t\t.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)\r\n\r\n\t\t// If a prefix of a national (significant) number is not as simple\r\n\t\t// as just a basic national prefix, then just prepend such prefix\r\n\t\t// before the national (significant) number, optionally spacing\r\n\t\t// the two with a whitespace.\r\n\t\tif (!nationalPrefixIncludedInTemplate) {\r\n\t\t\tif (complexPrefixBeforeNationalSignificantNumber) {\r\n\t\t\t\t// Prepend the prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, complexPrefixBeforeNationalSignificantNumber.length) +\r\n\t\t\t\t\t' ' +\r\n\t\t\t\t\ttemplate\r\n\t\t\t} else if (nationalPrefix) {\r\n\t\t\t\t// Prepend national prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +\r\n\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\r\n\t\t\t\t\ttemplate\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (international) {\r\n\t\t\ttemplate = applyInternationalSeparatorStyle(template)\r\n\t\t}\r\n\r\n\t\treturn template\r\n\t}\r\n\r\n\tformatNextNationalNumberDigits(digits) {\r\n\t\tconst result = populateTemplateWithDigits(\r\n\t\t\tthis.populatedNationalNumberTemplate,\r\n\t\t\tthis.populatedNationalNumberTemplatePosition,\r\n\t\t\tdigits\r\n\t\t)\r\n\r\n\t\tif (!result) {\r\n\t\t\t// Reset the format.\r\n\t\t\tthis.resetFormat()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.populatedNationalNumberTemplate = result[0]\r\n\t\tthis.populatedNationalNumberTemplatePosition = result[1]\r\n\r\n\t\t// Return the formatted phone number so far.\r\n\t\treturn cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\r\n\t\t// The old way which was good for `input-format` but is not so good\r\n\t\t// for `react-phone-number-input`'s default input (`InputBasic`).\r\n\t\t// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\t\t// \t.replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')\r\n\t}\r\n\r\n\tshouldTryNationalPrefixFormattingRule = (format, { international, nationalPrefix }) => {\r\n\t\tif (format.nationalPrefixFormattingRule()) {\r\n\t\t\t// In some countries, `national_prefix_formatting_rule` is `($1)`,\r\n\t\t\t// so it applies even if the user hasn't input a national prefix.\r\n\t\t\t// `format.usesNationalPrefix()` detects such cases.\r\n\t\t\tconst usesNationalPrefix = format.usesNationalPrefix()\r\n\t\t\tif ((usesNationalPrefix && nationalPrefix) ||\r\n\t\t\t\t(!usesNationalPrefix && !international)) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"],"file":"AsYouTypeFormatter.js"}
|
|
1
|
+
{"version":3,"file":"AsYouTypeFormatter.js","names":["DIGIT_PLACEHOLDER","countOccurences","repeat","cutAndStripNonPairedParens","closeNonPairedParens","stripNonPairedParens","populateTemplateWithDigits","formatCompleteNumber","canFormatCompleteNumber","PatternMatcher","parseDigits","FIRST_GROUP_PATTERN","VALID_PUNCTUATION","applyInternationalSeparatorStyle","DUMMY_DIGIT","LONGEST_NATIONAL_PHONE_NUMBER_LENGTH","LONGEST_DUMMY_PHONE_NUMBER","NATIONAL_PREFIX_SEPARATORS_PATTERN","SUPPORT_LEGACY_FORMATTING_PATTERNS","CREATE_CHARACTER_CLASS_PATTERN","CREATE_STANDALONE_DIGIT_PATTERN","NON_ALTERING_FORMAT_REG_EXP","RegExp","MIN_LEADING_DIGITS_LENGTH","AsYouTypeFormatter","state","metadata","resetFormat","chosenFormat","undefined","template","nationalNumberTemplate","populatedNationalNumberTemplate","populatedNationalNumberTemplatePosition","numberingPlan","isNANP","callingCode","matchingFormats","formats","nationalSignificantNumber","narrowDownMatchingFormats","nextDigits","format","formattedCompleteNumber","shouldTryNationalPrefixFormattingRule","international","nationalPrefix","getSeparatorAfterNationalPrefix","setNationalNumberTemplate","replace","lastIndexOf","formatNationalNumberWithNextDigits","previouslyChosenFormat","newlyChosenFormat","chooseFormat","formatNextNationalNumberDigits","getNationalDigits","leadingDigits","leadingDigitsPatternIndex","length","filter","formatSuits","formatMatches","indexOf","usesNationalPrefix","nationalPrefixIsOptionalWhenFormattingInNationalFormat","nationalPrefixIsMandatoryWhenFormattingInNationalFormat","leadingDigitsPatternsCount","leadingDigitsPatterns","Math","min","leadingDigitsPattern","match","allowOverflow","error","console","test","internationalFormat","getFormatFormat","createTemplateForFormat","_","slice","pattern","getTemplateForFormat","nationalPrefixFormattingRule","options","IDDPrefix","missingPlus","spacing","index","i","internationalPrefix","getInternationalPrefixBeforeCountryCallingCode","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","digits","strictPattern","nationalNumberDummyDigits","numberFormat","nationalPrefixIncludedInTemplate","numberFormatWithNationalPrefix","result"],"sources":["../source/AsYouTypeFormatter.js"],"sourcesContent":["import {\r\n\tDIGIT_PLACEHOLDER,\r\n\tcountOccurences,\r\n\trepeat,\r\n\tcutAndStripNonPairedParens,\r\n\tcloseNonPairedParens,\r\n\tstripNonPairedParens,\r\n\tpopulateTemplateWithDigits\r\n} from './AsYouTypeFormatter.util.js'\r\n\r\nimport formatCompleteNumber, {\r\n\tcanFormatCompleteNumber\r\n} from './AsYouTypeFormatter.complete.js'\r\n\r\nimport PatternMatcher from './AsYouTypeFormatter.PatternMatcher.js'\r\n\r\nimport parseDigits from './helpers/parseDigits.js'\r\nexport { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util.js'\r\nimport { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat.js'\r\nimport { VALID_PUNCTUATION } from './constants.js'\r\nimport applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle.js'\r\n\r\n// Used in phone number format template creation.\r\n// Could be any digit, I guess.\r\nconst DUMMY_DIGIT = '9'\r\n// I don't know why is it exactly `15`\r\nconst LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15\r\n// Create a phone number consisting only of the digit 9 that matches the\r\n// `number_pattern` by applying the pattern to the \"longest phone number\" string.\r\nconst LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH)\r\n\r\n// A set of characters that, if found in a national prefix formatting rules, are an indicator to\r\n// us that we should separate the national prefix from the number when formatting.\r\nconst NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/\r\n\r\n// Deprecated: Google has removed some formatting pattern related code from their repo.\r\n// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c\r\n// \"We no longer have numbers in formatting matching patterns, only \\d.\"\r\n// Because this library supports generating custom metadata\r\n// some users may still be using old metadata so the relevant\r\n// code seems to stay until some next major version update.\r\nconst SUPPORT_LEGACY_FORMATTING_PATTERNS = true\r\n\r\n// A pattern that is used to match character classes in regular expressions.\r\n// An example of a character class is \"[1-4]\".\r\nconst CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\[([^\\[\\]])*\\]/g)\r\n\r\n// Any digit in a regular expression that actually denotes a digit. For\r\n// example, in the regular expression \"80[0-2]\\d{6,10}\", the first 2 digits\r\n// (8 and 0) are standalone digits, but the rest are not.\r\n// Two look-aheads are needed because the number following \\\\d could be a\r\n// two-digit number, since the phone number can be as long as 15 digits.\r\nconst CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\d(?=[^,}][^,}])/g)\r\n\r\n// A regular expression that is used to determine if a `format` is\r\n// suitable to be used in the \"as you type formatter\".\r\n// A `format` is suitable when the resulting formatted number has\r\n// the same digits as the user has entered.\r\n//\r\n// In the simplest case, that would mean that the format\r\n// doesn't add any additional digits when formatting a number.\r\n// Google says that it also shouldn't add \"star\" (`*`) characters,\r\n// like it does in some Israeli formats.\r\n// Such basic format would only contain \"valid punctuation\"\r\n// and \"captured group\" identifiers ($1, $2, etc).\r\n//\r\n// An example of a format that adds additional digits:\r\n//\r\n// Country: `AR` (Argentina).\r\n// Format:\r\n// {\r\n// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n// \"leading_digits_patterns\": [\"91\"],\r\n// \"national_prefix_formatting_rule\": \"0$1\",\r\n// \"format\": \"$2 15-$3-$4\",\r\n// \"international_format\": \"$1 $2 $3-$4\"\r\n// }\r\n//\r\n// In the format above, the `format` adds `15` to the digits when formatting a number.\r\n// A sidenote: this format actually is suitable because `national_prefix_for_parsing`\r\n// has previously removed `15` from a national number, so re-adding `15` in `format`\r\n// doesn't actually result in any extra digits added to user's input.\r\n// But verifying that would be a complex procedure, so the code chooses a simpler path:\r\n// it simply filters out all `format`s that contain anything but \"captured group\" ids.\r\n//\r\n// This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's\r\n// `libphonenumber` code.\r\n//\r\nconst NON_ALTERING_FORMAT_REG_EXP = new RegExp(\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t// Google developers say:\r\n\t// \"We require that the first matching group is present in the\r\n\t// output pattern to ensure no data is lost while formatting.\"\r\n\t'\\\\$1' +\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t'(\\\\$\\\\d[' + VALID_PUNCTUATION + ']*)*' +\r\n\t'$'\r\n)\r\n\r\n// This is the minimum length of the leading digits of a phone number\r\n// to guarantee the first \"leading digits pattern\" for a phone number format\r\n// to be preemptive.\r\nconst MIN_LEADING_DIGITS_LENGTH = 3\r\n\r\nexport default class AsYouTypeFormatter {\r\n\tconstructor({\r\n\t\tstate,\r\n\t\tmetadata\r\n\t}) {\r\n\t\tthis.metadata = metadata\r\n\t\tthis.resetFormat()\r\n\t}\r\n\r\n\tresetFormat() {\r\n\t\tthis.chosenFormat = undefined\r\n\t\tthis.template = undefined\r\n\t\tthis.nationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t}\r\n\r\n\treset(numberingPlan, state) {\r\n\t\tthis.resetFormat()\r\n\t\tif (numberingPlan) {\r\n\t\t\tthis.isNANP = numberingPlan.callingCode() === '1'\r\n\t\t\tthis.matchingFormats = numberingPlan.formats()\r\n\t\t\tif (state.nationalSignificantNumber) {\r\n\t\t\t\tthis.narrowDownMatchingFormats(state)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tthis.isNANP = undefined\r\n\t\t\tthis.matchingFormats = []\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Formats an updated phone number.\r\n\t * @param {string} nextDigits — Additional phone number digits.\r\n\t * @param {object} state — `AsYouType` state.\r\n\t * @return {[string]} Returns undefined if the updated phone number can't be formatted using any of the available formats.\r\n\t */\r\n\tformat(nextDigits, state) {\r\n\t\t// See if the phone number digits can be formatted as a complete phone number.\r\n\t\t// If not, use the results from `formatNationalNumberWithNextDigits()`,\r\n\t\t// which formats based on the chosen formatting pattern.\r\n\t\t//\r\n\t\t// Attempting to format complete phone number first is how it's done\r\n\t\t// in Google's `libphonenumber`, so this library just follows it.\r\n\t\t// Google's `libphonenumber` code doesn't explain in detail why does it\r\n\t\t// attempt to format digits as a complete phone number\r\n\t\t// instead of just going with a previoulsy (or newly) chosen `format`:\r\n\t\t//\r\n\t\t// \"Checks to see if there is an exact pattern match for these digits.\r\n\t\t// If so, we should use this instead of any other formatting template\r\n\t\t// whose leadingDigitsPattern also matches the input.\"\r\n\t\t//\r\n\t\tif (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {\r\n\t\t\tfor (const format of this.matchingFormats) {\r\n\t\t\t\tconst formattedCompleteNumber = formatCompleteNumber(\r\n\t\t\t\t\tstate,\r\n\t\t\t\t\tformat,\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmetadata: this.metadata,\r\n\t\t\t\t\t\tshouldTryNationalPrefixFormattingRule: (format) => this.shouldTryNationalPrefixFormattingRule(format, {\r\n\t\t\t\t\t\t\tinternational: state.international,\r\n\t\t\t\t\t\t\tnationalPrefix: state.nationalPrefix\r\n\t\t\t\t\t\t}),\r\n\t\t\t\t\t\tgetSeparatorAfterNationalPrefix: (format) => this.getSeparatorAfterNationalPrefix(format)\r\n\t\t\t\t\t}\r\n\t\t\t\t)\r\n\t\t\t\tif (formattedCompleteNumber) {\r\n\t\t\t\t\tthis.resetFormat()\r\n\t\t\t\t\tthis.chosenFormat = format\r\n\t\t\t\t\tthis.setNationalNumberTemplate(formattedCompleteNumber.replace(/\\d/g, DIGIT_PLACEHOLDER), state)\r\n\t\t\t\t\tthis.populatedNationalNumberTemplate = formattedCompleteNumber\r\n\t\t\t\t\t// With a new formatting template, the matched position\r\n\t\t\t\t\t// using the old template needs to be reset.\r\n\t\t\t\t\tthis.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(DIGIT_PLACEHOLDER)\r\n\t\t\t\t\treturn formattedCompleteNumber\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Format the digits as a partial (incomplete) phone number\r\n\t\t// using the previously chosen formatting pattern (or a newly chosen one).\r\n\t\treturn this.formatNationalNumberWithNextDigits(nextDigits, state)\r\n\t}\r\n\r\n\t// Formats the next phone number digits.\r\n\tformatNationalNumberWithNextDigits(nextDigits, state) {\r\n\t\tconst previouslyChosenFormat = this.chosenFormat\r\n\t\t// Choose a format from the list of matching ones.\r\n\t\tconst newlyChosenFormat = this.chooseFormat(state)\r\n\t\tif (newlyChosenFormat) {\r\n\t\t\tif (newlyChosenFormat === previouslyChosenFormat) {\r\n\t\t\t\t// If it can format the next (current) digits\r\n\t\t\t\t// using the previously chosen phone number format\r\n\t\t\t\t// then return the updated formatted number.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(nextDigits)\r\n\t\t\t} else {\r\n\t\t\t\t// If a more appropriate phone number format\r\n\t\t\t\t// has been chosen for these \"leading digits\",\r\n\t\t\t\t// then re-format the national phone number part\r\n\t\t\t\t// using the newly selected format.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(state.getNationalDigits())\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tnarrowDownMatchingFormats({\r\n\t\tnationalSignificantNumber,\r\n\t\tnationalPrefix,\r\n\t\tinternational\r\n\t}) {\r\n\t\tconst leadingDigits = nationalSignificantNumber\r\n\r\n\t\t// \"leading digits\" pattern list starts with a\r\n\t\t// \"leading digits\" pattern fitting a maximum of 3 leading digits.\r\n\t\t// So, after a user inputs 3 digits of a national (significant) phone number\r\n\t\t// this national (significant) number can already be formatted.\r\n\t\t// The next \"leading digits\" pattern is for 4 leading digits max,\r\n\t\t// and the \"leading digits\" pattern after it is for 5 leading digits max, etc.\r\n\r\n\t\t// This implementation is different from Google's\r\n\t\t// in that it searches for a fitting format\r\n\t\t// even if the user has entered less than\r\n\t\t// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.\r\n\t\t// Because some leading digit patterns already match for a single first digit.\r\n\t\tlet leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH\r\n\t\tif (leadingDigitsPatternIndex < 0) {\r\n\t\t\tleadingDigitsPatternIndex = 0\r\n\t\t}\r\n\r\n\t\tthis.matchingFormats = this.matchingFormats.filter(\r\n\t\t\tformat => this.formatSuits(format, international, nationalPrefix)\r\n\t\t\t\t&& this.formatMatches(format, leadingDigits, leadingDigitsPatternIndex)\r\n\t\t)\r\n\r\n\t\t// If there was a phone number format chosen\r\n\t\t// and it no longer holds given the new leading digits then reset it.\r\n\t\t// The test for this `if` condition is marked as:\r\n\t\t// \"Reset a chosen format when it no longer holds given the new leading digits\".\r\n\t\t// To construct a valid test case for this one can find a country\r\n\t\t// in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`\r\n\t\t// and yielding another format for 4 `<leadingDigits>` (Australia in this case).\r\n\t\tif (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t}\r\n\r\n\tformatSuits(format, international, nationalPrefix) {\r\n\t\t// When a prefix before a national (significant) number is\r\n\t\t// simply a national prefix, then it's parsed as `this.nationalPrefix`.\r\n\t\t// In more complex cases, a prefix before national (significant) number\r\n\t\t// could include a national prefix as well as some \"capturing groups\",\r\n\t\t// and in that case there's no info whether a national prefix has been parsed.\r\n\t\t// If national prefix is not used when formatting a phone number\r\n\t\t// using this format, but a national prefix has been entered by the user,\r\n\t\t// and was extracted, then discard such phone number format.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184\r\n\t\tif (nationalPrefix &&\r\n\t\t\t!format.usesNationalPrefix() &&\r\n\t\t\t// !format.domesticCarrierCodeFormattingRule() &&\r\n\t\t\t!format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\t// If national prefix is mandatory for this phone number format\r\n\t\t// and there're no guarantees that a national prefix is present in user input\r\n\t\t// then discard this phone number format as not suitable.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193\r\n\t\tif (!international &&\r\n\t\t\t!nationalPrefix &&\r\n\t\t\tformat.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n\r\n\tformatMatches(format, leadingDigits, leadingDigitsPatternIndex) {\r\n\t\tconst leadingDigitsPatternsCount = format.leadingDigitsPatterns().length\r\n\r\n\t\t// If this format is not restricted to a certain\r\n\t\t// leading digits pattern then it fits.\r\n\t\t// The test case could be found by searching for \"leadingDigitsPatternsCount === 0\".\r\n\t\tif (leadingDigitsPatternsCount === 0) {\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\t// Start narrowing down the list of possible formats based on the leading digits.\r\n\t\t// (only previously matched formats take part in the narrowing down process)\r\n\r\n\t\t// `leading_digits_patterns` start with 3 digits min\r\n\t\t// and then go up from there one digit at a time.\r\n\t\tleadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1)\r\n\t\tconst leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]\r\n\r\n\t\t// Google imposes a requirement on the leading digits\r\n\t\t// to be minimum 3 digits long in order to be eligible\r\n\t\t// for checking those with a leading digits pattern.\r\n\t\t//\r\n\t\t// Since `leading_digits_patterns` start with 3 digits min,\r\n\t\t// Google's original `libphonenumber` library only starts\r\n\t\t// excluding any non-matching formats only when the\r\n\t\t// national number entered so far is at least 3 digits long,\r\n\t\t// otherwise format matching would give false negatives.\r\n\t\t//\r\n\t\t// For example, when the digits entered so far are `2`\r\n\t\t// and the leading digits pattern is `21` –\r\n\t\t// it's quite obvious in this case that the format could be the one\r\n\t\t// but due to the absence of further digits it would give false negative.\r\n\t\t//\r\n\t\t// Also, `leading_digits_patterns` doesn't always correspond to a single\r\n\t\t// digits count. For example, `60|8` pattern would already match `8`\r\n\t\t// but the `60` part would require having at least two leading digits,\r\n\t\t// so the whole pattern would require inputting two digits first in order to\r\n\t\t// decide on whether it matches the input, even when the input is \"80\".\r\n\t\t//\r\n\t\t// This library — `libphonenumber-js` — allows filtering by `leading_digits_patterns`\r\n\t\t// even when there's only 1 or 2 digits of the national (significant) number.\r\n\t\t// To do that, it uses a non-strict pattern matcher written specifically for that.\r\n\t\t//\r\n\t\tif (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {\r\n\t\t\t// Before leading digits < 3 matching was implemented:\r\n\t\t\t// return true\r\n\t\t\t//\r\n\t\t\t// After leading digits < 3 matching was implemented:\r\n\t\t\ttry {\r\n\t\t\t\treturn new PatternMatcher(leadingDigitsPattern).match(leadingDigits, { allowOverflow: true }) !== undefined\r\n\t\t\t} catch (error) /* istanbul ignore next */ {\r\n\t\t\t\t// There's a slight possibility that there could be some undiscovered bug\r\n\t\t\t\t// in the pattern matcher code. Since the \"leading digits < 3 matching\"\r\n\t\t\t\t// feature is not \"essential\" for operation, it can fall back to the old way\r\n\t\t\t\t// in case of any issues rather than halting the application's execution.\r\n\t\t\t\tconsole.error(error)\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are\r\n\t\t// available then use the usual regular expression matching.\r\n\t\t//\r\n\t\t// The whole pattern is wrapped in round brackets (`()`) because\r\n\t\t// the pattern can use \"or\" operator (`|`) at the top level of the pattern.\r\n\t\t//\r\n\t\treturn new RegExp(`^(${leadingDigitsPattern})`).test(leadingDigits)\r\n\t}\r\n\r\n\tgetFormatFormat(format, international) {\r\n\t\treturn international ? format.internationalFormat() : format.format()\r\n\t}\r\n\r\n\tchooseFormat(state) {\r\n\t\t// When there are multiple available formats, the formatter uses the first\r\n\t\t// format where a formatting template could be created.\r\n\t\t//\r\n\t\t// For some weird reason, `istanbul` says \"else path not taken\"\r\n\t\t// for the `for of` line below. Supposedly that means that\r\n\t\t// the loop doesn't ever go over the last element in the list.\r\n\t\t// That's true because there always is `this.chosenFormat`\r\n\t\t// when `this.matchingFormats` is non-empty.\r\n\t\t// And, for some weird reason, it doesn't think that the case\r\n\t\t// with empty `this.matchingFormats` qualifies for a valid \"else\" path.\r\n\t\t// So simply muting this `istanbul` warning.\r\n\t\t// It doesn't skip the contents of the `for of` loop,\r\n\t\t// it just skips the `for of` line.\r\n\t\t//\r\n\t\t/* istanbul ignore next */\r\n\t\tfor (const format of this.matchingFormats.slice()) {\r\n\t\t\t// If this format is currently being used\r\n\t\t\t// and is still suitable, then stick to it.\r\n\t\t\tif (this.chosenFormat === format) {\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\t// Sometimes, a formatting rule inserts additional digits in a phone number,\r\n\t\t\t// and \"as you type\" formatter can't do that: it should only use the digits\r\n\t\t\t// that the user has input.\r\n\t\t\t//\r\n\t\t\t// For example, in Argentina, there's a format for mobile phone numbers:\r\n\t\t\t//\r\n\t\t\t// {\r\n\t\t\t// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n\t\t\t// \"leading_digits_patterns\": [\"91\"],\r\n\t\t\t// \"national_prefix_formatting_rule\": \"0$1\",\r\n\t\t\t// \"format\": \"$2 15-$3-$4\",\r\n\t\t\t// \"international_format\": \"$1 $2 $3-$4\"\r\n\t\t\t// }\r\n\t\t\t//\r\n\t\t\t// In that format, `international_format` is used instead of `format`\r\n\t\t\t// because `format` inserts `15` in the formatted number,\r\n\t\t\t// and `AsYouType` formatter should only use the digits\r\n\t\t\t// the user has actually input, without adding any extra digits.\r\n\t\t\t// In this case, it wouldn't make a difference, because the `15`\r\n\t\t\t// is first stripped when applying `national_prefix_for_parsing`\r\n\t\t\t// and then re-added when using `format`, so in reality it doesn't\r\n\t\t\t// add any new digits to the number, but to detect that, the code\r\n\t\t\t// would have to be more complex: it would have to try formatting\r\n\t\t\t// the digits using the format and then see if any digits have\r\n\t\t\t// actually been added or removed, and then, every time a new digit\r\n\t\t\t// is input, it should re-check whether the chosen format doesn't\r\n\t\t\t// alter the digits.\r\n\t\t\t//\r\n\t\t\t// Google's code doesn't go that far, and so does this library:\r\n\t\t\t// it simply requires that a `format` doesn't add any additonal\r\n\t\t\t// digits to user's input.\r\n\t\t\t//\r\n\t\t\t// Also, people in general should move from inputting phone numbers\r\n\t\t\t// in national format (possibly with national prefixes)\r\n\t\t\t// and use international phone number format instead:\r\n\t\t\t// it's a logical thing in the modern age of mobile phones,\r\n\t\t\t// globalization and the internet.\r\n\t\t\t//\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (!NON_ALTERING_FORMAT_REG_EXP.test(this.getFormatFormat(format, state.international))) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tif (!this.createTemplateForFormat(format, state)) {\r\n\t\t\t\t// Remove the format if it can't generate a template.\r\n\t\t\t\tthis.matchingFormats = this.matchingFormats.filter(_ => _ !== format)\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tthis.chosenFormat = format\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tif (!this.chosenFormat) {\r\n\t\t\t// No format matches the national (significant) phone number.\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t\treturn this.chosenFormat\r\n\t}\r\n\r\n\tcreateTemplateForFormat(format, state) {\r\n\t\t// The formatter doesn't format numbers when numberPattern contains '|', e.g.\r\n\t\t// (20|3)\\d{4}. In those cases we quickly return.\r\n\t\t// (Though there's no such format in current metadata)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Get formatting template for this phone number format\r\n\t\tconst template = this.getTemplateForFormat(format, state)\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (template) {\r\n\t\t\tthis.setNationalNumberTemplate(template, state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\tgetSeparatorAfterNationalPrefix(format) {\r\n\t\t// `US` metadata doesn't have a `national_prefix_formatting_rule`,\r\n\t\t// so the `if` condition below doesn't apply to `US`,\r\n\t\t// but in reality there shoudl be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\t// So `US` national prefix separator is a \"special\" \"hardcoded\" case.\r\n\t\tif (this.isNANP) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// If a `format` has a `national_prefix_formatting_rule`\r\n\t\t// and that rule has a separator after a national prefix,\r\n\t\t// then it means that there should be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\tif (format &&\r\n\t\t\tformat.nationalPrefixFormattingRule() &&\r\n\t\t\tNATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// At this point, there seems to be no clear evidence that\r\n\t\t// there should be a separator between a national prefix\r\n\t\t// and a national (significant) number. So don't insert one.\r\n\t\treturn ''\r\n\t}\r\n\r\n\tgetInternationalPrefixBeforeCountryCallingCode({ IDDPrefix, missingPlus }, options) {\r\n\t\tif (IDDPrefix) {\r\n\t\t\treturn options && options.spacing === false ? IDDPrefix : IDDPrefix + ' '\r\n\t\t}\r\n\t\tif (missingPlus) {\r\n\t\t\treturn ''\r\n\t\t}\r\n\t\treturn '+'\r\n\t}\r\n\r\n\tgetTemplate(state) {\r\n\t\tif (!this.template) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// `this.template` holds the template for a \"complete\" phone number.\r\n\t\t// The currently entered phone number is most likely not \"complete\",\r\n\t\t// so trim all non-populated digits.\r\n\t\tlet index = -1\r\n\t\tlet i = 0\r\n\t\tconst internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, { spacing: false }) : ''\r\n\t\twhile (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {\r\n\t\t\tindex = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn cutAndStripNonPairedParens(this.template, index + 1)\r\n\t}\r\n\r\n\tsetNationalNumberTemplate(template, state) {\r\n\t\tthis.nationalNumberTemplate = template\r\n\t\tthis.populatedNationalNumberTemplate = template\r\n\t\t// With a new formatting template, the matched position\r\n\t\t// using the old template needs to be reset.\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t\t// For convenience, the public `.template` property\r\n\t\t// contains the whole international number\r\n\t\t// if the phone number being input is international:\r\n\t\t// 'x' for the '+' sign, 'x'es for the country phone code,\r\n\t\t// a spacebar and then the template for the formatted national number.\r\n\t\tif (state.international) {\r\n\t\t\tthis.template =\r\n\t\t\t\tthis.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER) +\r\n\t\t\t\trepeat(DIGIT_PLACEHOLDER, state.callingCode.length) +\r\n\t\t\t\t' ' +\r\n\t\t\t\ttemplate\r\n\t\t} else {\r\n\t\t\tthis.template = template\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Generates formatting template for a national phone number,\r\n\t * optionally containing a national prefix, for a format.\r\n\t * @param {Format} format\r\n\t * @param {string} nationalPrefix\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplateForFormat(format, {\r\n\t\tnationalSignificantNumber,\r\n\t\tinternational,\r\n\t\tnationalPrefix,\r\n\t\tcomplexPrefixBeforeNationalSignificantNumber\r\n\t}) {\r\n\t\tlet pattern = format.pattern()\r\n\r\n\t\t/* istanbul ignore else */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS) {\r\n\t\t\tpattern = pattern\r\n\t\t\t\t// Replace anything in the form of [..] with \\d\r\n\t\t\t\t.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\\\d')\r\n\t\t\t\t// Replace any standalone digit (not the one in `{}`) with \\d\r\n\t\t\t\t.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\\\d')\r\n\t\t}\r\n\r\n\t\t// Generate a dummy national number (consisting of `9`s)\r\n\t\t// that fits this format's `pattern`.\r\n\t\t//\r\n\t\t// This match will always succeed,\r\n\t\t// because the \"longest dummy phone number\"\r\n\t\t// has enough length to accomodate any possible\r\n\t\t// national phone number format pattern.\r\n\t\t//\r\n\t\tlet digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]\r\n\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (nationalSignificantNumber.length > digits.length) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// Get a formatting template which can be used to efficiently format\r\n\t\t// a partial number where digits are added one by one.\r\n\r\n\t\t// Below `strictPattern` is used for the\r\n\t\t// regular expression (with `^` and `$`).\r\n\t\t// This wasn't originally in Google's `libphonenumber`\r\n\t\t// and I guess they don't really need it\r\n\t\t// because they're not using \"templates\" to format phone numbers\r\n\t\t// but I added `strictPattern` after encountering\r\n\t\t// South Korean phone number formatting bug.\r\n\t\t//\r\n\t\t// Non-strict regular expression bug demonstration:\r\n\t\t//\r\n\t\t// this.nationalSignificantNumber : `111111111` (9 digits)\r\n\t\t//\r\n\t\t// pattern : (\\d{2})(\\d{3,4})(\\d{4})\r\n\t\t// format : `$1 $2 $3`\r\n\t\t// digits : `9999999999` (10 digits)\r\n\t\t//\r\n\t\t// '9999999999'.replace(new RegExp(/(\\d{2})(\\d{3,4})(\\d{4})/g), '$1 $2 $3') = \"99 9999 9999\"\r\n\t\t//\r\n\t\t// template : xx xxxx xxxx\r\n\t\t//\r\n\t\t// But the correct template in this case is `xx xxx xxxx`.\r\n\t\t// The template was generated incorrectly because of the\r\n\t\t// `{3,4}` variability in the `pattern`.\r\n\t\t//\r\n\t\t// The fix is, if `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then `this.nationalSignificantNumber`\r\n\t\t// is used instead of `digits`.\r\n\r\n\t\tconst strictPattern = new RegExp('^' + pattern + '$')\r\n\t\tconst nationalNumberDummyDigits = nationalSignificantNumber.replace(/\\d/g, DUMMY_DIGIT)\r\n\r\n\t\t// If `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then use it\r\n\t\t// instead of `digits`.\r\n\t\tif (strictPattern.test(nationalNumberDummyDigits)) {\r\n\t\t\tdigits = nationalNumberDummyDigits\r\n\t\t}\r\n\r\n\t\tlet numberFormat = this.getFormatFormat(format, international)\r\n\t\tlet nationalPrefixIncludedInTemplate\r\n\r\n\t\t// If a user did input a national prefix (and that's guaranteed),\r\n\t\t// and if a `format` does have a national prefix formatting rule,\r\n\t\t// then see if that national prefix formatting rule\r\n\t\t// prepends exactly the same national prefix the user has input.\r\n\t\t// If that's the case, then use the `format` with the national prefix formatting rule.\r\n\t\t// Otherwise, use the `format` without the national prefix formatting rule,\r\n\t\t// and prepend a national prefix manually to it.\r\n\t\tif (this.shouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix })) {\r\n\t\t\tconst numberFormatWithNationalPrefix = numberFormat.replace(\r\n\t\t\t\tFIRST_GROUP_PATTERN,\r\n\t\t\t\tformat.nationalPrefixFormattingRule()\r\n\t\t\t)\r\n\t\t\t// If `national_prefix_formatting_rule` of a `format` simply prepends\r\n\t\t\t// national prefix at the start of a national (significant) number,\r\n\t\t\t// then such formatting can be used with `AsYouType` formatter.\r\n\t\t\t// There seems to be no `else` case: everywhere in metadata,\r\n\t\t\t// national prefix formatting rule is national prefix + $1,\r\n\t\t\t// or `($1)`, in which case such format isn't even considered\r\n\t\t\t// when the user has input a national prefix.\r\n\t\t\t/* istanbul ignore else */\r\n\t\t\tif (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {\r\n\t\t\t\tnumberFormat = numberFormatWithNationalPrefix\r\n\t\t\t\tnationalPrefixIncludedInTemplate = true\r\n\t\t\t\t// Replace all digits of the national prefix in the formatting template\r\n\t\t\t\t// with `DIGIT_PLACEHOLDER`s.\r\n\t\t\t\tif (nationalPrefix) {\r\n\t\t\t\t\tlet i = nationalPrefix.length\r\n\t\t\t\t\twhile (i > 0) {\r\n\t\t\t\t\t\tnumberFormat = numberFormat.replace(/\\d/, DIGIT_PLACEHOLDER)\r\n\t\t\t\t\t\ti--\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Generate formatting template for this phone number format.\r\n\t\tlet template = digits\r\n\t\t\t// Format the dummy phone number according to the format.\r\n\t\t\t.replace(new RegExp(pattern), numberFormat)\r\n\t\t\t// Replace each dummy digit with a DIGIT_PLACEHOLDER.\r\n\t\t\t.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)\r\n\r\n\t\t// If a prefix of a national (significant) number is not as simple\r\n\t\t// as just a basic national prefix, then just prepend such prefix\r\n\t\t// before the national (significant) number, optionally spacing\r\n\t\t// the two with a whitespace.\r\n\t\tif (!nationalPrefixIncludedInTemplate) {\r\n\t\t\tif (complexPrefixBeforeNationalSignificantNumber) {\r\n\t\t\t\t// Prepend the prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, complexPrefixBeforeNationalSignificantNumber.length) +\r\n\t\t\t\t\t' ' +\r\n\t\t\t\t\ttemplate\r\n\t\t\t} else if (nationalPrefix) {\r\n\t\t\t\t// Prepend national prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +\r\n\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\r\n\t\t\t\t\ttemplate\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (international) {\r\n\t\t\ttemplate = applyInternationalSeparatorStyle(template)\r\n\t\t}\r\n\r\n\t\treturn template\r\n\t}\r\n\r\n\tformatNextNationalNumberDigits(digits) {\r\n\t\tconst result = populateTemplateWithDigits(\r\n\t\t\tthis.populatedNationalNumberTemplate,\r\n\t\t\tthis.populatedNationalNumberTemplatePosition,\r\n\t\t\tdigits\r\n\t\t)\r\n\r\n\t\tif (!result) {\r\n\t\t\t// Reset the format.\r\n\t\t\tthis.resetFormat()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.populatedNationalNumberTemplate = result[0]\r\n\t\tthis.populatedNationalNumberTemplatePosition = result[1]\r\n\r\n\t\t// Return the formatted phone number so far.\r\n\t\treturn cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\r\n\t\t// The old way which was good for `input-format` but is not so good\r\n\t\t// for `react-phone-number-input`'s default input (`InputBasic`).\r\n\t\t// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\t\t// \t.replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')\r\n\t}\r\n\r\n\tshouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix }) {\r\n\t\tif (format.nationalPrefixFormattingRule()) {\r\n\t\t\t// In some countries, `national_prefix_formatting_rule` is `($1)`,\r\n\t\t\t// so it applies even if the user hasn't input a national prefix.\r\n\t\t\t// `format.usesNationalPrefix()` detects such cases.\r\n\t\t\tconst usesNationalPrefix = format.usesNationalPrefix()\r\n\t\t\tif ((usesNationalPrefix && nationalPrefix) ||\r\n\t\t\t\t(!usesNationalPrefix && !international)) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;AAAA,SACCA,iBADD,EAECC,eAFD,EAGCC,MAHD,EAICC,0BAJD,EAKCC,oBALD,EAMCC,oBAND,EAOCC,0BAPD,QAQO,8BARP;AAUA,OAAOC,oBAAP,IACCC,uBADD,QAEO,kCAFP;AAIA,OAAOC,cAAP,MAA2B,wCAA3B;AAEA,OAAOC,WAAP,MAAwB,0BAAxB;AACA,SAASV,iBAAT,QAAkC,8BAAlC;AACA,SAASW,mBAAT,QAAoC,8CAApC;AACA,SAASC,iBAAT,QAAkC,gBAAlC;AACA,OAAOC,gCAAP,MAA6C,+CAA7C,C,CAEA;AACA;;AACA,IAAMC,WAAW,GAAG,GAApB,C,CACA;;AACA,IAAMC,oCAAoC,GAAG,EAA7C,C,CACA;AACA;;AACA,IAAMC,0BAA0B,GAAGd,MAAM,CAACY,WAAD,EAAcC,oCAAd,CAAzC,C,CAEA;AACA;;AACA,IAAME,kCAAkC,GAAG,MAA3C,C,CAEA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,kCAAkC,GAAG,IAA3C,C,CAEA;AACA;;AACA,IAAMC,8BAA8B,GAAGD,kCAAkC,IAAK;EAAA,OAAM,iBAAN;AAAA,CAA9E,C,CAEA;AACA;AACA;AACA;AACA;;;AACA,IAAME,+BAA+B,GA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