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
package/es6/AsYouType.test.js
CHANGED
|
@@ -1,287 +1,312 @@
|
|
|
1
|
-
function _typeof(
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
16
|
-
|
|
17
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
18
|
-
|
|
19
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
|
-
|
|
21
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
|
-
|
|
23
|
-
import metadata from '../metadata.min.json' assert { type: 'json' };
|
|
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 _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); } }
|
|
3
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
5
|
+
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); }
|
|
6
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
7
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
8
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
9
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
10
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
11
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
12
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
13
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
14
|
+
import metadata from '../metadata.min.json' with { type: 'json' };
|
|
24
15
|
import AsYouType_ from './AsYouType.js';
|
|
25
|
-
|
|
26
16
|
var AsYouType = /*#__PURE__*/function (_AsYouType_) {
|
|
27
|
-
_inherits(AsYouType, _AsYouType_);
|
|
28
|
-
|
|
29
|
-
var _super = _createSuper(AsYouType);
|
|
30
|
-
|
|
31
17
|
function AsYouType(country_code) {
|
|
32
18
|
_classCallCheck(this, AsYouType);
|
|
33
|
-
|
|
34
|
-
return _super.call(this, country_code, metadata);
|
|
19
|
+
return _callSuper(this, AsYouType, [country_code, metadata]);
|
|
35
20
|
}
|
|
36
|
-
|
|
21
|
+
_inherits(AsYouType, _AsYouType_);
|
|
37
22
|
return _createClass(AsYouType);
|
|
38
23
|
}(AsYouType_);
|
|
39
|
-
|
|
40
24
|
var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
|
|
41
25
|
describe('AsYouType', function () {
|
|
42
26
|
it('should use "national_prefix_formatting_rule"', function () {
|
|
43
27
|
// With national prefix (full).
|
|
44
|
-
new AsYouType('RU').input('88005553535').
|
|
45
|
-
|
|
46
|
-
new AsYouType('RU').input('880055535').
|
|
28
|
+
expect(new AsYouType('RU').input('88005553535')).to.equal('8 (800) 555-35-35');
|
|
29
|
+
// With national prefix (partial).
|
|
30
|
+
expect(new AsYouType('RU').input('880055535')).to.equal('8 (800) 555-35');
|
|
47
31
|
});
|
|
48
32
|
it('should populate national number template (digit by digit)', function () {
|
|
49
33
|
var formatter = new AsYouType('US');
|
|
50
|
-
formatter.input('1');
|
|
51
|
-
|
|
52
|
-
formatter.formatter.template.
|
|
53
|
-
|
|
54
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
34
|
+
formatter.input('1');
|
|
35
|
+
// formatter.formatter.template.should.equal('x (xxx) xxx-xxxx')
|
|
36
|
+
expect(formatter.formatter.template).to.equal('x xxx-xxxx');
|
|
37
|
+
// formatter.formatter.populatedNationalNumberTemplate.should.equal('1 (xxx) xxx-xxxx')
|
|
38
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 xxx-xxxx');
|
|
55
39
|
formatter.input('213');
|
|
56
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
40
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 (213) xxx-xxxx');
|
|
57
41
|
formatter.input('3734253');
|
|
58
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
42
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 (213) 373-4253');
|
|
59
43
|
});
|
|
60
44
|
it('should populate international number template (digit by digit) (default country)', function () {
|
|
61
45
|
var formatter = new AsYouType('US');
|
|
62
46
|
expect(formatter.formatter.template).to.be.undefined;
|
|
63
47
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined;
|
|
64
|
-
formatter.input('').
|
|
48
|
+
expect(formatter.input('')).to.equal('');
|
|
65
49
|
expect(formatter.formatter.template).to.be.undefined;
|
|
66
50
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined;
|
|
67
|
-
formatter.input('+').
|
|
68
|
-
formatter.getTemplate().
|
|
51
|
+
expect(formatter.input('+')).to.equal('+');
|
|
52
|
+
expect(formatter.getTemplate()).to.equal('x');
|
|
69
53
|
expect(formatter.formatter.template).to.be.undefined;
|
|
70
54
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined;
|
|
71
|
-
formatter.input('1').
|
|
72
|
-
formatter.getTemplate().
|
|
55
|
+
expect(formatter.input('1')).to.equal('+1');
|
|
56
|
+
expect(formatter.getTemplate()).to.equal('xx');
|
|
57
|
+
// Hasn't started formatting the phone number using the template yet.
|
|
73
58
|
// formatter.formatter.template.should.equal('xx xxx xxx xxxx')
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
59
|
+
expect(formatter.formatter.template).to.equal('xx xxx xxxx');
|
|
60
|
+
// formatter.formatter.populatedNationalNumberTemplate.should.equal('xxx xxx xxxx')
|
|
61
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('xxx xxxx');
|
|
62
|
+
// Has some national number digits, starts formatting the phone number using the template.
|
|
79
63
|
formatter.input('213');
|
|
80
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
64
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 xxx xxxx');
|
|
81
65
|
formatter.input('3734253');
|
|
82
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
66
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 373 4253');
|
|
83
67
|
});
|
|
84
68
|
it('should populate international number template (digit by digit)', function () {
|
|
85
69
|
var formatter = new AsYouType();
|
|
86
70
|
expect(formatter.formatter.template).to.be.undefined;
|
|
87
71
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined;
|
|
88
|
-
formatter.input('').
|
|
72
|
+
expect(formatter.input('')).to.equal('');
|
|
89
73
|
expect(formatter.formatter.template).to.be.undefined;
|
|
90
74
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined;
|
|
91
|
-
formatter.input('+').
|
|
75
|
+
expect(formatter.input('+')).to.equal('+');
|
|
92
76
|
expect(formatter.formatter.template).to.be.undefined;
|
|
93
77
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined;
|
|
94
|
-
formatter.input('1').
|
|
95
|
-
|
|
96
|
-
formatter.formatter.template.
|
|
78
|
+
expect(formatter.input('1')).to.equal('+1');
|
|
79
|
+
// formatter.formatter.template.should.equal('xx xxx xxx xxxx')
|
|
80
|
+
expect(formatter.formatter.template).to.equal('xx xxx xxxx');
|
|
81
|
+
// Hasn't yet started formatting the phone number using the template.
|
|
97
82
|
// formatter.formatter.populatedNationalNumberTemplate.should.equal('xxx xxx xxxx')
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
83
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('xxx xxxx');
|
|
84
|
+
// Has some national number digits, starts formatting the phone number using the template.
|
|
101
85
|
formatter.input('213');
|
|
102
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
86
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 xxx xxxx');
|
|
103
87
|
formatter.input('3734253');
|
|
104
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
88
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 373 4253');
|
|
105
89
|
});
|
|
106
90
|
it('should populate national number template (attempt to format complete number)', function () {
|
|
107
91
|
var formatter = new AsYouType('US');
|
|
108
|
-
formatter.input('12133734253').
|
|
109
|
-
formatter.formatter.template.
|
|
110
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
92
|
+
expect(formatter.input('12133734253')).to.equal('1 (213) 373-4253');
|
|
93
|
+
expect(formatter.formatter.template).to.equal('x (xxx) xxx-xxxx');
|
|
94
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 (213) 373-4253');
|
|
111
95
|
});
|
|
112
96
|
it('should parse and format phone numbers as you type', function () {
|
|
113
97
|
// International number test
|
|
114
|
-
new AsYouType().input('+12133734').
|
|
98
|
+
expect(new AsYouType().input('+12133734')).to.equal('+1 213 373 4');
|
|
99
|
+
// Local number test
|
|
100
|
+
expect(new AsYouType('US').input('2133734')).to.equal('(213) 373-4');
|
|
115
101
|
|
|
116
|
-
|
|
102
|
+
// US national number retains national prefix.
|
|
103
|
+
expect(new AsYouType('US').input('12133734')).to.equal('1 (213) 373-4');
|
|
117
104
|
|
|
118
|
-
|
|
105
|
+
// US national number retains national prefix (full number).
|
|
106
|
+
expect(new AsYouType('US').input('12133734253')).to.equal('1 (213) 373-4253');
|
|
107
|
+
var formatter;
|
|
119
108
|
|
|
120
|
-
|
|
121
|
-
var formatter; // // Should discard national prefix from a "complete" phone number.
|
|
109
|
+
// // Should discard national prefix from a "complete" phone number.
|
|
122
110
|
// new AsYouType('RU').input('8800555353').should.equal('880 055-53-53')
|
|
111
|
+
|
|
123
112
|
// Shouldn't extract national prefix when inputting in international format.
|
|
113
|
+
expect(new AsYouType('RU').input('+7800555353')).to.equal('+7 800 555 35 3');
|
|
114
|
+
expect(new AsYouType('CH').input('044-668-1')).to.equal('044 668 1');
|
|
124
115
|
|
|
125
|
-
|
|
126
|
-
new AsYouType('CH').input('044-668-1').should.equal('044 668 1'); // Test International phone number (international)
|
|
127
|
-
|
|
128
|
-
formatter = new AsYouType(); // formatter.valid.should.be.false
|
|
129
|
-
|
|
130
|
-
type(formatter.getCountry()).should.equal('undefined');
|
|
131
|
-
type(formatter.getCountryCallingCode()).should.equal('undefined');
|
|
132
|
-
formatter.getTemplate().should.equal('');
|
|
133
|
-
formatter.input('+').should.equal('+'); // formatter.valid.should.be.false
|
|
134
|
-
|
|
135
|
-
type(formatter.getCountry()).should.equal('undefined');
|
|
136
|
-
type(formatter.getCountryCallingCode()).should.equal('undefined');
|
|
137
|
-
formatter.getTemplate().should.equal('x');
|
|
138
|
-
formatter.input('1').should.equal('+1'); // formatter.valid.should.be.false
|
|
139
|
-
|
|
140
|
-
type(formatter.getCountry()).should.equal('undefined');
|
|
141
|
-
formatter.getCountryCallingCode().should.equal('1');
|
|
142
|
-
formatter.getTemplate().should.equal('xx');
|
|
143
|
-
formatter.input('2').should.equal('+1 2');
|
|
144
|
-
formatter.getTemplate().should.equal('xx x'); // formatter.valid.should.be.false
|
|
145
|
-
|
|
146
|
-
type(formatter.getCountry()).should.equal('undefined');
|
|
147
|
-
formatter.input('1').should.equal('+1 21');
|
|
148
|
-
formatter.input('3').should.equal('+1 213');
|
|
149
|
-
formatter.input(' ').should.equal('+1 213');
|
|
150
|
-
formatter.input('3').should.equal('+1 213 3');
|
|
151
|
-
formatter.input('3').should.equal('+1 213 33');
|
|
152
|
-
formatter.input('3').should.equal('+1 213 333');
|
|
153
|
-
formatter.input('4').should.equal('+1 213 333 4');
|
|
154
|
-
formatter.input('4').should.equal('+1 213 333 44');
|
|
155
|
-
formatter.input('4').should.equal('+1 213 333 444'); // formatter.valid.should.be.false
|
|
156
|
-
|
|
157
|
-
type(formatter.getCountry()).should.equal('undefined');
|
|
158
|
-
formatter.input('4').should.equal('+1 213 333 4444'); // formatter.valid.should.be.true
|
|
159
|
-
|
|
160
|
-
formatter.getCountry().should.equal('US'); // This one below contains "punctuation spaces"
|
|
161
|
-
// along with the regular spaces
|
|
116
|
+
// Test International phone number (international)
|
|
162
117
|
|
|
163
|
-
formatter
|
|
164
|
-
formatter.input('5').should.equal('+1 21333344445'); // formatter.valid.should.be.false
|
|
118
|
+
formatter = new AsYouType();
|
|
165
119
|
|
|
120
|
+
// formatter.valid.should.be.false
|
|
121
|
+
expect(type(formatter.getCountry())).to.equal('undefined');
|
|
122
|
+
expect(type(formatter.getCountryCallingCode())).to.equal('undefined');
|
|
123
|
+
expect(formatter.getTemplate()).to.equal('');
|
|
124
|
+
expect(formatter.input('+')).to.equal('+');
|
|
125
|
+
|
|
126
|
+
// formatter.valid.should.be.false
|
|
127
|
+
expect(type(formatter.getCountry())).to.equal('undefined');
|
|
128
|
+
expect(type(formatter.getCountryCallingCode())).to.equal('undefined');
|
|
129
|
+
expect(formatter.getTemplate()).to.equal('x');
|
|
130
|
+
expect(formatter.input('1')).to.equal('+1');
|
|
131
|
+
|
|
132
|
+
// formatter.valid.should.be.false
|
|
133
|
+
expect(type(formatter.getCountry())).to.equal('undefined');
|
|
134
|
+
expect(formatter.getCountryCallingCode()).to.equal('1');
|
|
135
|
+
expect(formatter.getTemplate()).to.equal('xx');
|
|
136
|
+
expect(formatter.input('2')).to.equal('+1 2');
|
|
137
|
+
expect(formatter.getTemplate()).to.equal('xx x');
|
|
138
|
+
|
|
139
|
+
// formatter.valid.should.be.false
|
|
140
|
+
expect(type(formatter.getCountry())).to.equal('undefined');
|
|
141
|
+
expect(formatter.input('1')).to.equal('+1 21');
|
|
142
|
+
expect(formatter.input('3')).to.equal('+1 213');
|
|
143
|
+
expect(formatter.input(' ')).to.equal('+1 213');
|
|
144
|
+
expect(formatter.input('3')).to.equal('+1 213 3');
|
|
145
|
+
expect(formatter.input('3')).to.equal('+1 213 33');
|
|
146
|
+
expect(formatter.input('3')).to.equal('+1 213 333');
|
|
147
|
+
expect(formatter.input('4')).to.equal('+1 213 333 4');
|
|
148
|
+
expect(formatter.input('4')).to.equal('+1 213 333 44');
|
|
149
|
+
expect(formatter.input('4')).to.equal('+1 213 333 444');
|
|
150
|
+
|
|
151
|
+
// formatter.valid.should.be.false
|
|
152
|
+
expect(type(formatter.getCountry())).to.equal('undefined');
|
|
153
|
+
expect(formatter.input('4')).to.equal('+1 213 333 4444');
|
|
154
|
+
|
|
155
|
+
// formatter.valid.should.be.true
|
|
156
|
+
expect(formatter.getCountry()).to.equal('US');
|
|
157
|
+
// This one below contains "punctuation spaces"
|
|
158
|
+
// along with the regular spaces
|
|
159
|
+
expect(formatter.getTemplate()).to.equal('xx xxx xxx xxxx');
|
|
160
|
+
expect(formatter.input('5')).to.equal('+1 21333344445');
|
|
161
|
+
|
|
162
|
+
// formatter.valid.should.be.false
|
|
166
163
|
expect(formatter.getCountry()).to.be.undefined;
|
|
167
|
-
formatter.getCountryCallingCode().
|
|
168
|
-
expect(formatter.formatter.template).to.be.undefined;
|
|
164
|
+
expect(formatter.getCountryCallingCode()).to.equal('1');
|
|
165
|
+
expect(formatter.formatter.template).to.be.undefined;
|
|
166
|
+
|
|
167
|
+
// Check that clearing an international formatter
|
|
169
168
|
// also clears country metadata.
|
|
170
169
|
|
|
171
170
|
formatter.reset();
|
|
172
|
-
formatter.input('+').
|
|
173
|
-
formatter.input('7').
|
|
174
|
-
formatter.input('9').
|
|
175
|
-
formatter.input('99 111 22 33').
|
|
171
|
+
expect(formatter.input('+')).to.equal('+');
|
|
172
|
+
expect(formatter.input('7')).to.equal('+7');
|
|
173
|
+
expect(formatter.input('9')).to.equal('+7 9');
|
|
174
|
+
expect(formatter.input('99 111 22 33')).to.equal('+7 999 111 22 33');
|
|
175
|
+
|
|
176
|
+
// Test Switzerland phone numbers
|
|
176
177
|
|
|
177
178
|
formatter = new AsYouType('CH');
|
|
178
|
-
formatter.input(' ').
|
|
179
|
-
formatter.input('0').
|
|
180
|
-
formatter.input('4').
|
|
181
|
-
formatter.input(' ').
|
|
182
|
-
formatter.input('-').
|
|
183
|
-
formatter.input('4').
|
|
184
|
-
formatter.input('-').
|
|
185
|
-
formatter.input('6').
|
|
186
|
-
formatter.input('6').
|
|
187
|
-
formatter.input('8').
|
|
188
|
-
formatter.input('-').
|
|
189
|
-
formatter.input('1').
|
|
190
|
-
formatter.input('8').
|
|
191
|
-
|
|
192
|
-
formatter.
|
|
193
|
-
formatter.
|
|
194
|
-
formatter.
|
|
195
|
-
formatter.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
formatter.
|
|
199
|
-
formatter.
|
|
200
|
-
|
|
201
|
-
formatter.
|
|
202
|
-
|
|
179
|
+
expect(formatter.input(' ')).to.equal('');
|
|
180
|
+
expect(formatter.input('0')).to.equal('0');
|
|
181
|
+
expect(formatter.input('4')).to.equal('04');
|
|
182
|
+
expect(formatter.input(' ')).to.equal('04');
|
|
183
|
+
expect(formatter.input('-')).to.equal('04');
|
|
184
|
+
expect(formatter.input('4')).to.equal('044');
|
|
185
|
+
expect(formatter.input('-')).to.equal('044');
|
|
186
|
+
expect(formatter.input('6')).to.equal('044 6');
|
|
187
|
+
expect(formatter.input('6')).to.equal('044 66');
|
|
188
|
+
expect(formatter.input('8')).to.equal('044 668');
|
|
189
|
+
expect(formatter.input('-')).to.equal('044 668');
|
|
190
|
+
expect(formatter.input('1')).to.equal('044 668 1');
|
|
191
|
+
expect(formatter.input('8')).to.equal('044 668 18');
|
|
192
|
+
|
|
193
|
+
// formatter.valid.should.be.false
|
|
194
|
+
expect(formatter.getCountry()).to.equal('CH');
|
|
195
|
+
expect(formatter.formatter.template).to.equal('xxx xxx xx xx');
|
|
196
|
+
expect(formatter.getTemplate()).to.equal('xxx xxx xx');
|
|
197
|
+
expect(formatter.input(' 00')).to.equal('044 668 18 00');
|
|
198
|
+
|
|
199
|
+
// formatter.valid.should.be.true
|
|
200
|
+
expect(formatter.getCountry()).to.equal('CH');
|
|
201
|
+
expect(formatter.getTemplate()).to.equal('xxx xxx xx xx');
|
|
202
|
+
expect(formatter.input('9')).to.equal('04466818009');
|
|
203
|
+
|
|
204
|
+
// formatter.valid.should.be.false
|
|
205
|
+
expect(formatter.getCountry()).to.equal('CH');
|
|
206
|
+
expect(formatter.formatter.template).to.be.undefined;
|
|
207
|
+
|
|
208
|
+
// Kazakhstan (non-main country for +7 country phone code)
|
|
203
209
|
|
|
204
210
|
formatter = new AsYouType();
|
|
205
211
|
formatter.input('+77172580659');
|
|
206
|
-
formatter.getCountry().
|
|
212
|
+
expect(formatter.getCountry()).to.equal('KZ');
|
|
213
|
+
|
|
214
|
+
// Brazil
|
|
207
215
|
|
|
208
216
|
formatter = new AsYouType('BR');
|
|
209
|
-
formatter.input('11987654321').
|
|
217
|
+
expect(formatter.input('11987654321')).to.equal('(11) 98765-4321');
|
|
218
|
+
|
|
219
|
+
// UK (Jersey) (non-main country for +44 country phone code)
|
|
210
220
|
|
|
211
221
|
formatter = new AsYouType();
|
|
212
|
-
formatter.input('+447700300000').
|
|
213
|
-
formatter.getTemplate().
|
|
214
|
-
formatter.getCountry().
|
|
222
|
+
expect(formatter.input('+447700300000')).to.equal('+44 7700 300000');
|
|
223
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx xxxxxx');
|
|
224
|
+
expect(formatter.getCountry()).to.equal('JE');
|
|
215
225
|
|
|
226
|
+
// Braces must be part of the template.
|
|
216
227
|
formatter = new AsYouType('RU');
|
|
217
|
-
formatter.input('88005553535').
|
|
218
|
-
formatter.getTemplate().
|
|
228
|
+
expect(formatter.input('88005553535')).to.equal('8 (800) 555-35-35');
|
|
229
|
+
expect(formatter.getTemplate()).to.equal('x (xxx) xxx-xx-xx');
|
|
230
|
+
|
|
231
|
+
// Test Russian phone numbers
|
|
219
232
|
// (with optional national prefix `8`)
|
|
220
233
|
|
|
221
234
|
formatter = new AsYouType('RU');
|
|
222
|
-
formatter.input('8').
|
|
223
|
-
formatter.input('9').
|
|
224
|
-
formatter.input('9').
|
|
225
|
-
formatter.input('9').
|
|
226
|
-
formatter.input('-').
|
|
227
|
-
formatter.input('1234').
|
|
228
|
-
formatter.input('567').
|
|
229
|
-
formatter.input('8').
|
|
235
|
+
expect(formatter.input('8')).to.equal('8');
|
|
236
|
+
expect(formatter.input('9')).to.equal('8 9');
|
|
237
|
+
expect(formatter.input('9')).to.equal('8 99');
|
|
238
|
+
expect(formatter.input('9')).to.equal('8 (999)');
|
|
239
|
+
expect(formatter.input('-')).to.equal('8 (999)');
|
|
240
|
+
expect(formatter.input('1234')).to.equal('8 (999) 123-4');
|
|
241
|
+
expect(formatter.input('567')).to.equal('8 (999) 123-45-67');
|
|
242
|
+
expect(formatter.input('8')).to.equal('899912345678');
|
|
243
|
+
|
|
244
|
+
// Shouldn't strip national prefix if it is optional
|
|
230
245
|
// and if it's a valid phone number (international).
|
|
246
|
+
formatter = new AsYouType('RU');
|
|
247
|
+
// formatter.input('8005553535').should.equal('(800) 555-35-35')
|
|
248
|
+
expect(formatter.input('+78005553535')).to.equal('+7 800 555 35 35');
|
|
249
|
+
expect(formatter.getNationalNumber()).to.equal('8005553535');
|
|
231
250
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
formatter.input('+78005553535').should.equal('+7 800 555 35 35');
|
|
235
|
-
formatter.getNationalNumber().should.equal('8005553535'); // Check that clearing an national formatter:
|
|
251
|
+
// Check that clearing an national formatter:
|
|
236
252
|
// * doesn't clear country metadata
|
|
237
253
|
// * clears all other things
|
|
238
254
|
|
|
239
255
|
formatter.reset();
|
|
240
|
-
formatter.input('8').
|
|
241
|
-
formatter.input('9').
|
|
242
|
-
formatter.input('9').
|
|
243
|
-
formatter.input('9').
|
|
244
|
-
formatter.input('-').
|
|
245
|
-
formatter.input('1234').
|
|
246
|
-
formatter.input('567').
|
|
247
|
-
formatter.input('8').
|
|
256
|
+
expect(formatter.input('8')).to.equal('8');
|
|
257
|
+
expect(formatter.input('9')).to.equal('8 9');
|
|
258
|
+
expect(formatter.input('9')).to.equal('8 99');
|
|
259
|
+
expect(formatter.input('9')).to.equal('8 (999)');
|
|
260
|
+
expect(formatter.input('-')).to.equal('8 (999)');
|
|
261
|
+
expect(formatter.input('1234')).to.equal('8 (999) 123-4');
|
|
262
|
+
expect(formatter.input('567')).to.equal('8 (999) 123-45-67');
|
|
263
|
+
expect(formatter.input('8')).to.equal('899912345678');
|
|
264
|
+
|
|
265
|
+
// National prefix should not be prepended
|
|
248
266
|
// when formatting local NANPA phone numbers.
|
|
267
|
+
expect(new AsYouType('US').input('1')).to.equal('1');
|
|
268
|
+
expect(new AsYouType('US').input('12')).to.equal('1 2');
|
|
269
|
+
expect(new AsYouType('US').input('123')).to.equal('1 23');
|
|
249
270
|
|
|
250
|
-
|
|
251
|
-
new AsYouType('US').input('12').should.equal('1 2');
|
|
252
|
-
new AsYouType('US').input('123').should.equal('1 23'); // Bulgaria
|
|
271
|
+
// Bulgaria
|
|
253
272
|
// (should not prepend national prefix `0`)
|
|
273
|
+
expect(new AsYouType('BG').input('111 222 3')).to.equal('1112223');
|
|
254
274
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
new AsYouType().input('+4915539898001').should.equal('+49 15539 898001'); // KZ detection
|
|
275
|
+
// Deutchland
|
|
276
|
+
expect(new AsYouType().input('+4915539898001')).to.equal('+49 15539 898001');
|
|
258
277
|
|
|
278
|
+
// KZ detection
|
|
259
279
|
formatter = new AsYouType();
|
|
260
280
|
formatter.input('+7 702 211 1111');
|
|
261
|
-
formatter.getCountry().
|
|
262
|
-
//
|
|
281
|
+
expect(formatter.getCountry()).to.equal('KZ');
|
|
282
|
+
// formatter.valid.should.equal(true)
|
|
263
283
|
|
|
264
|
-
|
|
284
|
+
// New Zealand formatting fix (issue #89)
|
|
285
|
+
expect(new AsYouType('NZ').input('0212')).to.equal('021 2');
|
|
265
286
|
|
|
287
|
+
// South Korea
|
|
266
288
|
formatter = new AsYouType();
|
|
267
|
-
formatter.input('+82111111111').
|
|
268
|
-
formatter.getTemplate().
|
|
289
|
+
expect(formatter.input('+82111111111')).to.equal('+82 11 111 1111');
|
|
290
|
+
expect(formatter.getTemplate()).to.equal('xxx xx xxx xxxx');
|
|
269
291
|
});
|
|
270
292
|
it('should filter out formats that require a national prefix and no national prefix has been input', function () {
|
|
271
293
|
// Afghanistan.
|
|
272
|
-
var formatter = new AsYouType('AF');
|
|
273
|
-
// (not `"national_prefix_is_optional_when_formatting": true`)
|
|
294
|
+
var formatter = new AsYouType('AF');
|
|
274
295
|
|
|
275
|
-
|
|
276
|
-
|
|
296
|
+
// No national prefix, and national prefix is required in the format.
|
|
297
|
+
// (not `"national_prefix_is_optional_when_formatting": true`)
|
|
298
|
+
expect(formatter.input('44444444')).to.equal('44444444');
|
|
299
|
+
expect(formatter.formatter.template).to.be.undefined;
|
|
277
300
|
|
|
278
|
-
|
|
279
|
-
formatter.
|
|
301
|
+
// With national prefix
|
|
302
|
+
expect(formatter.reset().input('044444444')).to.equal('044 444 444');
|
|
303
|
+
expect(formatter.formatter.template).to.equal('xxx xxx xxxx');
|
|
280
304
|
});
|
|
281
305
|
it('should work when a digit is not a national prefix but a part of a valid national number', function () {
|
|
282
306
|
// In Russia, `8` could be both a valid national prefix
|
|
283
307
|
// and a part of a valid national number.
|
|
284
|
-
var formatter = new AsYouType('RU');
|
|
308
|
+
var formatter = new AsYouType('RU');
|
|
309
|
+
// The formatter could try both variants:
|
|
285
310
|
// with extracting national prefix
|
|
286
311
|
// and without extracting it,
|
|
287
312
|
// and then choose whichever way has `this.matchingFormats`.
|
|
@@ -296,39 +321,40 @@ describe('AsYouType', function () {
|
|
|
296
321
|
// in Russia, people are used to inputting `800` numbers with national prefix `8`:
|
|
297
322
|
// `8 800 555 35 35`.
|
|
298
323
|
// formatter.input('8005553535').should.equal('(800) 555-35-35')
|
|
299
|
-
|
|
300
|
-
formatter.input('8005553535').should.equal('8005553535');
|
|
324
|
+
expect(formatter.input('8005553535')).to.equal('8005553535');
|
|
301
325
|
formatter.reset();
|
|
302
|
-
formatter.input('+78005553535').
|
|
326
|
+
expect(formatter.input('+78005553535')).to.equal('+7 800 555 35 35');
|
|
303
327
|
});
|
|
304
328
|
it('should match formats that require a national prefix and no national prefix has been input (national prefix is mandatory for a format)', function () {
|
|
305
329
|
var formatter = new AsYouType('FR');
|
|
306
|
-
formatter.input('612345678').
|
|
330
|
+
expect(formatter.input('612345678')).to.equal('612345678');
|
|
307
331
|
formatter.reset();
|
|
308
|
-
formatter.input('0612345678').
|
|
332
|
+
expect(formatter.input('0612345678')).to.equal('06 12 34 56 78');
|
|
309
333
|
});
|
|
310
334
|
it('should match formats that require a national prefix and no national prefix has been input (national prefix is not mandatory for a format)', function () {
|
|
311
|
-
var formatter = new AsYouType('RU');
|
|
312
|
-
|
|
313
|
-
formatter.input('9991234567').
|
|
314
|
-
formatter.reset();
|
|
315
|
-
|
|
316
|
-
formatter.input('89991234567').
|
|
335
|
+
var formatter = new AsYouType('RU');
|
|
336
|
+
// Without national prefix.
|
|
337
|
+
expect(formatter.input('9991234567')).to.equal('999 123-45-67');
|
|
338
|
+
formatter.reset();
|
|
339
|
+
// With national prefix.
|
|
340
|
+
expect(formatter.input('89991234567')).to.equal('8 (999) 123-45-67');
|
|
317
341
|
});
|
|
318
342
|
it('should not use `national_prefix_formatting_rule` when formatting international phone numbers', function () {
|
|
319
343
|
// Brazil.
|
|
320
344
|
// `national_prefix_formatting_rule` is `($1)`.
|
|
321
345
|
// Should not add braces around `12` when being input in international format.
|
|
322
|
-
new AsYouType().input('+55123456789').
|
|
323
|
-
new AsYouType('BR').input('+55123456789').
|
|
324
|
-
new AsYouType('BR').input('123456789').
|
|
346
|
+
expect(new AsYouType().input('+55123456789')).to.equal('+55 12 3456 789');
|
|
347
|
+
expect(new AsYouType('BR').input('+55123456789')).to.equal('+55 12 3456 789');
|
|
348
|
+
expect(new AsYouType('BR').input('123456789')).to.equal('(12) 3456-789');
|
|
325
349
|
});
|
|
326
350
|
it('should support incorrectly entered international phone numbers (with a national prefix)', function () {
|
|
327
351
|
var formatter;
|
|
328
352
|
formatter = new AsYouType();
|
|
329
|
-
formatter.input('+1 1 877 215 5230').
|
|
353
|
+
expect(formatter.input('+1 1 877 215 5230')).to.equal('+1 1 877 215 5230');
|
|
354
|
+
// formatter.input('+1 1 877 215 5230').should.equal('+1 1 8772155230')
|
|
355
|
+
expect(formatter.getNationalNumber()).to.equal('8772155230');
|
|
330
356
|
|
|
331
|
-
|
|
357
|
+
// They've added another number format that has `8` leading digit
|
|
332
358
|
// and 14 digits. Maybe it's something related to Kazakhstan.
|
|
333
359
|
// formatter = new AsYouType()
|
|
334
360
|
// formatter.input('+78800555353').should.equal('+7 880 055 53 53')
|
|
@@ -337,96 +363,122 @@ describe('AsYouType', function () {
|
|
|
337
363
|
});
|
|
338
364
|
it('should return a partial template for current value', function () {
|
|
339
365
|
var asYouType = new AsYouType('US');
|
|
340
|
-
asYouType.input('').
|
|
341
|
-
asYouType.getTemplate().
|
|
342
|
-
asYouType.input('2').
|
|
366
|
+
expect(asYouType.input('')).to.equal('');
|
|
367
|
+
expect(asYouType.getTemplate()).to.equal('');
|
|
368
|
+
expect(asYouType.input('2')).to.equal('2');
|
|
369
|
+
// asYouType.getTemplate().should.equal('x')
|
|
343
370
|
// Doesn't format for a single digit.
|
|
344
|
-
|
|
345
|
-
asYouType.
|
|
346
|
-
asYouType.
|
|
347
|
-
asYouType.
|
|
348
|
-
asYouType.
|
|
349
|
-
asYouType.getTemplate().should.equal('(xxx)');
|
|
371
|
+
expect(asYouType.getTemplate()).to.equal('x');
|
|
372
|
+
expect(asYouType.input('1')).to.equal('21');
|
|
373
|
+
expect(asYouType.getTemplate()).to.equal('xx');
|
|
374
|
+
expect(asYouType.input('3')).to.equal('(213)');
|
|
375
|
+
expect(asYouType.getTemplate()).to.equal('(xxx)');
|
|
350
376
|
});
|
|
351
377
|
it("should fall back to the default country", function () {
|
|
352
378
|
var formatter = new AsYouType('RU');
|
|
353
|
-
formatter.input('8').
|
|
354
|
-
formatter.input('9').
|
|
355
|
-
formatter.input('9').
|
|
356
|
-
formatter.input('9').
|
|
379
|
+
expect(formatter.input('8')).to.equal('8');
|
|
380
|
+
expect(formatter.input('9')).to.equal('8 9');
|
|
381
|
+
expect(formatter.input('9')).to.equal('8 99');
|
|
382
|
+
expect(formatter.input('9')).to.equal('8 (999)');
|
|
357
383
|
|
|
358
|
-
formatter.
|
|
359
|
-
formatter.
|
|
384
|
+
// formatter.valid.should.be.false
|
|
385
|
+
expect(formatter.formatter.template).to.equal('x (xxx) xxx-xx-xx');
|
|
386
|
+
expect(formatter.getCountry()).to.equal('RU');
|
|
387
|
+
// formatter.getCountryCallingCode().should.equal('7')
|
|
360
388
|
|
|
361
|
-
formatter.input('000000000000').
|
|
389
|
+
expect(formatter.input('000000000000')).to.equal('8999000000000000');
|
|
362
390
|
|
|
391
|
+
// formatter.valid.should.be.false
|
|
363
392
|
expect(formatter.formatter.template).to.be.undefined;
|
|
364
|
-
formatter.getCountry().
|
|
393
|
+
expect(formatter.getCountry()).to.equal('RU');
|
|
394
|
+
// formatter.getCountryCallingCode().should.equal('7')
|
|
365
395
|
|
|
366
|
-
formatter.reset();
|
|
396
|
+
formatter.reset();
|
|
367
397
|
|
|
398
|
+
// formatter.valid.should.be.false
|
|
368
399
|
expect(formatter.formatter.template).to.be.undefined;
|
|
369
|
-
expect(formatter.getCountry()).to.be.undefined;
|
|
400
|
+
expect(formatter.getCountry()).to.be.undefined;
|
|
401
|
+
// formatter.getCountryCallingCode().should.equal('7')
|
|
370
402
|
|
|
371
|
-
formatter.input('+1-213-373-4253').
|
|
403
|
+
expect(formatter.input('+1-213-373-4253')).to.equal('+1 213 373 4253');
|
|
372
404
|
|
|
373
|
-
formatter.
|
|
374
|
-
formatter.
|
|
375
|
-
formatter.
|
|
405
|
+
// formatter.valid.should.be.true
|
|
406
|
+
expect(formatter.getTemplate()).to.equal('xx xxx xxx xxxx');
|
|
407
|
+
expect(formatter.getCountry()).to.equal('US');
|
|
408
|
+
expect(formatter.getCountryCallingCode()).to.equal('1');
|
|
376
409
|
});
|
|
377
410
|
it('should work in edge cases', function () {
|
|
378
411
|
var formatter;
|
|
379
|
-
var thrower;
|
|
412
|
+
var thrower;
|
|
380
413
|
|
|
414
|
+
// No metadata
|
|
381
415
|
thrower = function thrower() {
|
|
382
416
|
return new AsYouType_('RU');
|
|
383
417
|
};
|
|
418
|
+
expect(thrower).to["throw"]('`metadata` argument not passed');
|
|
384
419
|
|
|
385
|
-
|
|
420
|
+
// Second '+' sign
|
|
386
421
|
|
|
387
422
|
formatter = new AsYouType('RU');
|
|
388
|
-
formatter.input('+').
|
|
389
|
-
formatter.input('7').
|
|
390
|
-
formatter.input('+').
|
|
423
|
+
expect(formatter.input('+')).to.equal('+');
|
|
424
|
+
expect(formatter.input('7')).to.equal('+7');
|
|
425
|
+
expect(formatter.input('+')).to.equal('+7');
|
|
426
|
+
|
|
427
|
+
// Out-of-position '+' sign
|
|
391
428
|
|
|
392
429
|
formatter = new AsYouType('RU');
|
|
393
|
-
formatter.input('8').
|
|
394
|
-
formatter.input('+').
|
|
430
|
+
expect(formatter.input('8')).to.equal('8');
|
|
431
|
+
expect(formatter.input('+')).to.equal('8');
|
|
432
|
+
|
|
433
|
+
// No format matched
|
|
395
434
|
|
|
396
435
|
formatter = new AsYouType('RU');
|
|
397
|
-
formatter.input('88005553535').
|
|
398
|
-
formatter.input('0').
|
|
436
|
+
expect(formatter.input('88005553535')).to.equal('8 (800) 555-35-35');
|
|
437
|
+
expect(formatter.input('0')).to.equal('880055535350');
|
|
438
|
+
|
|
439
|
+
// Invalid country phone code
|
|
399
440
|
|
|
400
441
|
formatter = new AsYouType();
|
|
401
|
-
formatter.input('+0123').
|
|
442
|
+
expect(formatter.input('+0123')).to.equal('+0123');
|
|
443
|
+
|
|
444
|
+
// No country specified and not an international number
|
|
402
445
|
|
|
403
446
|
formatter = new AsYouType();
|
|
404
|
-
formatter.input('88005553535').
|
|
447
|
+
expect(formatter.input('88005553535')).to.equal('88005553535');
|
|
448
|
+
|
|
449
|
+
// Extract national prefix when no `national_prefix` is set
|
|
405
450
|
|
|
406
451
|
formatter = new AsYouType('AD');
|
|
407
|
-
formatter.input('155555').
|
|
452
|
+
expect(formatter.input('155555')).to.equal('155 555');
|
|
453
|
+
|
|
454
|
+
// Typing nonsense
|
|
408
455
|
|
|
409
456
|
formatter = new AsYouType('RU');
|
|
410
|
-
formatter.input('+1abc2').
|
|
457
|
+
expect(formatter.input('+1abc2')).to.equal('+1');
|
|
458
|
+
|
|
459
|
+
// Should reset default country when explicitly
|
|
411
460
|
// typing in an international phone number
|
|
412
461
|
|
|
413
462
|
formatter = new AsYouType('RU');
|
|
414
463
|
formatter.input('+');
|
|
415
|
-
type(formatter.getCountry()).
|
|
416
|
-
type(formatter.getCountryCallingCode()).
|
|
464
|
+
expect(type(formatter.getCountry())).to.equal('undefined');
|
|
465
|
+
expect(type(formatter.getCountryCallingCode())).to.equal('undefined');
|
|
466
|
+
|
|
467
|
+
// Country not inferrable from the phone number,
|
|
417
468
|
// while the phone number itself can already be formatted "completely".
|
|
418
469
|
|
|
419
470
|
formatter = new AsYouType();
|
|
420
471
|
formatter.input('+12223333333');
|
|
421
|
-
type(formatter.getCountry()).
|
|
422
|
-
formatter.getCountryCallingCode().
|
|
423
|
-
// If Google changes metadata for England then this test might not cover the case.
|
|
472
|
+
expect(type(formatter.getCountry())).to.equal('undefined');
|
|
473
|
+
expect(formatter.getCountryCallingCode()).to.equal('1');
|
|
424
474
|
|
|
475
|
+
// Reset a chosen format when it no longer applies given the new leading digits.
|
|
476
|
+
// If Google changes metadata for England then this test might not cover the case.
|
|
425
477
|
formatter = new AsYouType('GB');
|
|
426
|
-
formatter.input('0845').
|
|
478
|
+
expect(formatter.input('0845')).to.equal('0845');
|
|
479
|
+
// New leading digits don't match the format previously chosen.
|
|
427
480
|
// Reset the format.
|
|
428
|
-
|
|
429
|
-
formatter.input('0').should.equal('0845 0');
|
|
481
|
+
expect(formatter.input('0')).to.equal('0845 0');
|
|
430
482
|
});
|
|
431
483
|
it('should choose between matching formats based on the absence or presence of a national prefix', function () {
|
|
432
484
|
// The first matching format:
|
|
@@ -456,47 +508,52 @@ describe('AsYouType', function () {
|
|
|
456
508
|
// "domestic_carrier_code_formatting_rule": "$CC $FG"
|
|
457
509
|
// }
|
|
458
510
|
//
|
|
459
|
-
var formatter = new AsYouType('CN');
|
|
511
|
+
var formatter = new AsYouType('CN');
|
|
512
|
+
// National prefix has been input.
|
|
460
513
|
// Chooses the first format.
|
|
461
|
-
|
|
462
|
-
formatter.
|
|
463
|
-
|
|
514
|
+
expect(formatter.input('01010000')).to.equal('010 10000');
|
|
515
|
+
formatter.reset();
|
|
516
|
+
// No national prefix has been input,
|
|
464
517
|
// and `national_prefix_for_parsing` not matched.
|
|
465
518
|
// The first format won't match, because it doesn't have
|
|
466
519
|
// `"national_prefix_is_optional_when_formatting": true`.
|
|
467
520
|
// The second format will match, because it does have
|
|
468
521
|
// `"national_prefix_is_optional_when_formatting": true`.
|
|
469
|
-
|
|
470
|
-
formatter.input('1010000').should.equal('10 1000 0');
|
|
522
|
+
expect(formatter.input('1010000')).to.equal('10 1000 0');
|
|
471
523
|
});
|
|
472
524
|
it('should not accept phone number extensions', function () {
|
|
473
|
-
new AsYouType().input('+1-213-373-4253 ext. 123').
|
|
525
|
+
expect(new AsYouType().input('+1-213-373-4253 ext. 123')).to.equal('+1 213 373 4253');
|
|
474
526
|
});
|
|
475
527
|
it('should parse non-European digits', function () {
|
|
476
|
-
new AsYouType().input('+١٢١٢٢٣٢٣٢٣٢').
|
|
528
|
+
expect(new AsYouType().input('+١٢١٢٢٣٢٣٢٣٢')).to.equal('+1 212 232 3232');
|
|
477
529
|
});
|
|
478
530
|
it('should return a PhoneNumber instance', function () {
|
|
479
|
-
var formatter = new AsYouType('BR');
|
|
531
|
+
var formatter = new AsYouType('BR');
|
|
480
532
|
|
|
533
|
+
// No country calling code.
|
|
481
534
|
expect(formatter.getNumber()).to.be.undefined;
|
|
482
|
-
formatter.input('+1');
|
|
483
|
-
|
|
535
|
+
formatter.input('+1');
|
|
536
|
+
// No national number digits.
|
|
484
537
|
expect(formatter.getNumber()).to.be.undefined;
|
|
485
538
|
formatter.input('213-373-4253');
|
|
486
539
|
var phoneNumber = formatter.getNumber();
|
|
487
|
-
phoneNumber.country.
|
|
488
|
-
phoneNumber.countryCallingCode.
|
|
489
|
-
phoneNumber.number.
|
|
490
|
-
phoneNumber.nationalNumber.
|
|
540
|
+
expect(phoneNumber.country).to.equal('US');
|
|
541
|
+
expect(phoneNumber.countryCallingCode).to.equal('1');
|
|
542
|
+
expect(phoneNumber.number).to.equal('+12133734253');
|
|
543
|
+
expect(phoneNumber.nationalNumber).to.equal('2133734253');
|
|
491
544
|
formatter.reset();
|
|
492
545
|
formatter.input('+1-113-373-4253');
|
|
493
546
|
phoneNumber = formatter.getNumber();
|
|
494
547
|
expect(phoneNumber.country).to.be.undefined;
|
|
495
|
-
phoneNumber.countryCallingCode.
|
|
548
|
+
expect(phoneNumber.countryCallingCode).to.equal('1');
|
|
549
|
+
|
|
550
|
+
// An incorrect NANPA international phone number.
|
|
496
551
|
// (contains national prefix in an international phone number)
|
|
497
552
|
|
|
498
553
|
formatter.reset();
|
|
499
|
-
formatter.input('+1-1');
|
|
554
|
+
formatter.input('+1-1');
|
|
555
|
+
|
|
556
|
+
// Before leading digits < 3 matching was implemented:
|
|
500
557
|
//
|
|
501
558
|
// phoneNumber = formatter.getNumber()
|
|
502
559
|
// expect(phoneNumber).to.not.be.undefined
|
|
@@ -506,36 +563,37 @@ describe('AsYouType', function () {
|
|
|
506
563
|
// expect(phoneNumber.country).to.be.undefined
|
|
507
564
|
// phoneNumber.countryCallingCode.should.equal('1')
|
|
508
565
|
// phoneNumber.number.should.equal('+111')
|
|
566
|
+
|
|
509
567
|
// After leading digits < 3 matching was implemented:
|
|
510
568
|
//
|
|
511
|
-
|
|
512
569
|
phoneNumber = formatter.getNumber();
|
|
513
|
-
expect(phoneNumber).to.be.undefined;
|
|
514
|
-
|
|
570
|
+
expect(phoneNumber).to.be.undefined;
|
|
571
|
+
//
|
|
515
572
|
formatter.input('1');
|
|
516
573
|
phoneNumber = formatter.getNumber();
|
|
517
574
|
expect(phoneNumber.country).to.be.undefined;
|
|
518
|
-
phoneNumber.countryCallingCode.
|
|
519
|
-
phoneNumber.number.
|
|
575
|
+
expect(phoneNumber.countryCallingCode).to.equal('1');
|
|
576
|
+
expect(phoneNumber.number).to.equal('+11');
|
|
520
577
|
});
|
|
521
578
|
it('should work with countries that add digits to national (significant) number', function () {
|
|
522
579
|
// When formatting Argentinian mobile numbers in international format,
|
|
523
580
|
// a `9` is prepended, when compared to national format.
|
|
524
581
|
var asYouType = new AsYouType('AR');
|
|
525
|
-
asYouType.input('+5493435551212').
|
|
526
|
-
asYouType.reset();
|
|
582
|
+
expect(asYouType.input('+5493435551212')).to.equal('+54 9 3435 55 1212');
|
|
583
|
+
asYouType.reset();
|
|
584
|
+
// Digits shouldn't be changed when formatting in national format.
|
|
527
585
|
// (no `9` is prepended).
|
|
528
586
|
// First parses national (significant) number by prepending `9` to it
|
|
529
587
|
// and stripping `15` from it.
|
|
530
588
|
// Then uses `$2 15-$3-$4` format that strips the leading `9`
|
|
531
589
|
// and adds `15`.
|
|
532
|
-
|
|
533
|
-
asYouType.input('0343515551212').should.equal('03435 15-55-1212');
|
|
590
|
+
expect(asYouType.input('0343515551212')).to.equal('03435 15-55-1212');
|
|
534
591
|
});
|
|
535
592
|
it('should return non-formatted phone number when no format matches and national (significant) number has digits added', function () {
|
|
536
593
|
// When formatting Argentinian mobile numbers in international format,
|
|
537
594
|
// a `9` is prepended, when compared to national format.
|
|
538
|
-
var asYouType = new AsYouType('AR');
|
|
595
|
+
var asYouType = new AsYouType('AR');
|
|
596
|
+
// Digits shouldn't be changed when formatting in national format.
|
|
539
597
|
// (no `9` is prepended).
|
|
540
598
|
// First parses national (significant) number by prepending `9` to it
|
|
541
599
|
// and stripping `15` from it.
|
|
@@ -543,8 +601,7 @@ describe('AsYouType', function () {
|
|
|
543
601
|
// and adds `15`.
|
|
544
602
|
// `this.nationalSignificantNumberMatchesInput` is `false` in this case,
|
|
545
603
|
// so `getNonFormattedNumber()` returns `getFullNumber(getNationalDigits())`.
|
|
546
|
-
|
|
547
|
-
asYouType.input('0343515551212999').should.equal('0343515551212999');
|
|
604
|
+
expect(asYouType.input('0343515551212999')).to.equal('0343515551212999');
|
|
548
605
|
});
|
|
549
606
|
it('should format Argentina numbers (starting with 011) (digit by digit)', function () {
|
|
550
607
|
// Inputting a number digit-by-digit and as a whole a two different cases
|
|
@@ -554,40 +611,40 @@ describe('AsYouType', function () {
|
|
|
554
611
|
// nextDigits 0111523456789
|
|
555
612
|
// nationalNumber 91123456789
|
|
556
613
|
var formatter = new AsYouType('AR');
|
|
557
|
-
formatter.input('0').
|
|
558
|
-
formatter.getTemplate().
|
|
559
|
-
formatter.input('1').
|
|
560
|
-
formatter.getTemplate().
|
|
561
|
-
formatter.input('1').
|
|
562
|
-
formatter.getTemplate().
|
|
563
|
-
formatter.input('1').
|
|
564
|
-
formatter.getTemplate().
|
|
565
|
-
formatter.input('5').
|
|
566
|
-
formatter.getTemplate().
|
|
567
|
-
formatter.input('2').
|
|
568
|
-
formatter.getTemplate().
|
|
569
|
-
formatter.input('3').
|
|
570
|
-
formatter.getTemplate().
|
|
571
|
-
formatter.input('4').
|
|
572
|
-
formatter.getTemplate().
|
|
573
|
-
formatter.input('5').
|
|
574
|
-
formatter.getTemplate().
|
|
575
|
-
formatter.input('6').
|
|
576
|
-
formatter.getTemplate().
|
|
577
|
-
formatter.input('7').
|
|
578
|
-
formatter.getTemplate().
|
|
579
|
-
formatter.input('8').
|
|
580
|
-
formatter.getTemplate().
|
|
581
|
-
formatter.input('9').
|
|
582
|
-
formatter.getTemplate().
|
|
583
|
-
|
|
584
|
-
formatter.state.nationalSignificantNumber.
|
|
614
|
+
expect(formatter.input('0')).to.equal('0');
|
|
615
|
+
expect(formatter.getTemplate()).to.equal('x');
|
|
616
|
+
expect(formatter.input('1')).to.equal('01');
|
|
617
|
+
expect(formatter.getTemplate()).to.equal('xx');
|
|
618
|
+
expect(formatter.input('1')).to.equal('011');
|
|
619
|
+
expect(formatter.getTemplate()).to.equal('xxx');
|
|
620
|
+
expect(formatter.input('1')).to.equal('011 1');
|
|
621
|
+
expect(formatter.getTemplate()).to.equal('xxx x');
|
|
622
|
+
expect(formatter.input('5')).to.equal('011 15');
|
|
623
|
+
expect(formatter.getTemplate()).to.equal('xxx xx');
|
|
624
|
+
expect(formatter.input('2')).to.equal('011 152');
|
|
625
|
+
expect(formatter.getTemplate()).to.equal('xxx xxx');
|
|
626
|
+
expect(formatter.input('3')).to.equal('011 1523');
|
|
627
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx');
|
|
628
|
+
expect(formatter.input('4')).to.equal('011 1523-4');
|
|
629
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx-x');
|
|
630
|
+
expect(formatter.input('5')).to.equal('011 1523-45');
|
|
631
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx-xx');
|
|
632
|
+
expect(formatter.input('6')).to.equal('011 1523-456');
|
|
633
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx-xxx');
|
|
634
|
+
expect(formatter.input('7')).to.equal('011 1523-4567');
|
|
635
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx-xxxx');
|
|
636
|
+
expect(formatter.input('8')).to.equal('011152345678');
|
|
637
|
+
expect(formatter.getTemplate()).to.equal('xxxxxxxxxxxx');
|
|
638
|
+
expect(formatter.input('9')).to.equal('011 15-2345-6789');
|
|
639
|
+
expect(formatter.getTemplate()).to.equal('xxx xx-xxxx-xxxx');
|
|
640
|
+
// Private property (not public API).
|
|
641
|
+
expect(formatter.state.nationalSignificantNumber).to.equal('91123456789');
|
|
642
|
+
// Private property (not public API).
|
|
585
643
|
// `formatter.digits` is not always `formatter.nationalPrefix`
|
|
586
644
|
// plus `formatter.nationalNumberDigits`.
|
|
587
|
-
|
|
588
|
-
formatter.
|
|
589
|
-
formatter.
|
|
590
|
-
formatter.isValid().should.equal(true);
|
|
645
|
+
expect(formatter.state.nationalPrefix).to.equal('0');
|
|
646
|
+
expect(formatter.isPossible()).to.equal(true);
|
|
647
|
+
expect(formatter.isValid()).to.equal(true);
|
|
591
648
|
});
|
|
592
649
|
it('should format Argentina numbers (starting with 011)', function () {
|
|
593
650
|
// Inputting a number digit-by-digit and as a whole a two different cases
|
|
@@ -597,60 +654,64 @@ describe('AsYouType', function () {
|
|
|
597
654
|
// nextDigits 0111523456789
|
|
598
655
|
// nationalNumber 91123456789
|
|
599
656
|
var formatter = new AsYouType('AR');
|
|
600
|
-
formatter.input('0111523456789').
|
|
601
|
-
|
|
602
|
-
formatter.state.nationalSignificantNumber.
|
|
657
|
+
expect(formatter.input('0111523456789')).to.equal('011 15-2345-6789');
|
|
658
|
+
// Private property (not public API).
|
|
659
|
+
expect(formatter.state.nationalSignificantNumber).to.equal('91123456789');
|
|
660
|
+
// Private property (not public API).
|
|
603
661
|
// `formatter.digits` is not always `formatter.nationalPrefix`
|
|
604
662
|
// plus `formatter.nationalNumberDigits`.
|
|
663
|
+
expect(formatter.state.nationalPrefix).to.equal('0');
|
|
664
|
+
// expect(formatter.nationalPrefix).to.be.undefined
|
|
665
|
+
expect(formatter.isPossible()).to.equal(true);
|
|
666
|
+
expect(formatter.isValid()).to.equal(true);
|
|
667
|
+
});
|
|
605
668
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
formatter.isPossible().should.equal(true);
|
|
609
|
-
formatter.isValid().should.equal(true);
|
|
610
|
-
}); // https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/93
|
|
611
|
-
|
|
669
|
+
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/93
|
|
612
670
|
it('should format Indonesian numbers', function () {
|
|
613
671
|
var formatter = new AsYouType('ID');
|
|
614
|
-
formatter.getChars().
|
|
672
|
+
expect(formatter.getChars()).to.equal('');
|
|
673
|
+
// Before leading digits < 3 matching was implemented:
|
|
615
674
|
// formatter.input('081').should.equal('(081)')
|
|
616
675
|
// After leading digits < 3 matching was implemented:
|
|
617
|
-
|
|
618
|
-
formatter.input('081').should.equal('081');
|
|
676
|
+
expect(formatter.input('081')).to.equal('081');
|
|
619
677
|
});
|
|
620
678
|
it('should prepend `complexPrefixBeforeNationalSignificantNumber` (not a complete number)', function () {
|
|
621
679
|
// A country having `national_prefix_for_parsing` with a "capturing group".
|
|
622
680
|
// National prefix is either not used in a format or is optional.
|
|
623
681
|
// Input phone number without a national prefix.
|
|
624
682
|
var formatter = new AsYouType('AU');
|
|
625
|
-
formatter.input('1831130345678').
|
|
626
|
-
|
|
627
|
-
formatter.state.nationalSignificantNumber.
|
|
683
|
+
expect(formatter.input('1831130345678')).to.equal('1831 1303 456 78');
|
|
684
|
+
// Private property (not public API).
|
|
685
|
+
expect(formatter.state.nationalSignificantNumber).to.equal('130345678');
|
|
686
|
+
// Private property (not public API).
|
|
628
687
|
// `formatter.digits` is not always `formatter.nationalPrefix`
|
|
629
688
|
// plus `formatter.nationalNumberDigits`.
|
|
630
|
-
|
|
631
689
|
expect(formatter.state.nationalPrefix).to.be.undefined;
|
|
632
|
-
formatter.state.complexPrefixBeforeNationalSignificantNumber.
|
|
690
|
+
expect(formatter.state.complexPrefixBeforeNationalSignificantNumber).to.equal('1831');
|
|
633
691
|
});
|
|
634
692
|
it('should prepend `complexPrefixBeforeNationalSignificantNumber` (complete number)', function () {
|
|
635
693
|
// A country having `national_prefix_for_parsing` with a "capturing group".
|
|
636
694
|
// National prefix is either not used in a format or is optional.
|
|
637
695
|
// Input phone number without a national prefix.
|
|
638
696
|
var formatter = new AsYouType('AU');
|
|
639
|
-
formatter.input('18311303456789').
|
|
640
|
-
|
|
641
|
-
formatter.state.nationalSignificantNumber.
|
|
697
|
+
expect(formatter.input('18311303456789')).to.equal('1831 1303 456 789');
|
|
698
|
+
// Private property (not public API).
|
|
699
|
+
expect(formatter.state.nationalSignificantNumber).to.equal('1303456789');
|
|
700
|
+
// Private property (not public API).
|
|
642
701
|
// `formatter.digits` is not always `formatter.nationalPrefix`
|
|
643
702
|
// plus `formatter.nationalNumberDigits`.
|
|
644
|
-
|
|
645
703
|
expect(formatter.state.nationalPrefix).to.be.undefined;
|
|
646
|
-
formatter.state.complexPrefixBeforeNationalSignificantNumber.
|
|
704
|
+
expect(formatter.state.complexPrefixBeforeNationalSignificantNumber).to.equal('1831');
|
|
647
705
|
});
|
|
648
706
|
it('should work with Mexico numbers', function () {
|
|
649
|
-
var asYouType = new AsYouType('MX');
|
|
707
|
+
var asYouType = new AsYouType('MX');
|
|
708
|
+
|
|
709
|
+
// Fixed line. International.
|
|
710
|
+
expect(asYouType.input('+52(449)978-000')).to.equal('+52 449 978 000');
|
|
711
|
+
expect(asYouType.input('1')).to.equal('+52 449 978 0001');
|
|
712
|
+
asYouType.reset();
|
|
650
713
|
|
|
651
|
-
|
|
652
|
-
asYouType.input('1').should.equal('+52 449 978 0001');
|
|
653
|
-
asYouType.reset(); // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
|
|
714
|
+
// "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
|
|
654
715
|
// no longer valid since August 2019."
|
|
655
716
|
// // Fixed line. National. With national prefix "01".
|
|
656
717
|
// asYouType.input('01449978000').should.equal('01449 978 000')
|
|
@@ -658,17 +719,20 @@ describe('AsYouType', function () {
|
|
|
658
719
|
// asYouType.input('1').should.equal('01449 978 0001')
|
|
659
720
|
// asYouType.getTemplate().should.equal('xxxxx xxx xxxx')
|
|
660
721
|
// asYouType.reset()
|
|
661
|
-
// Fixed line. National. Without national prefix.
|
|
662
722
|
|
|
663
|
-
|
|
664
|
-
asYouType.
|
|
665
|
-
asYouType.
|
|
666
|
-
asYouType.
|
|
667
|
-
asYouType.
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
asYouType.
|
|
723
|
+
// Fixed line. National. Without national prefix.
|
|
724
|
+
expect(asYouType.input('(449)978-000')).to.equal('449 978 000');
|
|
725
|
+
expect(asYouType.getTemplate()).to.equal('xxx xxx xxx');
|
|
726
|
+
expect(asYouType.input('1')).to.equal('449 978 0001');
|
|
727
|
+
expect(asYouType.getTemplate()).to.equal('xxx xxx xxxx');
|
|
728
|
+
asYouType.reset();
|
|
729
|
+
|
|
730
|
+
// Mobile.
|
|
731
|
+
expect(asYouType.input('+52331234567')).to.equal('+52 33 1234 567');
|
|
732
|
+
expect(asYouType.input('8')).to.equal('+52 33 1234 5678');
|
|
733
|
+
asYouType.reset();
|
|
734
|
+
|
|
735
|
+
// "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
|
|
672
736
|
// no longer valid since August 2019."
|
|
673
737
|
// // Mobile.
|
|
674
738
|
// // With `1` prepended before area code to mobile numbers in international format.
|
|
@@ -692,32 +756,32 @@ describe('AsYouType', function () {
|
|
|
692
756
|
it('should just prepend national prefix if national_prefix_formatting_rule does not produce a suitable number', function () {
|
|
693
757
|
// "national_prefix": "8"
|
|
694
758
|
// "national_prefix_for_parsing": "0|80?"
|
|
695
|
-
var formatter = new AsYouType('BY');
|
|
759
|
+
var formatter = new AsYouType('BY');
|
|
760
|
+
// "national_prefix_formatting_rule": "8 $1"
|
|
696
761
|
// That `national_prefix_formatting_rule` isn't used
|
|
697
762
|
// because the user didn't input national prefix `8`.
|
|
698
|
-
|
|
699
|
-
formatter.
|
|
700
|
-
formatter.getTemplate().should.equal('x xxx xxx');
|
|
763
|
+
expect(formatter.input('0800123')).to.equal('0 800 123');
|
|
764
|
+
expect(formatter.getTemplate()).to.equal('x xxx xxx');
|
|
701
765
|
});
|
|
702
766
|
it('should not duplicate area code for certain countries', function () {
|
|
703
767
|
// https://github.com/catamphetamine/libphonenumber-js/issues/318
|
|
704
|
-
var asYouType = new AsYouType('VI');
|
|
768
|
+
var asYouType = new AsYouType('VI');
|
|
769
|
+
// Even though `parse("3406934")` would return a
|
|
705
770
|
// "(340) 340-6934" national number, still
|
|
706
771
|
// "As You Type" formatter should leave it as "(340) 6934".
|
|
707
|
-
|
|
708
|
-
asYouType.input('
|
|
709
|
-
asYouType.input('
|
|
710
|
-
asYouType.input('123').should.equal('(340) 693-4123');
|
|
772
|
+
expect(asYouType.input('340693')).to.equal('(340) 693');
|
|
773
|
+
expect(asYouType.input('4')).to.equal('(340) 693-4');
|
|
774
|
+
expect(asYouType.input('123')).to.equal('(340) 693-4123');
|
|
711
775
|
});
|
|
712
776
|
it('shouldn\'t throw when passed a non-existent default country', function () {
|
|
713
|
-
new AsYouType('XX').input('+78005553535').
|
|
714
|
-
new AsYouType('XX').input('88005553535').
|
|
777
|
+
expect(new AsYouType('XX').input('+78005553535')).to.equal('+7 800 555 35 35');
|
|
778
|
+
expect(new AsYouType('XX').input('88005553535')).to.equal('88005553535');
|
|
715
779
|
});
|
|
716
780
|
it('should parse carrier codes', function () {
|
|
717
781
|
var formatter = new AsYouType('BR');
|
|
718
782
|
formatter.input('0 15 21 5555-5555');
|
|
719
783
|
var phoneNumber = formatter.getNumber();
|
|
720
|
-
phoneNumber.carrierCode.
|
|
784
|
+
expect(phoneNumber.carrierCode).to.equal('15');
|
|
721
785
|
formatter.reset();
|
|
722
786
|
formatter.input('+1-213-373-4253');
|
|
723
787
|
phoneNumber = formatter.getNumber();
|
|
@@ -727,9 +791,9 @@ describe('AsYouType', function () {
|
|
|
727
791
|
var formatter = new AsYouType({
|
|
728
792
|
defaultCallingCode: '7'
|
|
729
793
|
});
|
|
730
|
-
formatter.input('88005553535').
|
|
731
|
-
formatter.getNumber().countryCallingCode.
|
|
732
|
-
formatter.getNumber().country.
|
|
794
|
+
expect(formatter.input('88005553535')).to.equal('8 (800) 555-35-35');
|
|
795
|
+
expect(formatter.getNumber().countryCallingCode).to.equal('7');
|
|
796
|
+
expect(formatter.getNumber().country).to.equal('RU');
|
|
733
797
|
});
|
|
734
798
|
it('shouldn\'t return PhoneNumber if country calling code hasn\'t been input yet', function () {
|
|
735
799
|
var formatter = new AsYouType();
|
|
@@ -738,99 +802,92 @@ describe('AsYouType', function () {
|
|
|
738
802
|
});
|
|
739
803
|
it('should format non-geographic numbering plan phone numbers', function () {
|
|
740
804
|
var formatter = new AsYouType();
|
|
741
|
-
formatter.input('+').
|
|
742
|
-
formatter.input('8').
|
|
743
|
-
formatter.input('7').
|
|
805
|
+
expect(formatter.input('+')).to.equal('+');
|
|
806
|
+
expect(formatter.input('8')).to.equal('+8');
|
|
807
|
+
expect(formatter.input('7')).to.equal('+87');
|
|
744
808
|
expect(formatter.getCountry()).to.be.undefined;
|
|
745
|
-
formatter.input('0').
|
|
746
|
-
|
|
809
|
+
expect(formatter.input('0')).to.equal('+870');
|
|
747
810
|
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
748
|
-
formatter.getCountry().
|
|
811
|
+
expect(formatter.getCountry()).to.equal('001');
|
|
749
812
|
} else {
|
|
750
813
|
expect(formatter.getCountry()).to.be.undefined;
|
|
751
814
|
}
|
|
752
|
-
|
|
753
|
-
formatter.input('7').
|
|
754
|
-
formatter.input('
|
|
755
|
-
formatter.input('
|
|
756
|
-
formatter.input('1').
|
|
757
|
-
formatter.input('1').
|
|
758
|
-
formatter.input('
|
|
759
|
-
formatter.input('
|
|
760
|
-
formatter.input('
|
|
761
|
-
formatter.input('2').should.equal('+870 773 111 632');
|
|
762
|
-
|
|
815
|
+
expect(formatter.input('7')).to.equal('+870 7');
|
|
816
|
+
expect(formatter.input('7')).to.equal('+870 77');
|
|
817
|
+
expect(formatter.input('3')).to.equal('+870 773');
|
|
818
|
+
expect(formatter.input('1')).to.equal('+870 773 1');
|
|
819
|
+
expect(formatter.input('1')).to.equal('+870 773 11');
|
|
820
|
+
expect(formatter.input('1')).to.equal('+870 773 111');
|
|
821
|
+
expect(formatter.input('6')).to.equal('+870 773 111 6');
|
|
822
|
+
expect(formatter.input('3')).to.equal('+870 773 111 63');
|
|
823
|
+
expect(formatter.input('2')).to.equal('+870 773 111 632');
|
|
763
824
|
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
764
|
-
formatter.getNumber().country.
|
|
825
|
+
expect(formatter.getNumber().country).to.equal('001');
|
|
765
826
|
} else {
|
|
766
827
|
expect(formatter.getCountry()).to.be.undefined;
|
|
767
828
|
}
|
|
768
|
-
|
|
769
|
-
formatter.getNumber().countryCallingCode.should.equal('870');
|
|
829
|
+
expect(formatter.getNumber().countryCallingCode).to.equal('870');
|
|
770
830
|
});
|
|
771
831
|
it('should format non-geographic numbering plan phone numbers (default country calling code)', function () {
|
|
772
832
|
var formatter = new AsYouType({
|
|
773
833
|
defaultCallingCode: '870'
|
|
774
834
|
});
|
|
775
|
-
|
|
776
835
|
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
777
|
-
formatter.getNumber().country.
|
|
836
|
+
expect(formatter.getNumber().country).to.equal('001');
|
|
778
837
|
} else {
|
|
779
838
|
expect(formatter.getCountry()).to.be.undefined;
|
|
780
839
|
}
|
|
781
|
-
|
|
782
|
-
formatter.input('7').
|
|
783
|
-
formatter.input('
|
|
784
|
-
formatter.input('
|
|
785
|
-
formatter.input('1').
|
|
786
|
-
formatter.input('1').
|
|
787
|
-
formatter.input('
|
|
788
|
-
formatter.input('
|
|
789
|
-
formatter.input('
|
|
790
|
-
formatter.input('2').should.equal('773 111 632');
|
|
791
|
-
|
|
840
|
+
expect(formatter.input('7')).to.equal('7');
|
|
841
|
+
expect(formatter.input('7')).to.equal('77');
|
|
842
|
+
expect(formatter.input('3')).to.equal('773');
|
|
843
|
+
expect(formatter.input('1')).to.equal('773 1');
|
|
844
|
+
expect(formatter.input('1')).to.equal('773 11');
|
|
845
|
+
expect(formatter.input('1')).to.equal('773 111');
|
|
846
|
+
expect(formatter.input('6')).to.equal('773 111 6');
|
|
847
|
+
expect(formatter.input('3')).to.equal('773 111 63');
|
|
848
|
+
expect(formatter.input('2')).to.equal('773 111 632');
|
|
792
849
|
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
793
|
-
formatter.getNumber().country.
|
|
850
|
+
expect(formatter.getNumber().country).to.equal('001');
|
|
794
851
|
} else {
|
|
795
852
|
expect(formatter.getCountry()).to.be.undefined;
|
|
796
853
|
}
|
|
797
|
-
|
|
798
|
-
formatter.getNumber().countryCallingCode.should.equal('870');
|
|
854
|
+
expect(formatter.getNumber().countryCallingCode).to.equal('870');
|
|
799
855
|
});
|
|
800
856
|
it('should not format non-geographic numbering plan phone numbers (default country 001)', function () {
|
|
801
857
|
var formatter = new AsYouType('001');
|
|
802
858
|
expect(formatter.defaultCountry).to.be.undefined;
|
|
803
859
|
expect(formatter.defaultCallingCode).to.be.undefined;
|
|
804
|
-
formatter.input('7').
|
|
805
|
-
formatter.input('7').
|
|
806
|
-
formatter.input('3').
|
|
807
|
-
formatter.input('1').
|
|
808
|
-
formatter.input('1').
|
|
809
|
-
formatter.input('1').
|
|
810
|
-
formatter.input('6').
|
|
811
|
-
formatter.input('3').
|
|
812
|
-
formatter.input('2').
|
|
860
|
+
expect(formatter.input('7')).to.equal('7');
|
|
861
|
+
expect(formatter.input('7')).to.equal('77');
|
|
862
|
+
expect(formatter.input('3')).to.equal('773');
|
|
863
|
+
expect(formatter.input('1')).to.equal('7731');
|
|
864
|
+
expect(formatter.input('1')).to.equal('77311');
|
|
865
|
+
expect(formatter.input('1')).to.equal('773111');
|
|
866
|
+
expect(formatter.input('6')).to.equal('7731116');
|
|
867
|
+
expect(formatter.input('3')).to.equal('77311163');
|
|
868
|
+
expect(formatter.input('2')).to.equal('773111632');
|
|
813
869
|
expect(formatter.getCountry()).to.be.undefined;
|
|
814
870
|
expect(formatter.getNumber()).to.be.undefined;
|
|
815
871
|
});
|
|
816
872
|
it('should return PhoneNumber (should strip national prefix `1` in E.164 value)', function () {
|
|
817
873
|
var formatter = new AsYouType('RU');
|
|
818
874
|
formatter.input('+1111');
|
|
819
|
-
formatter.getNumber().number.
|
|
875
|
+
expect(formatter.getNumber().number).to.equal('+111');
|
|
820
876
|
});
|
|
821
877
|
it('should return PhoneNumber with autocorrected international numbers without leading +', function () {
|
|
822
878
|
// https://github.com/catamphetamine/libphonenumber-js/issues/316
|
|
823
879
|
var formatter = new AsYouType('FR');
|
|
824
|
-
formatter.input('33612902554').
|
|
825
|
-
formatter.getNumber().country.
|
|
826
|
-
formatter.getNumber().nationalNumber.
|
|
827
|
-
formatter.getNumber().number.
|
|
828
|
-
|
|
880
|
+
expect(formatter.input('33612902554')).to.equal('33 6 12 90 25 54');
|
|
881
|
+
expect(formatter.getNumber().country).to.equal('FR');
|
|
882
|
+
expect(formatter.getNumber().nationalNumber).to.equal('612902554');
|
|
883
|
+
expect(formatter.getNumber().number).to.equal('+33612902554');
|
|
884
|
+
// Should also strip national prefix.
|
|
829
885
|
formatter.reset();
|
|
830
|
-
formatter.input('330612902554').
|
|
831
|
-
formatter.getNumber().country.
|
|
832
|
-
formatter.getNumber().nationalNumber.
|
|
833
|
-
formatter.getNumber().number.
|
|
886
|
+
expect(formatter.input('330612902554')).to.equal('33 06 12 90 25 54');
|
|
887
|
+
expect(formatter.getNumber().country).to.equal('FR');
|
|
888
|
+
expect(formatter.getNumber().nationalNumber).to.equal('612902554');
|
|
889
|
+
expect(formatter.getNumber().number).to.equal('+33612902554');
|
|
890
|
+
// On second thought, this "prepend default area code" feature won't be added,
|
|
834
891
|
// because when a user selects "British Virgin Islands" and inputs
|
|
835
892
|
// "2291234", then they see "(229) 123-4" which clearly indicates that
|
|
836
893
|
// they should input the complete phone number (with area code).
|
|
@@ -846,19 +903,19 @@ describe('AsYouType', function () {
|
|
|
846
903
|
});
|
|
847
904
|
it('should work with out-of-country dialing prefix (like 00)', function () {
|
|
848
905
|
var formatter = new AsYouType('DE');
|
|
849
|
-
formatter.input('00498911196611').
|
|
850
|
-
formatter.getCountry().
|
|
851
|
-
formatter.formatter.template.
|
|
852
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
853
|
-
formatter.getTemplate().
|
|
854
|
-
formatter.getNumber().country.
|
|
855
|
-
formatter.getNumber().nationalNumber.
|
|
856
|
-
formatter.getNumber().number.
|
|
906
|
+
expect(formatter.input('00498911196611')).to.equal('00 49 89 11196611');
|
|
907
|
+
expect(formatter.getCountry()).to.equal('DE');
|
|
908
|
+
expect(formatter.formatter.template).to.equal('xx xx xx xxxxxxxx');
|
|
909
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('89 11196611');
|
|
910
|
+
expect(formatter.getTemplate()).to.equal('xx xx xx xxxxxxxx');
|
|
911
|
+
expect(formatter.getNumber().country).to.equal('DE');
|
|
912
|
+
expect(formatter.getNumber().nationalNumber).to.equal('8911196611');
|
|
913
|
+
expect(formatter.getNumber().number).to.equal('+498911196611');
|
|
857
914
|
});
|
|
858
915
|
it('shouldn\'t choose a format when there\'re too many digits for any of them', function () {
|
|
859
916
|
var formatter = new AsYouType('RU');
|
|
860
917
|
formatter.input('89991112233');
|
|
861
|
-
formatter.formatter.chosenFormat.format().
|
|
918
|
+
expect(formatter.formatter.chosenFormat.format()).to.equal('$1 $2-$3-$4');
|
|
862
919
|
formatter.reset();
|
|
863
920
|
formatter.input('899911122334');
|
|
864
921
|
expect(formatter.formatter.chosenFormat).to.be.undefined;
|
|
@@ -868,56 +925,56 @@ describe('AsYouType', function () {
|
|
|
868
925
|
// Has separator after national prefix.
|
|
869
926
|
var formatter = new AsYouType('RU');
|
|
870
927
|
var format = formatter.metadata.formats()[0];
|
|
871
|
-
format.nationalPrefixFormattingRule().
|
|
872
|
-
formatter.formatter.getSeparatorAfterNationalPrefix(format).
|
|
928
|
+
expect(format.nationalPrefixFormattingRule()).to.equal('8 ($1)');
|
|
929
|
+
expect(formatter.formatter.getSeparatorAfterNationalPrefix(format)).to.equal(' ');
|
|
930
|
+
// Britain.
|
|
873
931
|
// Has no separator after national prefix.
|
|
874
|
-
|
|
875
932
|
var formatter2 = new AsYouType('GB');
|
|
876
933
|
var format2 = formatter2.metadata.formats()[0];
|
|
877
|
-
format2.nationalPrefixFormattingRule().
|
|
878
|
-
formatter2.formatter.getSeparatorAfterNationalPrefix(format2).
|
|
934
|
+
expect(format2.nationalPrefixFormattingRule()).to.equal('0$1');
|
|
935
|
+
expect(formatter2.formatter.getSeparatorAfterNationalPrefix(format2)).to.equal('');
|
|
879
936
|
});
|
|
880
937
|
it('should return if the number is possible', function () {
|
|
881
938
|
// National. Russia.
|
|
882
939
|
var formatter = new AsYouType('RU');
|
|
883
|
-
formatter.isPossible().
|
|
940
|
+
expect(formatter.isPossible()).to.equal(false);
|
|
884
941
|
formatter.input('8');
|
|
885
|
-
formatter.isPossible().
|
|
942
|
+
expect(formatter.isPossible()).to.equal(false);
|
|
886
943
|
formatter.input('8005553535');
|
|
887
|
-
formatter.isPossible().
|
|
944
|
+
expect(formatter.isPossible()).to.equal(true);
|
|
888
945
|
formatter.input('5');
|
|
889
|
-
formatter.isPossible().
|
|
946
|
+
expect(formatter.isPossible()).to.equal(false);
|
|
890
947
|
});
|
|
891
948
|
it('should return if the number is valid', function () {
|
|
892
949
|
// National. Russia.
|
|
893
950
|
var formatter = new AsYouType('RU');
|
|
894
|
-
formatter.isValid().
|
|
951
|
+
expect(formatter.isValid()).to.equal(false);
|
|
895
952
|
formatter.input('88005553535');
|
|
896
|
-
formatter.isValid().
|
|
953
|
+
expect(formatter.isValid()).to.equal(true);
|
|
897
954
|
formatter.input('5');
|
|
898
|
-
formatter.isValid().
|
|
955
|
+
expect(formatter.isValid()).to.equal(false);
|
|
899
956
|
});
|
|
900
957
|
it('should return if the number is international', function () {
|
|
901
958
|
// National. Russia.
|
|
902
959
|
var formatter = new AsYouType('RU');
|
|
903
|
-
formatter.isInternational().
|
|
960
|
+
expect(formatter.isInternational()).to.equal(false);
|
|
904
961
|
formatter.input('88005553535');
|
|
905
|
-
formatter.isInternational().
|
|
906
|
-
|
|
962
|
+
expect(formatter.isInternational()).to.equal(false);
|
|
963
|
+
// International. Russia.
|
|
907
964
|
var formatterInt = new AsYouType();
|
|
908
|
-
formatterInt.isInternational().
|
|
965
|
+
expect(formatterInt.isInternational()).to.equal(false);
|
|
909
966
|
formatterInt.input('+');
|
|
910
|
-
formatterInt.isInternational().
|
|
967
|
+
expect(formatterInt.isInternational()).to.equal(true);
|
|
911
968
|
formatterInt.input('78005553535');
|
|
912
|
-
formatterInt.isInternational().
|
|
969
|
+
expect(formatterInt.isInternational()).to.equal(true);
|
|
913
970
|
});
|
|
914
971
|
it('should return country calling code part of the number', function () {
|
|
915
972
|
// National. Russia.
|
|
916
973
|
var formatter = new AsYouType('RU');
|
|
917
974
|
expect(formatter.getCountryCallingCode()).to.be.undefined;
|
|
918
975
|
formatter.input('88005553535');
|
|
919
|
-
expect(formatter.getCountryCallingCode()).to.be.undefined;
|
|
920
|
-
|
|
976
|
+
expect(formatter.getCountryCallingCode()).to.be.undefined;
|
|
977
|
+
// International. Russia.
|
|
921
978
|
var formatterInt = new AsYouType();
|
|
922
979
|
expect(formatterInt.getCountryCallingCode()).to.be.undefined;
|
|
923
980
|
formatterInt.input('+');
|
|
@@ -934,15 +991,15 @@ describe('AsYouType', function () {
|
|
|
934
991
|
formatter.input('8');
|
|
935
992
|
expect(formatter.getCountry()).to.equal('RU');
|
|
936
993
|
formatter.input('8005553535');
|
|
937
|
-
expect(formatter.getCountry()).to.equal('RU');
|
|
938
|
-
|
|
994
|
+
expect(formatter.getCountry()).to.equal('RU');
|
|
995
|
+
// International. Austria.
|
|
939
996
|
var formatterInt = new AsYouType();
|
|
940
997
|
expect(formatterInt.getCountry()).to.be.undefined;
|
|
941
998
|
formatterInt.input('+');
|
|
942
999
|
expect(formatterInt.getCountry()).to.be.undefined;
|
|
943
1000
|
formatterInt.input('43');
|
|
944
|
-
expect(formatterInt.getCountry()).to.equal('AT');
|
|
945
|
-
|
|
1001
|
+
expect(formatterInt.getCountry()).to.equal('AT');
|
|
1002
|
+
// International. USA.
|
|
946
1003
|
var formatterIntRu = new AsYouType();
|
|
947
1004
|
expect(formatterIntRu.getCountry()).to.be.undefined;
|
|
948
1005
|
formatterIntRu.input('+');
|
|
@@ -955,37 +1012,39 @@ describe('AsYouType', function () {
|
|
|
955
1012
|
expect(formatterIntRu.getCountry()).to.be.undefined;
|
|
956
1013
|
});
|
|
957
1014
|
it('should parse a long IDD prefix', function () {
|
|
958
|
-
var formatter = new AsYouType('AU');
|
|
959
|
-
|
|
960
|
-
formatter.input('1').
|
|
961
|
-
formatter.input('4').
|
|
962
|
-
formatter.input('8').
|
|
963
|
-
formatter.input('8').
|
|
964
|
-
formatter.input('0').
|
|
965
|
-
formatter.input('0').
|
|
966
|
-
formatter.input('1').
|
|
967
|
-
formatter.input('1').
|
|
1015
|
+
var formatter = new AsYouType('AU');
|
|
1016
|
+
// `14880011` is a long IDD prefix in Australia.
|
|
1017
|
+
expect(formatter.input('1')).to.equal('1');
|
|
1018
|
+
expect(formatter.input('4')).to.equal('14');
|
|
1019
|
+
expect(formatter.input('8')).to.equal('148');
|
|
1020
|
+
expect(formatter.input('8')).to.equal('1488');
|
|
1021
|
+
expect(formatter.input('0')).to.equal('14880');
|
|
1022
|
+
expect(formatter.input('0')).to.equal('148800');
|
|
1023
|
+
expect(formatter.input('1')).to.equal('1488001');
|
|
1024
|
+
expect(formatter.input('1')).to.equal('14880011');
|
|
1025
|
+
// As if were calling US using `14880011` IDD prefix,
|
|
968
1026
|
// though that prefix could mean something else.
|
|
969
|
-
|
|
970
|
-
formatter.input('
|
|
971
|
-
formatter.input('
|
|
972
|
-
formatter.input('
|
|
973
|
-
formatter.input('3').should.equal('14880011 1 213');
|
|
1027
|
+
expect(formatter.input('1')).to.equal('14880011 1');
|
|
1028
|
+
expect(formatter.input('2')).to.equal('14880011 1 2');
|
|
1029
|
+
expect(formatter.input('1')).to.equal('14880011 1 21');
|
|
1030
|
+
expect(formatter.input('3')).to.equal('14880011 1 213');
|
|
974
1031
|
});
|
|
975
1032
|
it('should return the phone number characters entered by the user', function () {
|
|
976
1033
|
var formatter = new AsYouType('RU');
|
|
977
|
-
formatter.getChars().
|
|
1034
|
+
expect(formatter.getChars()).to.equal('');
|
|
978
1035
|
formatter.input('+123');
|
|
979
|
-
formatter.getChars().
|
|
1036
|
+
expect(formatter.getChars()).to.equal('+123');
|
|
980
1037
|
formatter.reset();
|
|
981
1038
|
formatter.input('123');
|
|
982
|
-
formatter.getChars().
|
|
983
|
-
});
|
|
1039
|
+
expect(formatter.getChars()).to.equal('123');
|
|
1040
|
+
});
|
|
1041
|
+
|
|
1042
|
+
// A test confirming the case when input `"11"` for country `"US"`
|
|
984
1043
|
// produces `value` `"+11"`.
|
|
985
1044
|
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/113
|
|
986
|
-
|
|
987
1045
|
it('should determine the national (significant) part correctly when input with national prefix in US', function () {
|
|
988
|
-
var formatter = new AsYouType('US');
|
|
1046
|
+
var formatter = new AsYouType('US');
|
|
1047
|
+
// As soon as the user has input `"11"`, no `format` matches
|
|
989
1048
|
// those "national number" digits in the `"US"` country metadata.
|
|
990
1049
|
// Since no `format` matches, the number doesn't seem like a valid one,
|
|
991
1050
|
// so it attempts to see if the user "forgot" to input a `"+"` at the start.
|
|
@@ -993,9 +1052,8 @@ describe('AsYouType', function () {
|
|
|
993
1052
|
// So it acts as if the leading `"+"` is there,
|
|
994
1053
|
// as if the user's input is `"+11"`.
|
|
995
1054
|
// See `AsYouType.fixMissingPlus()` function.
|
|
996
|
-
|
|
997
|
-
formatter.
|
|
998
|
-
formatter.getNumber().nationalNumber.should.equal('2222222223');
|
|
1055
|
+
expect(formatter.input('1 122 222 2222 3')).to.equal('1 1 222 222 2223');
|
|
1056
|
+
expect(formatter.getNumber().nationalNumber).to.equal('2222222223');
|
|
999
1057
|
});
|
|
1000
1058
|
});
|
|
1001
1059
|
describe('AsYouType.getNumberValue()', function () {
|
|
@@ -1005,17 +1063,17 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1005
1063
|
formatter.input('');
|
|
1006
1064
|
expect(formatter.getNumberValue()).to.be.undefined;
|
|
1007
1065
|
formatter.input('1');
|
|
1008
|
-
formatter.getNumberValue().
|
|
1066
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1009
1067
|
formatter.input('2');
|
|
1010
|
-
formatter.getNumberValue().
|
|
1068
|
+
expect(formatter.getNumberValue()).to.equal('+12');
|
|
1011
1069
|
formatter.input('1');
|
|
1012
|
-
formatter.getNumberValue().
|
|
1070
|
+
expect(formatter.getNumberValue()).to.equal('+121');
|
|
1013
1071
|
formatter.input('3');
|
|
1014
|
-
formatter.getNumberValue().
|
|
1072
|
+
expect(formatter.getNumberValue()).to.equal('+1213');
|
|
1015
1073
|
formatter.input('373-4253');
|
|
1016
|
-
formatter.getNumberValue().
|
|
1074
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253');
|
|
1017
1075
|
formatter.input('4');
|
|
1018
|
-
formatter.getNumberValue().
|
|
1076
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534');
|
|
1019
1077
|
});
|
|
1020
1078
|
it('should return E.164 number value (national number, with national prefix, default calling code: 1)', function () {
|
|
1021
1079
|
var formatter = new AsYouType({
|
|
@@ -1025,17 +1083,17 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1025
1083
|
formatter.input('');
|
|
1026
1084
|
expect(formatter.getNumberValue()).to.be.undefined;
|
|
1027
1085
|
formatter.input('1');
|
|
1028
|
-
formatter.getNumberValue().
|
|
1086
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1029
1087
|
formatter.input('2');
|
|
1030
|
-
formatter.getNumberValue().
|
|
1088
|
+
expect(formatter.getNumberValue()).to.equal('+12');
|
|
1031
1089
|
formatter.input('1');
|
|
1032
|
-
formatter.getNumberValue().
|
|
1090
|
+
expect(formatter.getNumberValue()).to.equal('+121');
|
|
1033
1091
|
formatter.input('3');
|
|
1034
|
-
formatter.getNumberValue().
|
|
1092
|
+
expect(formatter.getNumberValue()).to.equal('+1213');
|
|
1035
1093
|
formatter.input('373-4253');
|
|
1036
|
-
formatter.getNumberValue().
|
|
1094
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253');
|
|
1037
1095
|
formatter.input('4');
|
|
1038
|
-
formatter.getNumberValue().
|
|
1096
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534');
|
|
1039
1097
|
});
|
|
1040
1098
|
it('should return E.164 number value (national number, default country: US)', function () {
|
|
1041
1099
|
var formatter = new AsYouType('US');
|
|
@@ -1043,15 +1101,15 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1043
1101
|
formatter.input('');
|
|
1044
1102
|
expect(formatter.getNumberValue()).to.be.undefined;
|
|
1045
1103
|
formatter.input('2');
|
|
1046
|
-
formatter.getNumberValue().
|
|
1104
|
+
expect(formatter.getNumberValue()).to.equal('+12');
|
|
1047
1105
|
formatter.input('1');
|
|
1048
|
-
formatter.getNumberValue().
|
|
1106
|
+
expect(formatter.getNumberValue()).to.equal('+121');
|
|
1049
1107
|
formatter.input('3');
|
|
1050
|
-
formatter.getNumberValue().
|
|
1108
|
+
expect(formatter.getNumberValue()).to.equal('+1213');
|
|
1051
1109
|
formatter.input('373-4253');
|
|
1052
|
-
formatter.getNumberValue().
|
|
1110
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253');
|
|
1053
1111
|
formatter.input('4');
|
|
1054
|
-
formatter.getNumberValue().
|
|
1112
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534');
|
|
1055
1113
|
});
|
|
1056
1114
|
it('should return E.164 number value (national number, default calling code: 1)', function () {
|
|
1057
1115
|
var formatter = new AsYouType({
|
|
@@ -1061,15 +1119,15 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1061
1119
|
formatter.input('');
|
|
1062
1120
|
expect(formatter.getNumberValue()).to.be.undefined;
|
|
1063
1121
|
formatter.input('2');
|
|
1064
|
-
formatter.getNumberValue().
|
|
1122
|
+
expect(formatter.getNumberValue()).to.equal('+12');
|
|
1065
1123
|
formatter.input('1');
|
|
1066
|
-
formatter.getNumberValue().
|
|
1124
|
+
expect(formatter.getNumberValue()).to.equal('+121');
|
|
1067
1125
|
formatter.input('3');
|
|
1068
|
-
formatter.getNumberValue().
|
|
1126
|
+
expect(formatter.getNumberValue()).to.equal('+1213');
|
|
1069
1127
|
formatter.input('373-4253');
|
|
1070
|
-
formatter.getNumberValue().
|
|
1128
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253');
|
|
1071
1129
|
formatter.input('4');
|
|
1072
|
-
formatter.getNumberValue().
|
|
1130
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534');
|
|
1073
1131
|
});
|
|
1074
1132
|
it('should return E.164 number value (international number, not a valid calling code)', function () {
|
|
1075
1133
|
var formatter = new AsYouType();
|
|
@@ -1079,7 +1137,7 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1079
1137
|
formatter.input('+');
|
|
1080
1138
|
expect(formatter.getNumberValue()).to.be.undefined;
|
|
1081
1139
|
formatter.input('2150');
|
|
1082
|
-
formatter.getNumberValue().
|
|
1140
|
+
expect(formatter.getNumberValue()).to.equal('+2150');
|
|
1083
1141
|
});
|
|
1084
1142
|
it('should return E.164 number value (international number, default country: US)', function () {
|
|
1085
1143
|
var formatter = new AsYouType('US');
|
|
@@ -1089,19 +1147,19 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1089
1147
|
formatter.input('+');
|
|
1090
1148
|
expect(formatter.getNumberValue()).to.be.undefined;
|
|
1091
1149
|
formatter.input('1');
|
|
1092
|
-
formatter.getNumberValue().
|
|
1150
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1093
1151
|
formatter.input('1');
|
|
1094
|
-
formatter.getNumberValue().
|
|
1152
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1095
1153
|
formatter.input('2');
|
|
1096
|
-
formatter.getNumberValue().
|
|
1154
|
+
expect(formatter.getNumberValue()).to.equal('+12');
|
|
1097
1155
|
formatter.input('1');
|
|
1098
|
-
formatter.getNumberValue().
|
|
1156
|
+
expect(formatter.getNumberValue()).to.equal('+121');
|
|
1099
1157
|
formatter.input('3');
|
|
1100
|
-
formatter.getNumberValue().
|
|
1158
|
+
expect(formatter.getNumberValue()).to.equal('+1213');
|
|
1101
1159
|
formatter.input('373-4253');
|
|
1102
|
-
formatter.getNumberValue().
|
|
1160
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253');
|
|
1103
1161
|
formatter.input('4');
|
|
1104
|
-
formatter.getNumberValue().
|
|
1162
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534');
|
|
1105
1163
|
});
|
|
1106
1164
|
it('should return E.164 number value (international number, other default country: RU)', function () {
|
|
1107
1165
|
var formatter = new AsYouType('RU');
|
|
@@ -1111,19 +1169,19 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1111
1169
|
formatter.input('+');
|
|
1112
1170
|
expect(formatter.getNumberValue()).to.be.undefined;
|
|
1113
1171
|
formatter.input('1');
|
|
1114
|
-
formatter.getNumberValue().
|
|
1172
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1115
1173
|
formatter.input('1');
|
|
1116
|
-
formatter.getNumberValue().
|
|
1174
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1117
1175
|
formatter.input('2');
|
|
1118
|
-
formatter.getNumberValue().
|
|
1176
|
+
expect(formatter.getNumberValue()).to.equal('+12');
|
|
1119
1177
|
formatter.input('1');
|
|
1120
|
-
formatter.getNumberValue().
|
|
1178
|
+
expect(formatter.getNumberValue()).to.equal('+121');
|
|
1121
1179
|
formatter.input('3');
|
|
1122
|
-
formatter.getNumberValue().
|
|
1180
|
+
expect(formatter.getNumberValue()).to.equal('+1213');
|
|
1123
1181
|
formatter.input('373-4253');
|
|
1124
|
-
formatter.getNumberValue().
|
|
1182
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253');
|
|
1125
1183
|
formatter.input('4');
|
|
1126
|
-
formatter.getNumberValue().
|
|
1184
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534');
|
|
1127
1185
|
});
|
|
1128
1186
|
it('should return E.164 number value (international number, default calling code: 1)', function () {
|
|
1129
1187
|
var formatter = new AsYouType('US', {
|
|
@@ -1135,19 +1193,19 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1135
1193
|
formatter.input('+');
|
|
1136
1194
|
expect(formatter.getNumberValue()).to.be.undefined;
|
|
1137
1195
|
formatter.input('1');
|
|
1138
|
-
formatter.getNumberValue().
|
|
1196
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1139
1197
|
formatter.input('1');
|
|
1140
|
-
formatter.getNumberValue().
|
|
1198
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1141
1199
|
formatter.input('2');
|
|
1142
|
-
formatter.getNumberValue().
|
|
1200
|
+
expect(formatter.getNumberValue()).to.equal('+12');
|
|
1143
1201
|
formatter.input('1');
|
|
1144
|
-
formatter.getNumberValue().
|
|
1202
|
+
expect(formatter.getNumberValue()).to.equal('+121');
|
|
1145
1203
|
formatter.input('3');
|
|
1146
|
-
formatter.getNumberValue().
|
|
1204
|
+
expect(formatter.getNumberValue()).to.equal('+1213');
|
|
1147
1205
|
formatter.input('373-4253');
|
|
1148
|
-
formatter.getNumberValue().
|
|
1206
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253');
|
|
1149
1207
|
formatter.input('4');
|
|
1150
|
-
formatter.getNumberValue().
|
|
1208
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534');
|
|
1151
1209
|
});
|
|
1152
1210
|
it('should return E.164 number value (international number, other default calling code: 7)', function () {
|
|
1153
1211
|
var formatter = new AsYouType('US', {
|
|
@@ -1159,19 +1217,19 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1159
1217
|
formatter.input('+');
|
|
1160
1218
|
expect(formatter.getNumberValue()).to.be.undefined;
|
|
1161
1219
|
formatter.input('1');
|
|
1162
|
-
formatter.getNumberValue().
|
|
1220
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1163
1221
|
formatter.input('1');
|
|
1164
|
-
formatter.getNumberValue().
|
|
1222
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1165
1223
|
formatter.input('2');
|
|
1166
|
-
formatter.getNumberValue().
|
|
1224
|
+
expect(formatter.getNumberValue()).to.equal('+12');
|
|
1167
1225
|
formatter.input('1');
|
|
1168
|
-
formatter.getNumberValue().
|
|
1226
|
+
expect(formatter.getNumberValue()).to.equal('+121');
|
|
1169
1227
|
formatter.input('3');
|
|
1170
|
-
formatter.getNumberValue().
|
|
1228
|
+
expect(formatter.getNumberValue()).to.equal('+1213');
|
|
1171
1229
|
formatter.input('373-4253');
|
|
1172
|
-
formatter.getNumberValue().
|
|
1230
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253');
|
|
1173
1231
|
formatter.input('4');
|
|
1174
|
-
formatter.getNumberValue().
|
|
1232
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534');
|
|
1175
1233
|
});
|
|
1176
1234
|
it('should return E.164 number value (international number)', function () {
|
|
1177
1235
|
var formatter = new AsYouType();
|
|
@@ -1181,19 +1239,19 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1181
1239
|
formatter.input('+');
|
|
1182
1240
|
expect(formatter.getNumberValue()).to.be.undefined;
|
|
1183
1241
|
formatter.input('1');
|
|
1184
|
-
formatter.getNumberValue().
|
|
1242
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1185
1243
|
formatter.input('1');
|
|
1186
|
-
formatter.getNumberValue().
|
|
1244
|
+
expect(formatter.getNumberValue()).to.equal('+1');
|
|
1187
1245
|
formatter.input('2');
|
|
1188
|
-
formatter.getNumberValue().
|
|
1246
|
+
expect(formatter.getNumberValue()).to.equal('+12');
|
|
1189
1247
|
formatter.input('1');
|
|
1190
|
-
formatter.getNumberValue().
|
|
1248
|
+
expect(formatter.getNumberValue()).to.equal('+121');
|
|
1191
1249
|
formatter.input('3');
|
|
1192
|
-
formatter.getNumberValue().
|
|
1250
|
+
expect(formatter.getNumberValue()).to.equal('+1213');
|
|
1193
1251
|
formatter.input('373-4253');
|
|
1194
|
-
formatter.getNumberValue().
|
|
1252
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253');
|
|
1195
1253
|
formatter.input('4');
|
|
1196
|
-
formatter.getNumberValue().
|
|
1254
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534');
|
|
1197
1255
|
});
|
|
1198
1256
|
it('should return E.164 number value (national number) (no default country or calling code)', function () {
|
|
1199
1257
|
var formatter = new AsYouType();
|
|
@@ -1215,22 +1273,22 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1215
1273
|
// Test "+529011234567" number, proactively ensuring that no formatting is applied,
|
|
1216
1274
|
// where a format is chosen that would otherwise have led to some digits being dropped.
|
|
1217
1275
|
var formatter = new AsYouType('MX');
|
|
1218
|
-
formatter.input('9').
|
|
1219
|
-
formatter.input('0').
|
|
1220
|
-
formatter.input('1').
|
|
1221
|
-
formatter.input('1').
|
|
1222
|
-
formatter.input('2').
|
|
1223
|
-
formatter.input('3').
|
|
1224
|
-
formatter.input('4').
|
|
1225
|
-
formatter.input('5').
|
|
1226
|
-
formatter.input('6').
|
|
1227
|
-
formatter.input('7').
|
|
1276
|
+
expect(formatter.input('9')).to.equal('9');
|
|
1277
|
+
expect(formatter.input('0')).to.equal('90');
|
|
1278
|
+
expect(formatter.input('1')).to.equal('901');
|
|
1279
|
+
expect(formatter.input('1')).to.equal('901 1');
|
|
1280
|
+
expect(formatter.input('2')).to.equal('901 12');
|
|
1281
|
+
expect(formatter.input('3')).to.equal('901 123');
|
|
1282
|
+
expect(formatter.input('4')).to.equal('901 123 4');
|
|
1283
|
+
expect(formatter.input('5')).to.equal('901 123 45');
|
|
1284
|
+
expect(formatter.input('6')).to.equal('901 123 456');
|
|
1285
|
+
expect(formatter.input('7')).to.equal('901 123 4567');
|
|
1228
1286
|
});
|
|
1229
1287
|
it('should work for formats with no leading digits (`leadingDigitsPatternsCount === 0`)', function () {
|
|
1230
1288
|
var formatter = new AsYouType({
|
|
1231
1289
|
defaultCallingCode: 888
|
|
1232
1290
|
});
|
|
1233
|
-
formatter.input('1').
|
|
1291
|
+
expect(formatter.input('1')).to.equal('1');
|
|
1234
1292
|
});
|
|
1235
1293
|
it('should work for SK phone numbers', function () {
|
|
1236
1294
|
// There was a bug: "leading digits" `"2"` matched "leading digits pattern" `"90"`.
|
|
@@ -1238,17 +1296,17 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1238
1296
|
// while it should've been `undefined`.
|
|
1239
1297
|
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/66
|
|
1240
1298
|
var formatter = new AsYouType('SK');
|
|
1241
|
-
formatter.input('090').
|
|
1299
|
+
expect(formatter.input('090')).to.equal('090');
|
|
1242
1300
|
formatter.reset();
|
|
1243
|
-
formatter.input('080').
|
|
1301
|
+
expect(formatter.input('080')).to.equal('080');
|
|
1244
1302
|
formatter.reset();
|
|
1245
|
-
formatter.input('059').
|
|
1303
|
+
expect(formatter.input('059')).to.equal('059');
|
|
1246
1304
|
});
|
|
1247
1305
|
it('should work for SK phone numbers (2)', function () {
|
|
1248
1306
|
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/69
|
|
1249
1307
|
var formatter = new AsYouType('SK');
|
|
1250
|
-
formatter.input('421901222333').
|
|
1251
|
-
formatter.getTemplate().
|
|
1308
|
+
expect(formatter.input('421901222333')).to.equal('421 901 222 333');
|
|
1309
|
+
expect(formatter.getTemplate()).to.equal('xxx xxx xxx xxx');
|
|
1252
1310
|
});
|
|
1253
1311
|
it('should not choose `defaultCountry` over the "main" one when both the `defaultCountry` and the "main" one match the phone number', function () {
|
|
1254
1312
|
// This phone number matches both US and CA because they have the same
|
|
@@ -1256,20 +1314,21 @@ describe('AsYouType.getNumberValue()', function () {
|
|
|
1256
1314
|
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103
|
|
1257
1315
|
var formatter = new AsYouType('CA');
|
|
1258
1316
|
formatter.input('8004001000');
|
|
1259
|
-
formatter.getNumber().country.
|
|
1260
|
-
formatter.getNumber().country.
|
|
1317
|
+
expect(formatter.getNumber().country).not.to.equal('CA');
|
|
1318
|
+
expect(formatter.getNumber().country).to.equal('US');
|
|
1261
1319
|
|
|
1320
|
+
// This phone number is specific to CA.
|
|
1262
1321
|
var formatter2 = new AsYouType('US');
|
|
1263
1322
|
formatter2.input('4389999999');
|
|
1264
|
-
formatter2.getNumber().country.
|
|
1265
|
-
// In fact, it doesn't belong to any country from the "NANPA" zone.
|
|
1323
|
+
expect(formatter2.getNumber().country).to.equal('CA');
|
|
1266
1324
|
|
|
1325
|
+
// This phone number doesn't belong neither to CA nor to US.
|
|
1326
|
+
// In fact, it doesn't belong to any country from the "NANPA" zone.
|
|
1267
1327
|
var formatter3 = new AsYouType('US');
|
|
1268
1328
|
formatter3.input('1111111111');
|
|
1269
|
-
formatter3.getNumber().country.
|
|
1329
|
+
expect(formatter3.getNumber().country).to.equal('US');
|
|
1270
1330
|
});
|
|
1271
1331
|
});
|
|
1272
|
-
|
|
1273
1332
|
function type(something) {
|
|
1274
1333
|
return _typeof(something);
|
|
1275
1334
|
}
|