libphonenumber-js 1.12.10 → 1.12.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/build/AsYouType.js +69 -131
- package/build/AsYouType.js.map +1 -1
- package/build/AsYouType.test.js +610 -553
- package/build/AsYouType.test.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternMatcher.js +29 -77
- package/build/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternMatcher.test.js +107 -109
- package/build/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternParser.js +34 -67
- package/build/AsYouTypeFormatter.PatternParser.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternParser.test.js +7 -9
- package/build/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
- package/build/AsYouTypeFormatter.complete.js +18 -28
- package/build/AsYouTypeFormatter.complete.js.map +1 -1
- package/build/AsYouTypeFormatter.js +193 -233
- package/build/AsYouTypeFormatter.js.map +1 -1
- package/build/AsYouTypeFormatter.util.js +11 -38
- package/build/AsYouTypeFormatter.util.js.map +1 -1
- package/build/AsYouTypeFormatter.util.test.js +6 -7
- package/build/AsYouTypeFormatter.util.test.js.map +1 -1
- package/build/AsYouTypeParser.js +89 -143
- package/build/AsYouTypeParser.js.map +1 -1
- package/build/AsYouTypeState.js +13 -23
- package/build/AsYouTypeState.js.map +1 -1
- package/build/ParseError.js +22 -43
- package/build/ParseError.js.map +1 -1
- package/build/PhoneNumber.js +33 -70
- package/build/PhoneNumber.js.map +1 -1
- package/build/PhoneNumber.test.js +35 -33
- package/build/PhoneNumber.test.js.map +1 -1
- package/build/PhoneNumberMatcher.js +67 -101
- package/build/PhoneNumberMatcher.js.map +1 -1
- package/build/PhoneNumberMatcher.test.js +35 -18
- package/build/PhoneNumberMatcher.test.js.map +1 -1
- package/build/constants.js +17 -19
- package/build/constants.js.map +1 -1
- package/build/findNumbers/LRUCache.js +23 -34
- package/build/findNumbers/LRUCache.js.map +1 -1
- package/build/findNumbers/Leniency.js +58 -114
- package/build/findNumbers/Leniency.js.map +1 -1
- package/build/findNumbers/RegExpCache.js +9 -20
- package/build/findNumbers/RegExpCache.js.map +1 -1
- package/build/findNumbers/isValidCandidate.js +12 -19
- package/build/findNumbers/isValidCandidate.js.map +1 -1
- package/build/findNumbers/isValidPreCandidate.js +5 -7
- package/build/findNumbers/isValidPreCandidate.js.map +1 -1
- package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +9 -15
- package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
- package/build/findNumbers/parsePreCandidate.js +0 -3
- package/build/findNumbers/parsePreCandidate.js.map +1 -1
- package/build/findNumbers/utf-8.js +9 -13
- package/build/findNumbers/utf-8.js.map +1 -1
- package/build/findNumbers/util.js +1 -8
- package/build/findNumbers/util.js.map +1 -1
- package/build/findNumbers/util.test.js +9 -15
- package/build/findNumbers/util.test.js.map +1 -1
- package/build/findPhoneNumbersInText.js +10 -17
- package/build/findPhoneNumbersInText.js.map +1 -1
- package/build/findPhoneNumbersInText.test.js +100 -93
- package/build/findPhoneNumbersInText.test.js.map +1 -1
- package/build/format.js +31 -64
- package/build/format.js.map +1 -1
- package/build/format.test.js +133 -119
- package/build/format.test.js.map +1 -1
- package/build/formatIncompletePhoneNumber.js +1 -5
- package/build/formatIncompletePhoneNumber.js.map +1 -1
- package/build/formatIncompletePhoneNumber.test.js +14 -13
- package/build/formatIncompletePhoneNumber.test.js.map +1 -1
- package/build/formatPhoneNumberForMobileDialing.js +32 -32
- package/build/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/build/getCountries.js +1 -4
- package/build/getCountries.js.map +1 -1
- package/build/getCountries.test.js +2 -5
- package/build/getCountries.test.js.map +1 -1
- package/build/getCountryCallingCode.js +0 -1
- package/build/getCountryCallingCode.js.map +1 -1
- package/build/getCountryCallingCode.test.js +2 -5
- package/build/getCountryCallingCode.test.js.map +1 -1
- package/build/getExampleNumber.js +1 -4
- package/build/getExampleNumber.js.map +1 -1
- package/build/getExampleNumber.test.js +5 -9
- package/build/getExampleNumber.test.js.map +1 -1
- package/build/helpers/RFC3966.js +16 -38
- package/build/helpers/RFC3966.js.map +1 -1
- package/build/helpers/RFC3966.test.js +16 -14
- package/build/helpers/RFC3966.test.js.map +1 -1
- package/build/helpers/applyInternationalSeparatorStyle.js +0 -2
- package/build/helpers/applyInternationalSeparatorStyle.js.map +1 -1
- package/build/helpers/applyInternationalSeparatorStyle.test.js +3 -5
- package/build/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
- package/build/helpers/checkNumberLength.js +18 -22
- package/build/helpers/checkNumberLength.js.map +1 -1
- package/build/helpers/checkNumberLength.test.js +19 -27
- package/build/helpers/checkNumberLength.test.js.map +1 -1
- package/build/helpers/extension/createExtensionPattern.js +19 -35
- package/build/helpers/extension/createExtensionPattern.js.map +1 -1
- package/build/helpers/extension/extractExtension.js +6 -12
- package/build/helpers/extension/extractExtension.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.js +14 -24
- package/build/helpers/extractCountryCallingCode.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.test.js +4 -7
- package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +4 -16
- package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +16 -29
- package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
- package/build/helpers/extractNationalNumber.js +10 -21
- package/build/helpers/extractNationalNumber.js.map +1 -1
- package/build/helpers/extractNationalNumber.test.js +2 -8
- package/build/helpers/extractNationalNumber.test.js.map +1 -1
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -18
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -6
- package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
- package/build/helpers/extractPhoneContext.js +19 -28
- package/build/helpers/extractPhoneContext.js.map +1 -1
- package/build/helpers/extractPhoneContext.test.js +12 -15
- package/build/helpers/extractPhoneContext.test.js.map +1 -1
- package/build/helpers/formatNationalNumberUsingFormat.js +7 -13
- package/build/helpers/formatNationalNumberUsingFormat.js.map +1 -1
- package/build/helpers/getCountryByCallingCode.js +5 -14
- package/build/helpers/getCountryByCallingCode.js.map +1 -1
- package/build/helpers/getCountryByNationalNumber.js +18 -20
- package/build/helpers/getCountryByNationalNumber.js.map +1 -1
- package/build/helpers/getIddPrefix.js +4 -8
- package/build/helpers/getIddPrefix.js.map +1 -1
- package/build/helpers/getNumberType.js +23 -35
- package/build/helpers/getNumberType.js.map +1 -1
- package/build/helpers/getNumberType.test.js +4 -8
- package/build/helpers/getNumberType.test.js.map +1 -1
- package/build/helpers/getPossibleCountriesForNumber.js +1 -11
- package/build/helpers/getPossibleCountriesForNumber.js.map +1 -1
- package/build/helpers/isObject.js +0 -1
- package/build/helpers/isObject.js.map +1 -1
- package/build/helpers/isViablePhoneNumber.js +19 -19
- package/build/helpers/isViablePhoneNumber.js.map +1 -1
- package/build/helpers/matchesEntirely.js +0 -1
- package/build/helpers/matchesEntirely.js.map +1 -1
- package/build/helpers/matchesEntirely.test.js +4 -5
- package/build/helpers/matchesEntirely.test.js.map +1 -1
- package/build/helpers/mergeArrays.js +6 -11
- package/build/helpers/mergeArrays.js.map +1 -1
- package/build/helpers/mergeArrays.test.js +2 -4
- package/build/helpers/mergeArrays.test.js.map +1 -1
- package/build/helpers/parseDigits.js +7 -17
- package/build/helpers/parseDigits.js.map +1 -1
- package/build/helpers/parseDigits.test.js +2 -4
- package/build/helpers/parseDigits.test.js.map +1 -1
- package/build/helpers/stripIddPrefix.js +7 -17
- package/build/helpers/stripIddPrefix.js.map +1 -1
- package/build/helpers/stripIddPrefix.test.js +4 -7
- package/build/helpers/stripIddPrefix.test.js.map +1 -1
- package/build/isPossible.js +3 -15
- package/build/isPossible.js.map +1 -1
- package/build/isPossible.test.js +34 -41
- package/build/isPossible.test.js.map +1 -1
- package/build/isPossiblePhoneNumber.js +10 -15
- package/build/isPossiblePhoneNumber.js.map +1 -1
- package/build/isPossiblePhoneNumber.test.js +11 -17
- package/build/isPossiblePhoneNumber.test.js.map +1 -1
- package/build/isValid.js +7 -11
- package/build/isValid.js.map +1 -1
- package/build/isValid.test.js +59 -58
- package/build/isValid.test.js.map +1 -1
- package/build/isValidPhoneNumber.js +10 -15
- package/build/isValidPhoneNumber.js.map +1 -1
- package/build/isValidPhoneNumber.test.js +10 -15
- package/build/isValidPhoneNumber.test.js.map +1 -1
- package/build/legacy/findNumbers.js +4 -11
- package/build/legacy/findNumbers.js.map +1 -1
- package/build/legacy/findNumbers.test.js +77 -63
- package/build/legacy/findNumbers.test.js.map +1 -1
- package/build/legacy/findPhoneNumbers.js +11 -21
- package/build/legacy/findPhoneNumbers.js.map +1 -1
- package/build/legacy/findPhoneNumbers.test.js +75 -72
- package/build/legacy/findPhoneNumbers.test.js.map +1 -1
- package/build/legacy/findPhoneNumbersInitialImplementation.js +34 -62
- package/build/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
- package/build/legacy/format.js +28 -44
- package/build/legacy/format.js.map +1 -1
- package/build/legacy/format.test.js +119 -103
- package/build/legacy/format.test.js.map +1 -1
- package/build/legacy/getNumberType.js +30 -44
- package/build/legacy/getNumberType.js.map +1 -1
- package/build/legacy/getNumberType.test.js +31 -34
- package/build/legacy/getNumberType.test.js.map +1 -1
- package/build/legacy/isPossibleNumber.js +5 -11
- package/build/legacy/isPossibleNumber.js.map +1 -1
- package/build/legacy/isPossibleNumber.test.js +22 -25
- package/build/legacy/isPossibleNumber.test.js.map +1 -1
- package/build/legacy/isValidNumber.js +5 -11
- package/build/legacy/isValidNumber.js.map +1 -1
- package/build/legacy/isValidNumber.test.js +41 -39
- package/build/legacy/isValidNumber.test.js.map +1 -1
- package/build/legacy/isValidNumberForRegion.js +4 -12
- package/build/legacy/isValidNumberForRegion.js.map +1 -1
- package/build/legacy/isValidNumberForRegion.test.js +6 -11
- package/build/legacy/isValidNumberForRegion.test.js.map +1 -1
- package/build/legacy/isValidNumberForRegion_.js +1 -4
- package/build/legacy/isValidNumberForRegion_.js.map +1 -1
- package/build/legacy/parse.js +4 -9
- package/build/legacy/parse.js.map +1 -1
- package/build/legacy/parse.test.js +232 -193
- package/build/legacy/parse.test.js.map +1 -1
- package/build/legacy/searchNumbers.js +8 -12
- package/build/legacy/searchNumbers.js.map +1 -1
- package/build/legacy/searchNumbers.test.js +6 -14
- package/build/legacy/searchNumbers.test.js.map +1 -1
- package/build/metadata.js +85 -122
- package/build/metadata.js.map +1 -1
- package/build/metadata.test.js +54 -80
- package/build/metadata.test.js.map +1 -1
- package/build/normalizeArguments.js +25 -35
- package/build/normalizeArguments.js.map +1 -1
- package/build/parse.js +66 -116
- package/build/parse.js.map +1 -1
- package/build/parse.test.js +243 -205
- package/build/parse.test.js.map +1 -1
- package/build/parseIncompletePhoneNumber.js +8 -18
- package/build/parseIncompletePhoneNumber.js.map +1 -1
- package/build/parseIncompletePhoneNumber.test.js +24 -25
- package/build/parseIncompletePhoneNumber.test.js.map +1 -1
- package/build/parsePhoneNumber.js +4 -9
- package/build/parsePhoneNumber.js.map +1 -1
- package/build/parsePhoneNumber.test.js +14 -25
- package/build/parsePhoneNumber.test.js.map +1 -1
- package/build/parsePhoneNumberWithError.js +4 -9
- package/build/parsePhoneNumberWithError.js.map +1 -1
- package/build/parsePhoneNumberWithError.test.js +30 -34
- package/build/parsePhoneNumberWithError.test.js.map +1 -1
- package/build/parsePhoneNumberWithError_.js +7 -10
- package/build/parsePhoneNumberWithError_.js.map +1 -1
- package/build/parsePhoneNumber_.js +11 -16
- package/build/parsePhoneNumber_.js.map +1 -1
- package/build/searchPhoneNumbersInText.js +10 -16
- package/build/searchPhoneNumbersInText.js.map +1 -1
- package/build/searchPhoneNumbersInText.test.js +11 -21
- package/build/searchPhoneNumbersInText.test.js.map +1 -1
- package/build/tools/semver-compare.js +0 -4
- package/build/tools/semver-compare.js.map +1 -1
- package/build/tools/semver-compare.test.js +2 -4
- package/build/tools/semver-compare.test.js.map +1 -1
- package/build/validatePhoneNumberLength.js +12 -20
- package/build/validatePhoneNumberLength.js.map +1 -1
- package/build/validatePhoneNumberLength.test.js +14 -16
- package/build/validatePhoneNumberLength.test.js.map +1 -1
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/es6/AsYouType.js +66 -112
- package/es6/AsYouType.js.map +1 -1
- package/es6/AsYouType.test.js +610 -551
- package/es6/AsYouType.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternMatcher.js +27 -72
- package/es6/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js +106 -106
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternParser.js +33 -64
- package/es6/AsYouTypeFormatter.PatternParser.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternParser.test.js +6 -6
- package/es6/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.complete.js +17 -21
- package/es6/AsYouTypeFormatter.complete.js.map +1 -1
- package/es6/AsYouTypeFormatter.js +193 -217
- package/es6/AsYouTypeFormatter.js.map +1 -1
- package/es6/AsYouTypeFormatter.util.js +10 -30
- package/es6/AsYouTypeFormatter.util.js.map +1 -1
- package/es6/AsYouTypeFormatter.util.test.js +6 -6
- package/es6/AsYouTypeFormatter.util.test.js.map +1 -1
- package/es6/AsYouTypeParser.js +87 -132
- package/es6/AsYouTypeParser.js.map +1 -1
- package/es6/AsYouTypeState.js +12 -20
- package/es6/AsYouTypeState.js.map +1 -1
- package/es6/ParseError.js +21 -40
- package/es6/ParseError.js.map +1 -1
- package/es6/PhoneNumber.js +32 -53
- package/es6/PhoneNumber.js.map +1 -1
- package/es6/PhoneNumber.test.js +35 -30
- package/es6/PhoneNumber.test.js.map +1 -1
- package/es6/PhoneNumberMatcher.js +61 -78
- package/es6/PhoneNumberMatcher.js.map +1 -1
- package/es6/PhoneNumberMatcher.test.js +35 -16
- package/es6/PhoneNumberMatcher.test.js.map +1 -1
- package/es6/constants.js +15 -9
- package/es6/constants.js.map +1 -1
- package/es6/findNumbers/LRUCache.js +22 -31
- package/es6/findNumbers/LRUCache.js.map +1 -1
- package/es6/findNumbers/Leniency.js +57 -103
- package/es6/findNumbers/Leniency.js.map +1 -1
- package/es6/findNumbers/RegExpCache.js +10 -16
- package/es6/findNumbers/RegExpCache.js.map +1 -1
- package/es6/findNumbers/isValidCandidate.js +12 -13
- package/es6/findNumbers/isValidCandidate.js.map +1 -1
- package/es6/findNumbers/isValidPreCandidate.js +5 -6
- package/es6/findNumbers/isValidPreCandidate.js.map +1 -1
- package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +9 -12
- package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
- package/es6/findNumbers/parsePreCandidate.js +3 -2
- package/es6/findNumbers/parsePreCandidate.js.map +1 -1
- package/es6/findNumbers/utf-8.js +5 -3
- package/es6/findNumbers/utf-8.js.map +1 -1
- package/es6/findNumbers/util.js +1 -4
- package/es6/findNumbers/util.js.map +1 -1
- package/es6/findNumbers/util.test.js +9 -14
- package/es6/findNumbers/util.test.js.map +1 -1
- package/es6/findPhoneNumbersInText.js +9 -12
- package/es6/findPhoneNumbersInText.js.map +1 -1
- package/es6/findPhoneNumbersInText.test.js +101 -91
- package/es6/findPhoneNumbersInText.test.js.map +1 -1
- package/es6/format.js +27 -50
- package/es6/format.js.map +1 -1
- package/es6/format.test.js +133 -116
- package/es6/format.test.js.map +1 -1
- package/es6/formatIncompletePhoneNumber.js +1 -2
- package/es6/formatIncompletePhoneNumber.js.map +1 -1
- package/es6/formatIncompletePhoneNumber.test.js +14 -10
- package/es6/formatIncompletePhoneNumber.test.js.map +1 -1
- package/es6/formatPhoneNumberForMobileDialing.js +31 -24
- package/es6/formatPhoneNumberForMobileDialing.js.map +1 -1
- package/es6/getCountries.js.map +1 -1
- package/es6/getCountries.test.js +2 -2
- package/es6/getCountries.test.js.map +1 -1
- package/es6/getCountryCallingCode.js.map +1 -1
- package/es6/getCountryCallingCode.test.js +2 -2
- package/es6/getCountryCallingCode.test.js.map +1 -1
- package/es6/getExampleNumber.js.map +1 -1
- package/es6/getExampleNumber.test.js +6 -6
- package/es6/getExampleNumber.test.js.map +1 -1
- package/es6/helpers/RFC3966.js +17 -34
- package/es6/helpers/RFC3966.js.map +1 -1
- package/es6/helpers/RFC3966.test.js +16 -13
- package/es6/helpers/RFC3966.test.js.map +1 -1
- package/es6/helpers/applyInternationalSeparatorStyle.js +3 -2
- package/es6/helpers/applyInternationalSeparatorStyle.js.map +1 -1
- package/es6/helpers/applyInternationalSeparatorStyle.test.js +2 -2
- package/es6/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
- package/es6/helpers/checkNumberLength.js +17 -17
- package/es6/helpers/checkNumberLength.js.map +1 -1
- package/es6/helpers/checkNumberLength.test.js +20 -23
- package/es6/helpers/checkNumberLength.test.js.map +1 -1
- package/es6/helpers/extension/createExtensionPattern.js +21 -34
- package/es6/helpers/extension/createExtensionPattern.js.map +1 -1
- package/es6/helpers/extension/extractExtension.js +7 -9
- package/es6/helpers/extension/extractExtension.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.js +14 -18
- package/es6/helpers/extractCountryCallingCode.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.test.js +4 -4
- package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +4 -9
- package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
- package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +14 -19
- package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
- package/es6/helpers/extractNationalNumber.js +10 -15
- package/es6/helpers/extractNationalNumber.js.map +1 -1
- package/es6/helpers/extractNationalNumber.test.js +2 -4
- package/es6/helpers/extractNationalNumber.test.js.map +1 -1
- package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -17
- 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/extractPhoneContext.js +17 -17
- package/es6/helpers/extractPhoneContext.js.map +1 -1
- package/es6/helpers/extractPhoneContext.test.js +12 -12
- package/es6/helpers/extractPhoneContext.test.js.map +1 -1
- package/es6/helpers/formatNationalNumberUsingFormat.js +8 -8
- package/es6/helpers/formatNationalNumberUsingFormat.js.map +1 -1
- package/es6/helpers/getCountryByCallingCode.js +4 -9
- package/es6/helpers/getCountryByCallingCode.js.map +1 -1
- package/es6/helpers/getCountryByNationalNumber.js +17 -15
- package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
- package/es6/helpers/getIddPrefix.js +3 -4
- package/es6/helpers/getIddPrefix.js.map +1 -1
- package/es6/helpers/getNumberType.js +22 -29
- package/es6/helpers/getNumberType.js.map +1 -1
- package/es6/helpers/getNumberType.test.js +4 -4
- package/es6/helpers/getNumberType.test.js.map +1 -1
- package/es6/helpers/getPossibleCountriesForNumber.js +1 -8
- package/es6/helpers/getPossibleCountriesForNumber.js.map +1 -1
- package/es6/helpers/isObject.js.map +1 -1
- package/es6/helpers/isViablePhoneNumber.js +21 -13
- package/es6/helpers/isViablePhoneNumber.js.map +1 -1
- package/es6/helpers/matchesEntirely.js.map +1 -1
- package/es6/helpers/matchesEntirely.test.js +3 -2
- package/es6/helpers/matchesEntirely.test.js.map +1 -1
- package/es6/helpers/mergeArrays.js +6 -10
- 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 +6 -12
- 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 +6 -11
- package/es6/helpers/stripIddPrefix.js.map +1 -1
- package/es6/helpers/stripIddPrefix.test.js +4 -4
- package/es6/helpers/stripIddPrefix.test.js.map +1 -1
- package/es6/isPossible.js +3 -10
- package/es6/isPossible.js.map +1 -1
- package/es6/isPossible.test.js +34 -38
- package/es6/isPossible.test.js.map +1 -1
- package/es6/isPossiblePhoneNumber.js +9 -10
- package/es6/isPossiblePhoneNumber.js.map +1 -1
- package/es6/isPossiblePhoneNumber.test.js +12 -16
- package/es6/isPossiblePhoneNumber.test.js.map +1 -1
- package/es6/isValid.js +7 -6
- package/es6/isValid.js.map +1 -1
- package/es6/isValid.test.js +59 -55
- package/es6/isValid.test.js.map +1 -1
- package/es6/isValidPhoneNumber.js +9 -10
- package/es6/isValidPhoneNumber.js.map +1 -1
- package/es6/isValidPhoneNumber.test.js +10 -13
- package/es6/isValidPhoneNumber.test.js.map +1 -1
- package/es6/legacy/findNumbers.js +3 -6
- package/es6/legacy/findNumbers.js.map +1 -1
- package/es6/legacy/findNumbers.test.js +77 -60
- package/es6/legacy/findNumbers.test.js.map +1 -1
- package/es6/legacy/findPhoneNumbers.js +8 -9
- package/es6/legacy/findPhoneNumbers.js.map +1 -1
- package/es6/legacy/findPhoneNumbers.test.js +73 -62
- package/es6/legacy/findPhoneNumbers.test.js.map +1 -1
- package/es6/legacy/findPhoneNumbersInitialImplementation.js +32 -45
- package/es6/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
- package/es6/legacy/format.js +27 -37
- package/es6/legacy/format.js.map +1 -1
- package/es6/legacy/format.test.js +119 -101
- package/es6/legacy/format.test.js.map +1 -1
- package/es6/legacy/getNumberType.js +31 -37
- package/es6/legacy/getNumberType.js.map +1 -1
- package/es6/legacy/getNumberType.test.js +31 -31
- package/es6/legacy/getNumberType.test.js.map +1 -1
- package/es6/legacy/isPossibleNumber.js +5 -7
- package/es6/legacy/isPossibleNumber.js.map +1 -1
- package/es6/legacy/isPossibleNumber.test.js +22 -23
- package/es6/legacy/isPossibleNumber.test.js.map +1 -1
- package/es6/legacy/isValidNumber.js +6 -7
- package/es6/legacy/isValidNumber.js.map +1 -1
- package/es6/legacy/isValidNumber.test.js +41 -37
- package/es6/legacy/isValidNumber.test.js.map +1 -1
- package/es6/legacy/isValidNumberForRegion.js +5 -7
- package/es6/legacy/isValidNumberForRegion.js.map +1 -1
- package/es6/legacy/isValidNumberForRegion.test.js +6 -8
- package/es6/legacy/isValidNumberForRegion.test.js.map +1 -1
- package/es6/legacy/isValidNumberForRegion_.js +1 -1
- package/es6/legacy/isValidNumberForRegion_.js.map +1 -1
- package/es6/legacy/parse.js +3 -4
- package/es6/legacy/parse.js.map +1 -1
- package/es6/legacy/parse.test.js +232 -190
- package/es6/legacy/parse.test.js.map +1 -1
- package/es6/legacy/searchNumbers.js +8 -8
- package/es6/legacy/searchNumbers.js.map +1 -1
- package/es6/legacy/searchNumbers.test.js +6 -11
- package/es6/legacy/searchNumbers.test.js.map +1 -1
- package/es6/metadata.js +86 -114
- package/es6/metadata.js.map +1 -1
- package/es6/metadata.test.js +57 -73
- package/es6/metadata.test.js.map +1 -1
- package/es6/normalizeArguments.js +26 -32
- package/es6/normalizeArguments.js.map +1 -1
- package/es6/parse.js +66 -94
- package/es6/parse.js.map +1 -1
- package/es6/parse.test.js +243 -202
- package/es6/parse.test.js.map +1 -1
- package/es6/parseIncompletePhoneNumber.js +9 -16
- package/es6/parseIncompletePhoneNumber.js.map +1 -1
- package/es6/parseIncompletePhoneNumber.test.js +22 -18
- package/es6/parseIncompletePhoneNumber.test.js.map +1 -1
- package/es6/parsePhoneNumber.js +3 -4
- package/es6/parsePhoneNumber.js.map +1 -1
- package/es6/parsePhoneNumber.test.js +14 -23
- package/es6/parsePhoneNumber.test.js.map +1 -1
- package/es6/parsePhoneNumberWithError.js +3 -4
- package/es6/parsePhoneNumberWithError.js.map +1 -1
- package/es6/parsePhoneNumberWithError.test.js +31 -32
- package/es6/parsePhoneNumberWithError.test.js.map +1 -1
- package/es6/parsePhoneNumberWithError_.js +6 -6
- package/es6/parsePhoneNumberWithError_.js.map +1 -1
- package/es6/parsePhoneNumber_.js +10 -10
- package/es6/parsePhoneNumber_.js.map +1 -1
- package/es6/searchPhoneNumbersInText.js +9 -11
- package/es6/searchPhoneNumbersInText.js.map +1 -1
- package/es6/searchPhoneNumbersInText.test.js +11 -18
- package/es6/searchPhoneNumbersInText.test.js.map +1 -1
- package/es6/tools/semver-compare.js +0 -3
- 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/validatePhoneNumberLength.js +11 -12
- package/es6/validatePhoneNumberLength.js.map +1 -1
- package/es6/validatePhoneNumberLength.test.js +14 -14
- package/es6/validatePhoneNumberLength.test.js.map +1 -1
- package/jest.config.json +26 -0
- package/max/metadata/metadata.max.json +1 -0
- package/max/metadata/metadata.max.json.d.cts +4 -0
- package/max/metadata/metadata.max.json.d.ts +4 -0
- package/max/metadata/metadata.max.json.js +4 -0
- package/max/metadata/package.json +6 -6
- package/metadata.full.json +1 -1
- package/metadata.full.json.js +1 -1
- package/metadata.max.json +1 -1
- package/metadata.max.json.js +1 -1
- package/metadata.min.json +1 -1
- package/metadata.min.json.js +1 -1
- package/metadata.mobile.json +1 -1
- package/metadata.mobile.json.js +1 -1
- package/min/metadata/metadata.min.json +1 -0
- package/min/metadata/metadata.min.json.d.cts +4 -0
- package/min/metadata/metadata.min.json.d.ts +4 -0
- package/min/metadata/metadata.min.json.js +4 -0
- package/min/metadata/package.json +6 -6
- package/mobile/examples/examples.mobile.json +1 -0
- package/mobile/examples/examples.mobile.json.d.cts +4 -0
- package/mobile/examples/examples.mobile.json.d.ts +4 -0
- package/mobile/examples/examples.mobile.json.js +4 -0
- package/mobile/examples/package.json +6 -6
- package/mobile/metadata/metadata.mobile.json +1 -0
- package/mobile/metadata/metadata.mobile.json.d.cts +4 -0
- package/mobile/metadata/metadata.mobile.json.d.ts +4 -0
- package/mobile/metadata/metadata.mobile.json.js +4 -0
- package/mobile/metadata/package.json +6 -6
- package/package.json +43 -27
- package/rollup.config.mjs +2 -2
- package/runnable/generate-country-codes.js +1 -1
- package/source/AsYouType.test.js +414 -414
- package/source/AsYouTypeFormatter.PatternMatcher.test.js +91 -91
- package/source/AsYouTypeFormatter.PatternParser.test.js +6 -6
- package/source/AsYouTypeFormatter.util.test.js +6 -6
- package/source/PhoneNumber.test.js +34 -29
- package/source/PhoneNumberMatcher.js +8 -9
- package/source/PhoneNumberMatcher.test.js +18 -6
- package/source/findNumbers/Leniency.js +0 -1
- package/source/findNumbers/util.test.js +14 -19
- package/source/findPhoneNumbersInText.test.js +98 -53
- package/source/format.test.js +70 -65
- package/source/formatIncompletePhoneNumber.test.js +11 -7
- package/source/formatPhoneNumberForMobileDialing.js +16 -1
- package/source/getCountries.test.js +2 -2
- package/source/getCountryCallingCode.test.js +2 -2
- package/source/getExampleNumber.test.js +6 -6
- package/source/helpers/RFC3966.test.js +8 -8
- package/source/helpers/applyInternationalSeparatorStyle.test.js +2 -2
- package/source/helpers/checkNumberLength.test.js +11 -11
- package/source/helpers/extractCountryCallingCode.test.js +4 -4
- package/source/helpers/extractNationalNumber.test.js +2 -2
- package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -2
- package/source/helpers/extractPhoneContext.test.js +1 -1
- package/source/helpers/getNumberType.test.js +4 -4
- package/source/helpers/matchesEntirely.test.js +2 -2
- package/source/helpers/mergeArrays.test.js +1 -1
- package/source/helpers/parseDigits.test.js +1 -1
- package/source/helpers/stripIddPrefix.test.js +4 -4
- package/source/isPossible.test.js +16 -10
- package/source/isPossiblePhoneNumber.test.js +12 -13
- package/source/isValid.test.js +20 -20
- package/source/isValidPhoneNumber.test.js +9 -9
- package/source/legacy/findNumbers.test.js +57 -44
- package/source/legacy/findPhoneNumbers.test.js +51 -35
- package/source/legacy/format.test.js +74 -71
- package/source/legacy/getNumberType.test.js +20 -18
- package/source/legacy/isPossibleNumber.test.js +16 -10
- package/source/legacy/isValidNumber.test.js +25 -23
- package/source/legacy/isValidNumberForRegion.test.js +5 -5
- package/source/legacy/parse.test.js +113 -116
- package/source/legacy/searchNumbers.test.js +3 -3
- package/source/metadata.test.js +61 -49
- package/source/parse.test.js +115 -118
- package/source/parseIncompletePhoneNumber.test.js +13 -13
- package/source/parsePhoneNumber.test.js +14 -14
- package/source/parsePhoneNumberWithError.test.js +25 -25
- package/source/searchPhoneNumbersInText.test.js +8 -8
- package/source/tools/semver-compare.test.js +1 -1
- package/source/validatePhoneNumberLength.test.js +10 -10
- package/build/findNumbers/Leniency.test.js +0 -37
- package/build/findNumbers/Leniency.test.js.map +0 -1
- package/build/formatPhoneNumberForMobileDialing.test.js +0 -15
- package/build/formatPhoneNumberForMobileDialing.test.js.map +0 -1
- package/es6/findNumbers/Leniency.test.js +0 -36
- package/es6/findNumbers/Leniency.test.js.map +0 -1
- package/es6/formatPhoneNumberForMobileDialing.test.js +0 -14
- package/es6/formatPhoneNumberForMobileDialing.test.js.map +0 -1
- package/source/findNumbers/Leniency.test.js +0 -35
- package/source/formatPhoneNumberForMobileDialing.test.js +0 -16
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -12,71 +10,61 @@ Object.defineProperty(exports, "DIGIT_PLACEHOLDER", {
|
|
|
12
10
|
}
|
|
13
11
|
});
|
|
14
12
|
exports["default"] = void 0;
|
|
15
|
-
|
|
16
13
|
var _AsYouTypeFormatterUtil = require("./AsYouTypeFormatter.util.js");
|
|
17
|
-
|
|
18
14
|
var _AsYouTypeFormatterComplete = _interopRequireWildcard(require("./AsYouTypeFormatter.complete.js"));
|
|
19
|
-
|
|
20
15
|
var _AsYouTypeFormatterPatternMatcher = _interopRequireDefault(require("./AsYouTypeFormatter.PatternMatcher.js"));
|
|
21
|
-
|
|
22
16
|
var _parseDigits = _interopRequireDefault(require("./helpers/parseDigits.js"));
|
|
23
|
-
|
|
24
17
|
var _formatNationalNumberUsingFormat = require("./helpers/formatNationalNumberUsingFormat.js");
|
|
25
|
-
|
|
26
18
|
var _constants = require("./constants.js");
|
|
27
|
-
|
|
28
19
|
var _applyInternationalSeparatorStyle = _interopRequireDefault(require("./helpers/applyInternationalSeparatorStyle.js"));
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
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; }
|
|
41
|
-
|
|
42
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
43
|
-
|
|
44
|
-
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); } }
|
|
45
|
-
|
|
46
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
47
|
-
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
21
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
22
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
23
|
+
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
24
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
25
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
26
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
27
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
28
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
29
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
30
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
48
31
|
// Used in phone number format template creation.
|
|
49
32
|
// Could be any digit, I guess.
|
|
50
|
-
var DUMMY_DIGIT = '9';
|
|
51
|
-
|
|
52
|
-
var LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15;
|
|
33
|
+
var DUMMY_DIGIT = '9';
|
|
34
|
+
// I don't know why is it exactly `15`
|
|
35
|
+
var LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15;
|
|
36
|
+
// Create a phone number consisting only of the digit 9 that matches the
|
|
53
37
|
// `number_pattern` by applying the pattern to the "longest phone number" string.
|
|
38
|
+
var LONGEST_DUMMY_PHONE_NUMBER = (0, _AsYouTypeFormatterUtil.repeat)(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH);
|
|
54
39
|
|
|
55
|
-
|
|
40
|
+
// A set of characters that, if found in a national prefix formatting rules, are an indicator to
|
|
56
41
|
// us that we should separate the national prefix from the number when formatting.
|
|
42
|
+
var NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/;
|
|
57
43
|
|
|
58
|
-
|
|
44
|
+
// Deprecated: Google has removed some formatting pattern related code from their repo.
|
|
59
45
|
// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c
|
|
60
46
|
// "We no longer have numbers in formatting matching patterns, only \d."
|
|
61
47
|
// Because this library supports generating custom metadata
|
|
62
48
|
// some users may still be using old metadata so the relevant
|
|
63
49
|
// code seems to stay until some next major version update.
|
|
50
|
+
var SUPPORT_LEGACY_FORMATTING_PATTERNS = true;
|
|
64
51
|
|
|
65
|
-
|
|
52
|
+
// A pattern that is used to match character classes in regular expressions.
|
|
66
53
|
// An example of a character class is "[1-4]".
|
|
67
|
-
|
|
68
54
|
var CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && function () {
|
|
69
55
|
return /\[([^\[\]])*\]/g;
|
|
70
|
-
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Any digit in a regular expression that actually denotes a digit. For
|
|
71
59
|
// example, in the regular expression "80[0-2]\d{6,10}", the first 2 digits
|
|
72
60
|
// (8 and 0) are standalone digits, but the rest are not.
|
|
73
61
|
// Two look-aheads are needed because the number following \\d could be a
|
|
74
62
|
// two-digit number, since the phone number can be as long as 15 digits.
|
|
75
|
-
|
|
76
|
-
|
|
77
63
|
var CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && function () {
|
|
78
64
|
return /\d(?=[^,}][^,}])/g;
|
|
79
|
-
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// A regular expression that is used to determine if a `format` is
|
|
80
68
|
// suitable to be used in the "as you type formatter".
|
|
81
69
|
// A `format` is suitable when the resulting formatted number has
|
|
82
70
|
// the same digits as the user has entered.
|
|
@@ -110,29 +98,25 @@ var CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && func
|
|
|
110
98
|
// This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's
|
|
111
99
|
// `libphonenumber` code.
|
|
112
100
|
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var NON_ALTERING_FORMAT_REG_EXP = new RegExp('[' + _constants.VALID_PUNCTUATION + ']*' + // Google developers say:
|
|
101
|
+
var NON_ALTERING_FORMAT_REG_EXP = new RegExp('[' + _constants.VALID_PUNCTUATION + ']*' +
|
|
102
|
+
// Google developers say:
|
|
116
103
|
// "We require that the first matching group is present in the
|
|
117
104
|
// output pattern to ensure no data is lost while formatting."
|
|
118
|
-
'\\$1' + '[' + _constants.VALID_PUNCTUATION + ']*' + '(\\$\\d[' + _constants.VALID_PUNCTUATION + ']*)*' + '$');
|
|
105
|
+
'\\$1' + '[' + _constants.VALID_PUNCTUATION + ']*' + '(\\$\\d[' + _constants.VALID_PUNCTUATION + ']*)*' + '$');
|
|
106
|
+
|
|
107
|
+
// This is the minimum length of the leading digits of a phone number
|
|
119
108
|
// to guarantee the first "leading digits pattern" for a phone number format
|
|
120
109
|
// to be preemptive.
|
|
121
|
-
|
|
122
110
|
var MIN_LEADING_DIGITS_LENGTH = 3;
|
|
123
|
-
|
|
124
|
-
var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
111
|
+
var AsYouTypeFormatter = exports["default"] = /*#__PURE__*/function () {
|
|
125
112
|
function AsYouTypeFormatter(_ref) {
|
|
126
113
|
var state = _ref.state,
|
|
127
|
-
|
|
128
|
-
|
|
114
|
+
metadata = _ref.metadata;
|
|
129
115
|
_classCallCheck(this, AsYouTypeFormatter);
|
|
130
|
-
|
|
131
116
|
this.metadata = metadata;
|
|
132
117
|
this.resetFormat();
|
|
133
118
|
}
|
|
134
|
-
|
|
135
|
-
_createClass(AsYouTypeFormatter, [{
|
|
119
|
+
return _createClass(AsYouTypeFormatter, [{
|
|
136
120
|
key: "resetFormat",
|
|
137
121
|
value: function resetFormat() {
|
|
138
122
|
this.chosenFormat = undefined;
|
|
@@ -145,11 +129,9 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
145
129
|
key: "reset",
|
|
146
130
|
value: function reset(numberingPlan, state) {
|
|
147
131
|
this.resetFormat();
|
|
148
|
-
|
|
149
132
|
if (numberingPlan) {
|
|
150
133
|
this.isNANP = numberingPlan.callingCode() === '1';
|
|
151
134
|
this.matchingFormats = numberingPlan.formats();
|
|
152
|
-
|
|
153
135
|
if (state.nationalSignificantNumber) {
|
|
154
136
|
this.narrowDownMatchingFormats(state);
|
|
155
137
|
}
|
|
@@ -158,18 +140,17 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
158
140
|
this.matchingFormats = [];
|
|
159
141
|
}
|
|
160
142
|
}
|
|
143
|
+
|
|
161
144
|
/**
|
|
162
145
|
* Formats an updated phone number.
|
|
163
146
|
* @param {string} nextDigits — Additional phone number digits.
|
|
164
147
|
* @param {object} state — `AsYouType` state.
|
|
165
148
|
* @return {[string]} Returns undefined if the updated phone number can't be formatted using any of the available formats.
|
|
166
149
|
*/
|
|
167
|
-
|
|
168
150
|
}, {
|
|
169
151
|
key: "format",
|
|
170
152
|
value: function format(nextDigits, state) {
|
|
171
153
|
var _this = this;
|
|
172
|
-
|
|
173
154
|
// See if the phone number digits can be formatted as a complete phone number.
|
|
174
155
|
// If not, use the results from `formatNationalNumberWithNextDigits()`,
|
|
175
156
|
// which formats based on the chosen formatting pattern.
|
|
@@ -186,8 +167,8 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
186
167
|
//
|
|
187
168
|
if ((0, _AsYouTypeFormatterComplete.canFormatCompleteNumber)(state.nationalSignificantNumber, this.metadata)) {
|
|
188
169
|
for (var _iterator = _createForOfIteratorHelperLoose(this.matchingFormats), _step; !(_step = _iterator()).done;) {
|
|
189
|
-
var
|
|
190
|
-
var formattedCompleteNumber = (0, _AsYouTypeFormatterComplete["default"])(state,
|
|
170
|
+
var _format = _step.value;
|
|
171
|
+
var formattedCompleteNumber = (0, _AsYouTypeFormatterComplete["default"])(state, _format, {
|
|
191
172
|
metadata: this.metadata,
|
|
192
173
|
shouldTryNationalPrefixFormattingRule: function shouldTryNationalPrefixFormattingRule(format) {
|
|
193
174
|
return _this.shouldTryNationalPrefixFormattingRule(format, {
|
|
@@ -199,32 +180,31 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
199
180
|
return _this.getSeparatorAfterNationalPrefix(format);
|
|
200
181
|
}
|
|
201
182
|
});
|
|
202
|
-
|
|
203
183
|
if (formattedCompleteNumber) {
|
|
204
184
|
this.resetFormat();
|
|
205
|
-
this.chosenFormat =
|
|
185
|
+
this.chosenFormat = _format;
|
|
206
186
|
this.setNationalNumberTemplate(formattedCompleteNumber.replace(/\d/g, _AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER), state);
|
|
207
|
-
this.populatedNationalNumberTemplate = formattedCompleteNumber;
|
|
187
|
+
this.populatedNationalNumberTemplate = formattedCompleteNumber;
|
|
188
|
+
// With a new formatting template, the matched position
|
|
208
189
|
// using the old template needs to be reset.
|
|
209
|
-
|
|
210
190
|
this.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(_AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER);
|
|
211
191
|
return formattedCompleteNumber;
|
|
212
192
|
}
|
|
213
193
|
}
|
|
214
|
-
}
|
|
194
|
+
}
|
|
195
|
+
// Format the digits as a partial (incomplete) phone number
|
|
215
196
|
// using the previously chosen formatting pattern (or a newly chosen one).
|
|
216
|
-
|
|
217
|
-
|
|
218
197
|
return this.formatNationalNumberWithNextDigits(nextDigits, state);
|
|
219
|
-
}
|
|
198
|
+
}
|
|
220
199
|
|
|
200
|
+
// Formats the next phone number digits.
|
|
221
201
|
}, {
|
|
222
202
|
key: "formatNationalNumberWithNextDigits",
|
|
223
203
|
value: function formatNationalNumberWithNextDigits(nextDigits, state) {
|
|
224
|
-
var previouslyChosenFormat = this.chosenFormat;
|
|
204
|
+
var previouslyChosenFormat = this.chosenFormat;
|
|
225
205
|
|
|
206
|
+
// Choose a format from the list of matching ones.
|
|
226
207
|
var newlyChosenFormat = this.chooseFormat(state);
|
|
227
|
-
|
|
228
208
|
if (newlyChosenFormat) {
|
|
229
209
|
if (newlyChosenFormat === previouslyChosenFormat) {
|
|
230
210
|
// If it can format the next (current) digits
|
|
@@ -244,38 +224,38 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
244
224
|
key: "narrowDownMatchingFormats",
|
|
245
225
|
value: function narrowDownMatchingFormats(_ref2) {
|
|
246
226
|
var _this2 = this;
|
|
247
|
-
|
|
248
227
|
var nationalSignificantNumber = _ref2.nationalSignificantNumber,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
var leadingDigits = nationalSignificantNumber;
|
|
228
|
+
nationalPrefix = _ref2.nationalPrefix,
|
|
229
|
+
international = _ref2.international;
|
|
230
|
+
var leadingDigits = nationalSignificantNumber;
|
|
231
|
+
|
|
232
|
+
// "leading digits" pattern list starts with a
|
|
252
233
|
// "leading digits" pattern fitting a maximum of 3 leading digits.
|
|
253
234
|
// So, after a user inputs 3 digits of a national (significant) phone number
|
|
254
235
|
// this national (significant) number can already be formatted.
|
|
255
236
|
// The next "leading digits" pattern is for 4 leading digits max,
|
|
256
237
|
// and the "leading digits" pattern after it is for 5 leading digits max, etc.
|
|
238
|
+
|
|
257
239
|
// This implementation is different from Google's
|
|
258
240
|
// in that it searches for a fitting format
|
|
259
241
|
// even if the user has entered less than
|
|
260
242
|
// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.
|
|
261
243
|
// Because some leading digit patterns already match for a single first digit.
|
|
262
|
-
|
|
263
244
|
var leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH;
|
|
264
|
-
|
|
265
245
|
if (leadingDigitsPatternIndex < 0) {
|
|
266
246
|
leadingDigitsPatternIndex = 0;
|
|
267
247
|
}
|
|
268
|
-
|
|
269
248
|
this.matchingFormats = this.matchingFormats.filter(function (format) {
|
|
270
249
|
return _this2.formatSuits(format, international, nationalPrefix) && _this2.formatMatches(format, leadingDigits, leadingDigitsPatternIndex);
|
|
271
|
-
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// If there was a phone number format chosen
|
|
272
253
|
// and it no longer holds given the new leading digits then reset it.
|
|
273
254
|
// The test for this `if` condition is marked as:
|
|
274
255
|
// "Reset a chosen format when it no longer holds given the new leading digits".
|
|
275
256
|
// To construct a valid test case for this one can find a country
|
|
276
257
|
// in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`
|
|
277
258
|
// and yielding another format for 4 `<leadingDigits>` (Australia in this case).
|
|
278
|
-
|
|
279
259
|
if (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {
|
|
280
260
|
this.resetFormat();
|
|
281
261
|
}
|
|
@@ -293,39 +273,42 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
293
273
|
// and was extracted, then discard such phone number format.
|
|
294
274
|
// In Google's "AsYouType" formatter code, the equivalent would be this part:
|
|
295
275
|
// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184
|
|
296
|
-
if (nationalPrefix && !format.usesNationalPrefix() &&
|
|
276
|
+
if (nationalPrefix && !format.usesNationalPrefix() &&
|
|
277
|
+
// !format.domesticCarrierCodeFormattingRule() &&
|
|
297
278
|
!format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {
|
|
298
279
|
return false;
|
|
299
|
-
}
|
|
280
|
+
}
|
|
281
|
+
// If national prefix is mandatory for this phone number format
|
|
300
282
|
// and there're no guarantees that a national prefix is present in user input
|
|
301
283
|
// then discard this phone number format as not suitable.
|
|
302
284
|
// In Google's "AsYouType" formatter code, the equivalent would be this part:
|
|
303
285
|
// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193
|
|
304
|
-
|
|
305
|
-
|
|
306
286
|
if (!international && !nationalPrefix && format.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {
|
|
307
287
|
return false;
|
|
308
288
|
}
|
|
309
|
-
|
|
310
289
|
return true;
|
|
311
290
|
}
|
|
312
291
|
}, {
|
|
313
292
|
key: "formatMatches",
|
|
314
293
|
value: function formatMatches(format, leadingDigits, leadingDigitsPatternIndex) {
|
|
315
|
-
var leadingDigitsPatternsCount = format.leadingDigitsPatterns().length;
|
|
294
|
+
var leadingDigitsPatternsCount = format.leadingDigitsPatterns().length;
|
|
295
|
+
|
|
296
|
+
// If this format is not restricted to a certain
|
|
316
297
|
// leading digits pattern then it fits.
|
|
317
298
|
// The test case could be found by searching for "leadingDigitsPatternsCount === 0".
|
|
318
|
-
|
|
319
299
|
if (leadingDigitsPatternsCount === 0) {
|
|
320
300
|
return true;
|
|
321
|
-
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Start narrowing down the list of possible formats based on the leading digits.
|
|
322
304
|
// (only previously matched formats take part in the narrowing down process)
|
|
305
|
+
|
|
323
306
|
// `leading_digits_patterns` start with 3 digits min
|
|
324
307
|
// and then go up from there one digit at a time.
|
|
325
|
-
|
|
326
|
-
|
|
327
308
|
leadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1);
|
|
328
|
-
var leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex];
|
|
309
|
+
var leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex];
|
|
310
|
+
|
|
311
|
+
// Google imposes a requirement on the leading digits
|
|
329
312
|
// to be minimum 3 digits long in order to be eligible
|
|
330
313
|
// for checking those with a leading digits pattern.
|
|
331
314
|
//
|
|
@@ -350,7 +333,6 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
350
333
|
// even when there's only 1 or 2 digits of the national (significant) number.
|
|
351
334
|
// To do that, it uses a non-strict pattern matcher written specifically for that.
|
|
352
335
|
//
|
|
353
|
-
|
|
354
336
|
if (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {
|
|
355
337
|
// Before leading digits < 3 matching was implemented:
|
|
356
338
|
// return true
|
|
@@ -360,9 +342,7 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
360
342
|
return new _AsYouTypeFormatterPatternMatcher["default"](leadingDigitsPattern).match(leadingDigits, {
|
|
361
343
|
allowOverflow: true
|
|
362
344
|
}) !== undefined;
|
|
363
|
-
} catch (error)
|
|
364
|
-
/* istanbul ignore next */
|
|
365
|
-
{
|
|
345
|
+
} catch (error) /* istanbul ignore next */{
|
|
366
346
|
// There's a slight possibility that there could be some undiscovered bug
|
|
367
347
|
// in the pattern matcher code. Since the "leading digits < 3 matching"
|
|
368
348
|
// feature is not "essential" for operation, it can fall back to the old way
|
|
@@ -370,14 +350,14 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
370
350
|
console.error(error);
|
|
371
351
|
return true;
|
|
372
352
|
}
|
|
373
|
-
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are
|
|
374
356
|
// available then use the usual regular expression matching.
|
|
375
357
|
//
|
|
376
358
|
// The whole pattern is wrapped in round brackets (`()`) because
|
|
377
359
|
// the pattern can use "or" operator (`|`) at the top level of the pattern.
|
|
378
360
|
//
|
|
379
|
-
|
|
380
|
-
|
|
381
361
|
return new RegExp("^(".concat(leadingDigitsPattern, ")")).test(leadingDigits);
|
|
382
362
|
}
|
|
383
363
|
}, {
|
|
@@ -389,72 +369,66 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
389
369
|
key: "chooseFormat",
|
|
390
370
|
value: function chooseFormat(state) {
|
|
391
371
|
var _this3 = this;
|
|
392
|
-
|
|
393
372
|
var _loop = function _loop() {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
_this3.chosenFormat = format;
|
|
455
|
-
return "break";
|
|
456
|
-
};
|
|
457
|
-
|
|
373
|
+
var format = _step2.value;
|
|
374
|
+
// If this format is currently being used
|
|
375
|
+
// and is still suitable, then stick to it.
|
|
376
|
+
if (_this3.chosenFormat === format) {
|
|
377
|
+
return 0; // break
|
|
378
|
+
}
|
|
379
|
+
// Sometimes, a formatting rule inserts additional digits in a phone number,
|
|
380
|
+
// and "as you type" formatter can't do that: it should only use the digits
|
|
381
|
+
// that the user has input.
|
|
382
|
+
//
|
|
383
|
+
// For example, in Argentina, there's a format for mobile phone numbers:
|
|
384
|
+
//
|
|
385
|
+
// {
|
|
386
|
+
// "pattern": "(\\d)(\\d{2})(\\d{4})(\\d{4})",
|
|
387
|
+
// "leading_digits_patterns": ["91"],
|
|
388
|
+
// "national_prefix_formatting_rule": "0$1",
|
|
389
|
+
// "format": "$2 15-$3-$4",
|
|
390
|
+
// "international_format": "$1 $2 $3-$4"
|
|
391
|
+
// }
|
|
392
|
+
//
|
|
393
|
+
// In that format, `international_format` is used instead of `format`
|
|
394
|
+
// because `format` inserts `15` in the formatted number,
|
|
395
|
+
// and `AsYouType` formatter should only use the digits
|
|
396
|
+
// the user has actually input, without adding any extra digits.
|
|
397
|
+
// In this case, it wouldn't make a difference, because the `15`
|
|
398
|
+
// is first stripped when applying `national_prefix_for_parsing`
|
|
399
|
+
// and then re-added when using `format`, so in reality it doesn't
|
|
400
|
+
// add any new digits to the number, but to detect that, the code
|
|
401
|
+
// would have to be more complex: it would have to try formatting
|
|
402
|
+
// the digits using the format and then see if any digits have
|
|
403
|
+
// actually been added or removed, and then, every time a new digit
|
|
404
|
+
// is input, it should re-check whether the chosen format doesn't
|
|
405
|
+
// alter the digits.
|
|
406
|
+
//
|
|
407
|
+
// Google's code doesn't go that far, and so does this library:
|
|
408
|
+
// it simply requires that a `format` doesn't add any additonal
|
|
409
|
+
// digits to user's input.
|
|
410
|
+
//
|
|
411
|
+
// Also, people in general should move from inputting phone numbers
|
|
412
|
+
// in national format (possibly with national prefixes)
|
|
413
|
+
// and use international phone number format instead:
|
|
414
|
+
// it's a logical thing in the modern age of mobile phones,
|
|
415
|
+
// globalization and the internet.
|
|
416
|
+
//
|
|
417
|
+
/* istanbul ignore if */
|
|
418
|
+
if (!NON_ALTERING_FORMAT_REG_EXP.test(_this3.getFormatFormat(format, state.international))) {
|
|
419
|
+
return 1; // continue
|
|
420
|
+
}
|
|
421
|
+
if (!_this3.createTemplateForFormat(format, state)) {
|
|
422
|
+
// Remove the format if it can't generate a template.
|
|
423
|
+
_this3.matchingFormats = _this3.matchingFormats.filter(function (_) {
|
|
424
|
+
return _ !== format;
|
|
425
|
+
});
|
|
426
|
+
return 1; // continue
|
|
427
|
+
}
|
|
428
|
+
_this3.chosenFormat = format;
|
|
429
|
+
return 0; // break
|
|
430
|
+
},
|
|
431
|
+
_ret;
|
|
458
432
|
// When there are multiple available formats, the formatter uses the first
|
|
459
433
|
// format where a formatting template could be created.
|
|
460
434
|
//
|
|
@@ -469,20 +443,16 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
469
443
|
// It doesn't skip the contents of the `for of` loop,
|
|
470
444
|
// it just skips the `for of` line.
|
|
471
445
|
//
|
|
472
|
-
|
|
473
446
|
/* istanbul ignore next */
|
|
474
447
|
for (var _iterator2 = _createForOfIteratorHelperLoose(this.matchingFormats.slice()), _step2; !(_step2 = _iterator2()).done;) {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (_ret ===
|
|
478
|
-
if (_ret === "continue") continue;
|
|
448
|
+
_ret = _loop();
|
|
449
|
+
if (_ret === 0) break;
|
|
450
|
+
if (_ret === 1) continue;
|
|
479
451
|
}
|
|
480
|
-
|
|
481
452
|
if (!this.chosenFormat) {
|
|
482
453
|
// No format matches the national (significant) phone number.
|
|
483
454
|
this.resetFormat();
|
|
484
455
|
}
|
|
485
|
-
|
|
486
456
|
return this.chosenFormat;
|
|
487
457
|
}
|
|
488
458
|
}, {
|
|
@@ -491,16 +461,14 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
491
461
|
// The formatter doesn't format numbers when numberPattern contains '|', e.g.
|
|
492
462
|
// (20|3)\d{4}. In those cases we quickly return.
|
|
493
463
|
// (Though there's no such format in current metadata)
|
|
494
|
-
|
|
495
464
|
/* istanbul ignore if */
|
|
496
465
|
if (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {
|
|
497
466
|
return;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
467
|
+
}
|
|
468
|
+
// Get formatting template for this phone number format
|
|
469
|
+
var template = this.getTemplateForFormat(format, state);
|
|
470
|
+
// If the national number entered is too long
|
|
502
471
|
// for any phone number format, then abort.
|
|
503
|
-
|
|
504
472
|
if (template) {
|
|
505
473
|
this.setNationalNumberTemplate(template, state);
|
|
506
474
|
return true;
|
|
@@ -516,35 +484,30 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
516
484
|
// So `US` national prefix separator is a "special" "hardcoded" case.
|
|
517
485
|
if (this.isNANP) {
|
|
518
486
|
return ' ';
|
|
519
|
-
}
|
|
487
|
+
}
|
|
488
|
+
// If a `format` has a `national_prefix_formatting_rule`
|
|
520
489
|
// and that rule has a separator after a national prefix,
|
|
521
490
|
// then it means that there should be a separator
|
|
522
491
|
// between a national prefix and a national (significant) number.
|
|
523
|
-
|
|
524
|
-
|
|
525
492
|
if (format && format.nationalPrefixFormattingRule() && NATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {
|
|
526
493
|
return ' ';
|
|
527
|
-
}
|
|
494
|
+
}
|
|
495
|
+
// At this point, there seems to be no clear evidence that
|
|
528
496
|
// there should be a separator between a national prefix
|
|
529
497
|
// and a national (significant) number. So don't insert one.
|
|
530
|
-
|
|
531
|
-
|
|
532
498
|
return '';
|
|
533
499
|
}
|
|
534
500
|
}, {
|
|
535
501
|
key: "getInternationalPrefixBeforeCountryCallingCode",
|
|
536
502
|
value: function getInternationalPrefixBeforeCountryCallingCode(_ref3, options) {
|
|
537
503
|
var IDDPrefix = _ref3.IDDPrefix,
|
|
538
|
-
|
|
539
|
-
|
|
504
|
+
missingPlus = _ref3.missingPlus;
|
|
540
505
|
if (IDDPrefix) {
|
|
541
506
|
return options && options.spacing === false ? IDDPrefix : IDDPrefix + ' ';
|
|
542
507
|
}
|
|
543
|
-
|
|
544
508
|
if (missingPlus) {
|
|
545
509
|
return '';
|
|
546
510
|
}
|
|
547
|
-
|
|
548
511
|
return '+';
|
|
549
512
|
}
|
|
550
513
|
}, {
|
|
@@ -552,43 +515,41 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
552
515
|
value: function getTemplate(state) {
|
|
553
516
|
if (!this.template) {
|
|
554
517
|
return;
|
|
555
|
-
}
|
|
518
|
+
}
|
|
519
|
+
// `this.template` holds the template for a "complete" phone number.
|
|
556
520
|
// The currently entered phone number is most likely not "complete",
|
|
557
521
|
// so trim all non-populated digits.
|
|
558
|
-
|
|
559
|
-
|
|
560
522
|
var index = -1;
|
|
561
523
|
var i = 0;
|
|
562
524
|
var internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, {
|
|
563
525
|
spacing: false
|
|
564
526
|
}) : '';
|
|
565
|
-
|
|
566
527
|
while (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {
|
|
567
528
|
index = this.template.indexOf(_AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER, index + 1);
|
|
568
529
|
i++;
|
|
569
530
|
}
|
|
570
|
-
|
|
571
531
|
return (0, _AsYouTypeFormatterUtil.cutAndStripNonPairedParens)(this.template, index + 1);
|
|
572
532
|
}
|
|
573
533
|
}, {
|
|
574
534
|
key: "setNationalNumberTemplate",
|
|
575
535
|
value: function setNationalNumberTemplate(template, state) {
|
|
576
536
|
this.nationalNumberTemplate = template;
|
|
577
|
-
this.populatedNationalNumberTemplate = template;
|
|
537
|
+
this.populatedNationalNumberTemplate = template;
|
|
538
|
+
// With a new formatting template, the matched position
|
|
578
539
|
// using the old template needs to be reset.
|
|
579
|
-
|
|
580
|
-
|
|
540
|
+
this.populatedNationalNumberTemplatePosition = -1;
|
|
541
|
+
// For convenience, the public `.template` property
|
|
581
542
|
// contains the whole international number
|
|
582
543
|
// if the phone number being input is international:
|
|
583
544
|
// 'x' for the '+' sign, 'x'es for the country phone code,
|
|
584
545
|
// a spacebar and then the template for the formatted national number.
|
|
585
|
-
|
|
586
546
|
if (state.international) {
|
|
587
547
|
this.template = this.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\d\+]/g, _AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER) + (0, _AsYouTypeFormatterUtil.repeat)(_AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER, state.callingCode.length) + ' ' + template;
|
|
588
548
|
} else {
|
|
589
549
|
this.template = template;
|
|
590
550
|
}
|
|
591
551
|
}
|
|
552
|
+
|
|
592
553
|
/**
|
|
593
554
|
* Generates formatting template for a national phone number,
|
|
594
555
|
* optionally containing a national prefix, for a format.
|
|
@@ -596,22 +557,25 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
596
557
|
* @param {string} nationalPrefix
|
|
597
558
|
* @return {string}
|
|
598
559
|
*/
|
|
599
|
-
|
|
600
560
|
}, {
|
|
601
561
|
key: "getTemplateForFormat",
|
|
602
562
|
value: function getTemplateForFormat(format, _ref4) {
|
|
603
563
|
var nationalSignificantNumber = _ref4.nationalSignificantNumber,
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
564
|
+
international = _ref4.international,
|
|
565
|
+
nationalPrefix = _ref4.nationalPrefix,
|
|
566
|
+
complexPrefixBeforeNationalSignificantNumber = _ref4.complexPrefixBeforeNationalSignificantNumber;
|
|
607
567
|
var pattern = format.pattern();
|
|
608
|
-
/* istanbul ignore else */
|
|
609
568
|
|
|
569
|
+
/* istanbul ignore else */
|
|
610
570
|
if (SUPPORT_LEGACY_FORMATTING_PATTERNS) {
|
|
611
|
-
pattern = pattern
|
|
612
|
-
|
|
571
|
+
pattern = pattern
|
|
572
|
+
// Replace anything in the form of [..] with \d
|
|
573
|
+
.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\d')
|
|
574
|
+
// Replace any standalone digit (not the one in `{}`) with \d
|
|
613
575
|
.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\d');
|
|
614
|
-
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// Generate a dummy national number (consisting of `9`s)
|
|
615
579
|
// that fits this format's `pattern`.
|
|
616
580
|
//
|
|
617
581
|
// This match will always succeed,
|
|
@@ -619,15 +583,17 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
619
583
|
// has enough length to accomodate any possible
|
|
620
584
|
// national phone number format pattern.
|
|
621
585
|
//
|
|
586
|
+
var digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0];
|
|
622
587
|
|
|
623
|
-
|
|
624
|
-
var digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]; // If the national number entered is too long
|
|
588
|
+
// If the national number entered is too long
|
|
625
589
|
// for any phone number format, then abort.
|
|
626
|
-
|
|
627
590
|
if (nationalSignificantNumber.length > digits.length) {
|
|
628
591
|
return;
|
|
629
|
-
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// Get a formatting template which can be used to efficiently format
|
|
630
595
|
// a partial number where digits are added one by one.
|
|
596
|
+
|
|
631
597
|
// Below `strictPattern` is used for the
|
|
632
598
|
// regular expression (with `^` and `$`).
|
|
633
599
|
// This wasn't originally in Google's `libphonenumber`
|
|
@@ -656,63 +622,64 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
656
622
|
// to satisfy the `pattern` completely then `this.nationalSignificantNumber`
|
|
657
623
|
// is used instead of `digits`.
|
|
658
624
|
|
|
659
|
-
|
|
660
625
|
var strictPattern = new RegExp('^' + pattern + '$');
|
|
661
|
-
var nationalNumberDummyDigits = nationalSignificantNumber.replace(/\d/g, DUMMY_DIGIT);
|
|
626
|
+
var nationalNumberDummyDigits = nationalSignificantNumber.replace(/\d/g, DUMMY_DIGIT);
|
|
627
|
+
|
|
628
|
+
// If `this.nationalSignificantNumber` has already sufficient length
|
|
662
629
|
// to satisfy the `pattern` completely then use it
|
|
663
630
|
// instead of `digits`.
|
|
664
|
-
|
|
665
631
|
if (strictPattern.test(nationalNumberDummyDigits)) {
|
|
666
632
|
digits = nationalNumberDummyDigits;
|
|
667
633
|
}
|
|
668
|
-
|
|
669
634
|
var numberFormat = this.getFormatFormat(format, international);
|
|
670
|
-
var nationalPrefixIncludedInTemplate;
|
|
635
|
+
var nationalPrefixIncludedInTemplate;
|
|
636
|
+
|
|
637
|
+
// If a user did input a national prefix (and that's guaranteed),
|
|
671
638
|
// and if a `format` does have a national prefix formatting rule,
|
|
672
639
|
// then see if that national prefix formatting rule
|
|
673
640
|
// prepends exactly the same national prefix the user has input.
|
|
674
641
|
// If that's the case, then use the `format` with the national prefix formatting rule.
|
|
675
642
|
// Otherwise, use the `format` without the national prefix formatting rule,
|
|
676
643
|
// and prepend a national prefix manually to it.
|
|
677
|
-
|
|
678
644
|
if (this.shouldTryNationalPrefixFormattingRule(format, {
|
|
679
645
|
international: international,
|
|
680
646
|
nationalPrefix: nationalPrefix
|
|
681
647
|
})) {
|
|
682
|
-
var numberFormatWithNationalPrefix = numberFormat.replace(_formatNationalNumberUsingFormat.FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule());
|
|
648
|
+
var numberFormatWithNationalPrefix = numberFormat.replace(_formatNationalNumberUsingFormat.FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule());
|
|
649
|
+
// If `national_prefix_formatting_rule` of a `format` simply prepends
|
|
683
650
|
// national prefix at the start of a national (significant) number,
|
|
684
651
|
// then such formatting can be used with `AsYouType` formatter.
|
|
685
652
|
// There seems to be no `else` case: everywhere in metadata,
|
|
686
653
|
// national prefix formatting rule is national prefix + $1,
|
|
687
654
|
// or `($1)`, in which case such format isn't even considered
|
|
688
655
|
// when the user has input a national prefix.
|
|
689
|
-
|
|
690
656
|
/* istanbul ignore else */
|
|
691
|
-
|
|
692
657
|
if ((0, _parseDigits["default"])(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + (0, _parseDigits["default"])('$1')) {
|
|
693
658
|
numberFormat = numberFormatWithNationalPrefix;
|
|
694
|
-
nationalPrefixIncludedInTemplate = true;
|
|
659
|
+
nationalPrefixIncludedInTemplate = true;
|
|
660
|
+
// Replace all digits of the national prefix in the formatting template
|
|
695
661
|
// with `DIGIT_PLACEHOLDER`s.
|
|
696
|
-
|
|
697
662
|
if (nationalPrefix) {
|
|
698
663
|
var i = nationalPrefix.length;
|
|
699
|
-
|
|
700
664
|
while (i > 0) {
|
|
701
665
|
numberFormat = numberFormat.replace(/\d/, _AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER);
|
|
702
666
|
i--;
|
|
703
667
|
}
|
|
704
668
|
}
|
|
705
669
|
}
|
|
706
|
-
}
|
|
670
|
+
}
|
|
707
671
|
|
|
672
|
+
// Generate formatting template for this phone number format.
|
|
673
|
+
var template = digits
|
|
674
|
+
// Format the dummy phone number according to the format.
|
|
675
|
+
.replace(new RegExp(pattern), numberFormat)
|
|
676
|
+
// Replace each dummy digit with a DIGIT_PLACEHOLDER.
|
|
677
|
+
.replace(new RegExp(DUMMY_DIGIT, 'g'), _AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER);
|
|
708
678
|
|
|
709
|
-
|
|
710
|
-
.replace(new RegExp(pattern), numberFormat) // Replace each dummy digit with a DIGIT_PLACEHOLDER.
|
|
711
|
-
.replace(new RegExp(DUMMY_DIGIT, 'g'), _AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER); // If a prefix of a national (significant) number is not as simple
|
|
679
|
+
// If a prefix of a national (significant) number is not as simple
|
|
712
680
|
// as just a basic national prefix, then just prepend such prefix
|
|
713
681
|
// before the national (significant) number, optionally spacing
|
|
714
682
|
// the two with a whitespace.
|
|
715
|
-
|
|
716
683
|
if (!nationalPrefixIncludedInTemplate) {
|
|
717
684
|
if (complexPrefixBeforeNationalSignificantNumber) {
|
|
718
685
|
// Prepend the prefix to the template manually.
|
|
@@ -722,28 +689,27 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
722
689
|
template = (0, _AsYouTypeFormatterUtil.repeat)(_AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER, nationalPrefix.length) + this.getSeparatorAfterNationalPrefix(format) + template;
|
|
723
690
|
}
|
|
724
691
|
}
|
|
725
|
-
|
|
726
692
|
if (international) {
|
|
727
693
|
template = (0, _applyInternationalSeparatorStyle["default"])(template);
|
|
728
694
|
}
|
|
729
|
-
|
|
730
695
|
return template;
|
|
731
696
|
}
|
|
732
697
|
}, {
|
|
733
698
|
key: "formatNextNationalNumberDigits",
|
|
734
699
|
value: function formatNextNationalNumberDigits(digits) {
|
|
735
700
|
var result = (0, _AsYouTypeFormatterUtil.populateTemplateWithDigits)(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition, digits);
|
|
736
|
-
|
|
737
701
|
if (!result) {
|
|
738
702
|
// Reset the format.
|
|
739
703
|
this.resetFormat();
|
|
740
704
|
return;
|
|
741
705
|
}
|
|
742
|
-
|
|
743
706
|
this.populatedNationalNumberTemplate = result[0];
|
|
744
|
-
this.populatedNationalNumberTemplatePosition = result[1];
|
|
707
|
+
this.populatedNationalNumberTemplatePosition = result[1];
|
|
708
|
+
|
|
709
|
+
// Return the formatted phone number so far.
|
|
710
|
+
return (0, _AsYouTypeFormatterUtil.cutAndStripNonPairedParens)(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1);
|
|
745
711
|
|
|
746
|
-
|
|
712
|
+
// The old way which was good for `input-format` but is not so good
|
|
747
713
|
// for `react-phone-number-input`'s default input (`InputBasic`).
|
|
748
714
|
// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)
|
|
749
715
|
// .replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')
|
|
@@ -752,23 +718,17 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
|
|
|
752
718
|
key: "shouldTryNationalPrefixFormattingRule",
|
|
753
719
|
value: function shouldTryNationalPrefixFormattingRule(format, _ref5) {
|
|
754
720
|
var international = _ref5.international,
|
|
755
|
-
|
|
756
|
-
|
|
721
|
+
nationalPrefix = _ref5.nationalPrefix;
|
|
757
722
|
if (format.nationalPrefixFormattingRule()) {
|
|
758
723
|
// In some countries, `national_prefix_formatting_rule` is `($1)`,
|
|
759
724
|
// so it applies even if the user hasn't input a national prefix.
|
|
760
725
|
// `format.usesNationalPrefix()` detects such cases.
|
|
761
726
|
var usesNationalPrefix = format.usesNationalPrefix();
|
|
762
|
-
|
|
763
727
|
if (usesNationalPrefix && nationalPrefix || !usesNationalPrefix && !international) {
|
|
764
728
|
return true;
|
|
765
729
|
}
|
|
766
730
|
}
|
|
767
731
|
}
|
|
768
732
|
}]);
|
|
769
|
-
|
|
770
|
-
return AsYouTypeFormatter;
|
|
771
733
|
}();
|
|
772
|
-
|
|
773
|
-
exports["default"] = AsYouTypeFormatter;
|
|
774
734
|
//# sourceMappingURL=AsYouTypeFormatter.js.map
|