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