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/source/AsYouType.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import metadata from '../metadata.min.json'
|
|
1
|
+
import metadata from '../metadata.min.json' with { type: 'json' }
|
|
2
2
|
import AsYouType_ from './AsYouType.js'
|
|
3
3
|
|
|
4
4
|
class AsYouType extends AsYouType_ {
|
|
@@ -12,90 +12,90 @@ const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
|
|
|
12
12
|
describe('AsYouType', () => {
|
|
13
13
|
it('should use "national_prefix_formatting_rule"', () => {
|
|
14
14
|
// With national prefix (full).
|
|
15
|
-
new AsYouType('RU').input('88005553535').
|
|
15
|
+
expect(new AsYouType('RU').input('88005553535')).to.equal('8 (800) 555-35-35')
|
|
16
16
|
// With national prefix (partial).
|
|
17
|
-
new AsYouType('RU').input('880055535').
|
|
17
|
+
expect(new AsYouType('RU').input('880055535')).to.equal('8 (800) 555-35')
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
it('should populate national number template (digit by digit)', () => {
|
|
21
21
|
const formatter = new AsYouType('US')
|
|
22
22
|
formatter.input('1')
|
|
23
23
|
// formatter.formatter.template.should.equal('x (xxx) xxx-xxxx')
|
|
24
|
-
formatter.formatter.template.
|
|
24
|
+
expect(formatter.formatter.template).to.equal('x xxx-xxxx')
|
|
25
25
|
// formatter.formatter.populatedNationalNumberTemplate.should.equal('1 (xxx) xxx-xxxx')
|
|
26
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
26
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 xxx-xxxx')
|
|
27
27
|
formatter.input('213')
|
|
28
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
28
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 (213) xxx-xxxx')
|
|
29
29
|
formatter.input('3734253')
|
|
30
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
30
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 (213) 373-4253')
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
it('should populate international number template (digit by digit) (default country)', () => {
|
|
34
34
|
const formatter = new AsYouType('US')
|
|
35
35
|
expect(formatter.formatter.template).to.be.undefined
|
|
36
36
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined
|
|
37
|
-
formatter.input('').
|
|
37
|
+
expect(formatter.input('')).to.equal('')
|
|
38
38
|
expect(formatter.formatter.template).to.be.undefined
|
|
39
39
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined
|
|
40
|
-
formatter.input('+').
|
|
41
|
-
formatter.getTemplate().
|
|
40
|
+
expect(formatter.input('+')).to.equal('+')
|
|
41
|
+
expect(formatter.getTemplate()).to.equal('x')
|
|
42
42
|
expect(formatter.formatter.template).to.be.undefined
|
|
43
43
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined
|
|
44
|
-
formatter.input('1').
|
|
45
|
-
formatter.getTemplate().
|
|
44
|
+
expect(formatter.input('1')).to.equal('+1')
|
|
45
|
+
expect(formatter.getTemplate()).to.equal('xx')
|
|
46
46
|
// Hasn't started formatting the phone number using the template yet.
|
|
47
47
|
// formatter.formatter.template.should.equal('xx xxx xxx xxxx')
|
|
48
|
-
formatter.formatter.template.
|
|
48
|
+
expect(formatter.formatter.template).to.equal('xx xxx xxxx')
|
|
49
49
|
// formatter.formatter.populatedNationalNumberTemplate.should.equal('xxx xxx xxxx')
|
|
50
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
50
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('xxx xxxx')
|
|
51
51
|
// Has some national number digits, starts formatting the phone number using the template.
|
|
52
52
|
formatter.input('213')
|
|
53
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
53
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 xxx xxxx')
|
|
54
54
|
formatter.input('3734253')
|
|
55
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
55
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 373 4253')
|
|
56
56
|
})
|
|
57
57
|
|
|
58
58
|
it('should populate international number template (digit by digit)', () => {
|
|
59
59
|
const formatter = new AsYouType()
|
|
60
60
|
expect(formatter.formatter.template).to.be.undefined
|
|
61
61
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined
|
|
62
|
-
formatter.input('').
|
|
62
|
+
expect(formatter.input('')).to.equal('')
|
|
63
63
|
expect(formatter.formatter.template).to.be.undefined
|
|
64
64
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined
|
|
65
|
-
formatter.input('+').
|
|
65
|
+
expect(formatter.input('+')).to.equal('+')
|
|
66
66
|
expect(formatter.formatter.template).to.be.undefined
|
|
67
67
|
expect(formatter.formatter.populatedNationalNumberTemplate).to.be.undefined
|
|
68
|
-
formatter.input('1').
|
|
68
|
+
expect(formatter.input('1')).to.equal('+1')
|
|
69
69
|
// formatter.formatter.template.should.equal('xx xxx xxx xxxx')
|
|
70
|
-
formatter.formatter.template.
|
|
70
|
+
expect(formatter.formatter.template).to.equal('xx xxx xxxx')
|
|
71
71
|
// Hasn't yet started formatting the phone number using the template.
|
|
72
72
|
// formatter.formatter.populatedNationalNumberTemplate.should.equal('xxx xxx xxxx')
|
|
73
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
73
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('xxx xxxx')
|
|
74
74
|
// Has some national number digits, starts formatting the phone number using the template.
|
|
75
75
|
formatter.input('213')
|
|
76
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
76
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 xxx xxxx')
|
|
77
77
|
formatter.input('3734253')
|
|
78
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
78
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('213 373 4253')
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
it('should populate national number template (attempt to format complete number)', () => {
|
|
82
82
|
const formatter = new AsYouType('US')
|
|
83
|
-
formatter.input('12133734253').
|
|
84
|
-
formatter.formatter.template.
|
|
85
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
83
|
+
expect(formatter.input('12133734253')).to.equal('1 (213) 373-4253')
|
|
84
|
+
expect(formatter.formatter.template).to.equal('x (xxx) xxx-xxxx')
|
|
85
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('1 (213) 373-4253')
|
|
86
86
|
})
|
|
87
87
|
|
|
88
88
|
it('should parse and format phone numbers as you type', () => {
|
|
89
89
|
// International number test
|
|
90
|
-
new AsYouType().input('+12133734').
|
|
90
|
+
expect(new AsYouType().input('+12133734')).to.equal('+1 213 373 4')
|
|
91
91
|
// Local number test
|
|
92
|
-
new AsYouType('US').input('2133734').
|
|
92
|
+
expect(new AsYouType('US').input('2133734')).to.equal('(213) 373-4')
|
|
93
93
|
|
|
94
94
|
// US national number retains national prefix.
|
|
95
|
-
new AsYouType('US').input('12133734').
|
|
95
|
+
expect(new AsYouType('US').input('12133734')).to.equal('1 (213) 373-4')
|
|
96
96
|
|
|
97
97
|
// US national number retains national prefix (full number).
|
|
98
|
-
new AsYouType('US').input('12133734253').
|
|
98
|
+
expect(new AsYouType('US').input('12133734253')).to.equal('1 (213) 373-4253')
|
|
99
99
|
|
|
100
100
|
let formatter
|
|
101
101
|
|
|
@@ -103,65 +103,65 @@ describe('AsYouType', () => {
|
|
|
103
103
|
// new AsYouType('RU').input('8800555353').should.equal('880 055-53-53')
|
|
104
104
|
|
|
105
105
|
// Shouldn't extract national prefix when inputting in international format.
|
|
106
|
-
new AsYouType('RU').input('+7800555353').
|
|
106
|
+
expect(new AsYouType('RU').input('+7800555353')).to.equal('+7 800 555 35 3')
|
|
107
107
|
|
|
108
|
-
new AsYouType('CH').input('044-668-1').
|
|
108
|
+
expect(new AsYouType('CH').input('044-668-1')).to.equal('044 668 1')
|
|
109
109
|
|
|
110
110
|
// Test International phone number (international)
|
|
111
111
|
|
|
112
112
|
formatter = new AsYouType()
|
|
113
113
|
|
|
114
114
|
// formatter.valid.should.be.false
|
|
115
|
-
type(formatter.getCountry()).
|
|
116
|
-
type(formatter.getCountryCallingCode()).
|
|
117
|
-
formatter.getTemplate().
|
|
115
|
+
expect(type(formatter.getCountry())).to.equal('undefined')
|
|
116
|
+
expect(type(formatter.getCountryCallingCode())).to.equal('undefined')
|
|
117
|
+
expect(formatter.getTemplate()).to.equal('')
|
|
118
118
|
|
|
119
|
-
formatter.input('+').
|
|
119
|
+
expect(formatter.input('+')).to.equal('+')
|
|
120
120
|
|
|
121
121
|
// formatter.valid.should.be.false
|
|
122
|
-
type(formatter.getCountry()).
|
|
123
|
-
type(formatter.getCountryCallingCode()).
|
|
124
|
-
formatter.getTemplate().
|
|
122
|
+
expect(type(formatter.getCountry())).to.equal('undefined')
|
|
123
|
+
expect(type(formatter.getCountryCallingCode())).to.equal('undefined')
|
|
124
|
+
expect(formatter.getTemplate()).to.equal('x')
|
|
125
125
|
|
|
126
|
-
formatter.input('1').
|
|
126
|
+
expect(formatter.input('1')).to.equal('+1')
|
|
127
127
|
|
|
128
128
|
// formatter.valid.should.be.false
|
|
129
|
-
type(formatter.getCountry()).
|
|
130
|
-
formatter.getCountryCallingCode().
|
|
131
|
-
formatter.getTemplate().
|
|
129
|
+
expect(type(formatter.getCountry())).to.equal('undefined')
|
|
130
|
+
expect(formatter.getCountryCallingCode()).to.equal('1')
|
|
131
|
+
expect(formatter.getTemplate()).to.equal('xx')
|
|
132
132
|
|
|
133
|
-
formatter.input('2').
|
|
134
|
-
formatter.getTemplate().
|
|
133
|
+
expect(formatter.input('2')).to.equal('+1 2')
|
|
134
|
+
expect(formatter.getTemplate()).to.equal('xx x')
|
|
135
135
|
|
|
136
136
|
// formatter.valid.should.be.false
|
|
137
|
-
type(formatter.getCountry()).
|
|
138
|
-
|
|
139
|
-
formatter.input('1').
|
|
140
|
-
formatter.input('3').
|
|
141
|
-
formatter.input(' ').
|
|
142
|
-
formatter.input('3').
|
|
143
|
-
formatter.input('3').
|
|
144
|
-
formatter.input('3').
|
|
145
|
-
formatter.input('4').
|
|
146
|
-
formatter.input('4').
|
|
147
|
-
formatter.input('4').
|
|
137
|
+
expect(type(formatter.getCountry())).to.equal('undefined')
|
|
138
|
+
|
|
139
|
+
expect(formatter.input('1')).to.equal('+1 21')
|
|
140
|
+
expect(formatter.input('3')).to.equal('+1 213')
|
|
141
|
+
expect(formatter.input(' ')).to.equal('+1 213')
|
|
142
|
+
expect(formatter.input('3')).to.equal('+1 213 3')
|
|
143
|
+
expect(formatter.input('3')).to.equal('+1 213 33')
|
|
144
|
+
expect(formatter.input('3')).to.equal('+1 213 333')
|
|
145
|
+
expect(formatter.input('4')).to.equal('+1 213 333 4')
|
|
146
|
+
expect(formatter.input('4')).to.equal('+1 213 333 44')
|
|
147
|
+
expect(formatter.input('4')).to.equal('+1 213 333 444')
|
|
148
148
|
|
|
149
149
|
// formatter.valid.should.be.false
|
|
150
|
-
type(formatter.getCountry()).
|
|
150
|
+
expect(type(formatter.getCountry())).to.equal('undefined')
|
|
151
151
|
|
|
152
|
-
formatter.input('4').
|
|
152
|
+
expect(formatter.input('4')).to.equal('+1 213 333 4444')
|
|
153
153
|
|
|
154
154
|
// formatter.valid.should.be.true
|
|
155
|
-
formatter.getCountry().
|
|
155
|
+
expect(formatter.getCountry()).to.equal('US')
|
|
156
156
|
// This one below contains "punctuation spaces"
|
|
157
157
|
// along with the regular spaces
|
|
158
|
-
formatter.getTemplate().
|
|
158
|
+
expect(formatter.getTemplate()).to.equal('xx xxx xxx xxxx')
|
|
159
159
|
|
|
160
|
-
formatter.input('5').
|
|
160
|
+
expect(formatter.input('5')).to.equal('+1 21333344445')
|
|
161
161
|
|
|
162
162
|
// formatter.valid.should.be.false
|
|
163
163
|
expect(formatter.getCountry()).to.be.undefined
|
|
164
|
-
formatter.getCountryCallingCode().
|
|
164
|
+
expect(formatter.getCountryCallingCode()).to.equal('1')
|
|
165
165
|
expect(formatter.formatter.template).to.be.undefined
|
|
166
166
|
|
|
167
167
|
// Check that clearing an international formatter
|
|
@@ -169,44 +169,44 @@ describe('AsYouType', () => {
|
|
|
169
169
|
|
|
170
170
|
formatter.reset()
|
|
171
171
|
|
|
172
|
-
formatter.input('+').
|
|
173
|
-
formatter.input('7').
|
|
174
|
-
formatter.input('9').
|
|
175
|
-
formatter.input('99 111 22 33').
|
|
172
|
+
expect(formatter.input('+')).to.equal('+')
|
|
173
|
+
expect(formatter.input('7')).to.equal('+7')
|
|
174
|
+
expect(formatter.input('9')).to.equal('+7 9')
|
|
175
|
+
expect(formatter.input('99 111 22 33')).to.equal('+7 999 111 22 33')
|
|
176
176
|
|
|
177
177
|
// Test Switzerland phone numbers
|
|
178
178
|
|
|
179
179
|
formatter = new AsYouType('CH')
|
|
180
180
|
|
|
181
|
-
formatter.input(' ').
|
|
182
|
-
formatter.input('0').
|
|
183
|
-
formatter.input('4').
|
|
184
|
-
formatter.input(' ').
|
|
185
|
-
formatter.input('-').
|
|
186
|
-
formatter.input('4').
|
|
187
|
-
formatter.input('-').
|
|
188
|
-
formatter.input('6').
|
|
189
|
-
formatter.input('6').
|
|
190
|
-
formatter.input('8').
|
|
191
|
-
formatter.input('-').
|
|
192
|
-
formatter.input('1').
|
|
193
|
-
formatter.input('8').
|
|
181
|
+
expect(formatter.input(' ')).to.equal('')
|
|
182
|
+
expect(formatter.input('0')).to.equal('0')
|
|
183
|
+
expect(formatter.input('4')).to.equal('04')
|
|
184
|
+
expect(formatter.input(' ')).to.equal('04')
|
|
185
|
+
expect(formatter.input('-')).to.equal('04')
|
|
186
|
+
expect(formatter.input('4')).to.equal('044')
|
|
187
|
+
expect(formatter.input('-')).to.equal('044')
|
|
188
|
+
expect(formatter.input('6')).to.equal('044 6')
|
|
189
|
+
expect(formatter.input('6')).to.equal('044 66')
|
|
190
|
+
expect(formatter.input('8')).to.equal('044 668')
|
|
191
|
+
expect(formatter.input('-')).to.equal('044 668')
|
|
192
|
+
expect(formatter.input('1')).to.equal('044 668 1')
|
|
193
|
+
expect(formatter.input('8')).to.equal('044 668 18')
|
|
194
194
|
|
|
195
195
|
// formatter.valid.should.be.false
|
|
196
|
-
formatter.getCountry().
|
|
197
|
-
formatter.formatter.template.
|
|
198
|
-
formatter.getTemplate().
|
|
196
|
+
expect(formatter.getCountry()).to.equal('CH')
|
|
197
|
+
expect(formatter.formatter.template).to.equal('xxx xxx xx xx')
|
|
198
|
+
expect(formatter.getTemplate()).to.equal('xxx xxx xx')
|
|
199
199
|
|
|
200
|
-
formatter.input(' 00').
|
|
200
|
+
expect(formatter.input(' 00')).to.equal('044 668 18 00')
|
|
201
201
|
|
|
202
202
|
// formatter.valid.should.be.true
|
|
203
|
-
formatter.getCountry().
|
|
204
|
-
formatter.getTemplate().
|
|
203
|
+
expect(formatter.getCountry()).to.equal('CH')
|
|
204
|
+
expect(formatter.getTemplate()).to.equal('xxx xxx xx xx')
|
|
205
205
|
|
|
206
|
-
formatter.input('9').
|
|
206
|
+
expect(formatter.input('9')).to.equal('04466818009')
|
|
207
207
|
|
|
208
208
|
// formatter.valid.should.be.false
|
|
209
|
-
formatter.getCountry().
|
|
209
|
+
expect(formatter.getCountry()).to.equal('CH')
|
|
210
210
|
expect(formatter.formatter.template).to.be.undefined
|
|
211
211
|
|
|
212
212
|
// Kazakhstan (non-main country for +7 country phone code)
|
|
@@ -214,45 +214,45 @@ describe('AsYouType', () => {
|
|
|
214
214
|
formatter = new AsYouType()
|
|
215
215
|
|
|
216
216
|
formatter.input('+77172580659')
|
|
217
|
-
formatter.getCountry().
|
|
217
|
+
expect(formatter.getCountry()).to.equal('KZ')
|
|
218
218
|
|
|
219
219
|
// Brazil
|
|
220
220
|
|
|
221
221
|
formatter = new AsYouType('BR')
|
|
222
|
-
formatter.input('11987654321').
|
|
222
|
+
expect(formatter.input('11987654321')).to.equal('(11) 98765-4321')
|
|
223
223
|
|
|
224
224
|
// UK (Jersey) (non-main country for +44 country phone code)
|
|
225
225
|
|
|
226
226
|
formatter = new AsYouType()
|
|
227
|
-
formatter.input('+447700300000').
|
|
228
|
-
formatter.getTemplate().
|
|
229
|
-
formatter.getCountry().
|
|
227
|
+
expect(formatter.input('+447700300000')).to.equal('+44 7700 300000')
|
|
228
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx xxxxxx')
|
|
229
|
+
expect(formatter.getCountry()).to.equal('JE')
|
|
230
230
|
|
|
231
231
|
// Braces must be part of the template.
|
|
232
232
|
formatter = new AsYouType('RU')
|
|
233
|
-
formatter.input('88005553535').
|
|
234
|
-
formatter.getTemplate().
|
|
233
|
+
expect(formatter.input('88005553535')).to.equal('8 (800) 555-35-35')
|
|
234
|
+
expect(formatter.getTemplate()).to.equal('x (xxx) xxx-xx-xx')
|
|
235
235
|
|
|
236
236
|
// Test Russian phone numbers
|
|
237
237
|
// (with optional national prefix `8`)
|
|
238
238
|
|
|
239
239
|
formatter = new AsYouType('RU')
|
|
240
240
|
|
|
241
|
-
formatter.input('8').
|
|
242
|
-
formatter.input('9').
|
|
243
|
-
formatter.input('9').
|
|
244
|
-
formatter.input('9').
|
|
245
|
-
formatter.input('-').
|
|
246
|
-
formatter.input('1234').
|
|
247
|
-
formatter.input('567').
|
|
248
|
-
formatter.input('8').
|
|
241
|
+
expect(formatter.input('8')).to.equal('8')
|
|
242
|
+
expect(formatter.input('9')).to.equal('8 9')
|
|
243
|
+
expect(formatter.input('9')).to.equal('8 99')
|
|
244
|
+
expect(formatter.input('9')).to.equal('8 (999)')
|
|
245
|
+
expect(formatter.input('-')).to.equal('8 (999)')
|
|
246
|
+
expect(formatter.input('1234')).to.equal('8 (999) 123-4')
|
|
247
|
+
expect(formatter.input('567')).to.equal('8 (999) 123-45-67')
|
|
248
|
+
expect(formatter.input('8')).to.equal('899912345678')
|
|
249
249
|
|
|
250
250
|
// Shouldn't strip national prefix if it is optional
|
|
251
251
|
// and if it's a valid phone number (international).
|
|
252
252
|
formatter = new AsYouType('RU')
|
|
253
253
|
// formatter.input('8005553535').should.equal('(800) 555-35-35')
|
|
254
|
-
formatter.input('+78005553535').
|
|
255
|
-
formatter.getNationalNumber().
|
|
254
|
+
expect(formatter.input('+78005553535')).to.equal('+7 800 555 35 35')
|
|
255
|
+
expect(formatter.getNationalNumber()).to.equal('8005553535')
|
|
256
256
|
|
|
257
257
|
// Check that clearing an national formatter:
|
|
258
258
|
// * doesn't clear country metadata
|
|
@@ -260,41 +260,41 @@ describe('AsYouType', () => {
|
|
|
260
260
|
|
|
261
261
|
formatter.reset()
|
|
262
262
|
|
|
263
|
-
formatter.input('8').
|
|
264
|
-
formatter.input('9').
|
|
265
|
-
formatter.input('9').
|
|
266
|
-
formatter.input('9').
|
|
267
|
-
formatter.input('-').
|
|
268
|
-
formatter.input('1234').
|
|
269
|
-
formatter.input('567').
|
|
270
|
-
formatter.input('8').
|
|
263
|
+
expect(formatter.input('8')).to.equal('8')
|
|
264
|
+
expect(formatter.input('9')).to.equal('8 9')
|
|
265
|
+
expect(formatter.input('9')).to.equal('8 99')
|
|
266
|
+
expect(formatter.input('9')).to.equal('8 (999)')
|
|
267
|
+
expect(formatter.input('-')).to.equal('8 (999)')
|
|
268
|
+
expect(formatter.input('1234')).to.equal('8 (999) 123-4')
|
|
269
|
+
expect(formatter.input('567')).to.equal('8 (999) 123-45-67')
|
|
270
|
+
expect(formatter.input('8')).to.equal('899912345678')
|
|
271
271
|
|
|
272
272
|
// National prefix should not be prepended
|
|
273
273
|
// when formatting local NANPA phone numbers.
|
|
274
|
-
new AsYouType('US').input('1').
|
|
275
|
-
new AsYouType('US').input('12').
|
|
276
|
-
new AsYouType('US').input('123').
|
|
274
|
+
expect(new AsYouType('US').input('1')).to.equal('1')
|
|
275
|
+
expect(new AsYouType('US').input('12')).to.equal('1 2')
|
|
276
|
+
expect(new AsYouType('US').input('123')).to.equal('1 23')
|
|
277
277
|
|
|
278
278
|
// Bulgaria
|
|
279
279
|
// (should not prepend national prefix `0`)
|
|
280
|
-
new AsYouType('BG').input('111 222 3').
|
|
280
|
+
expect(new AsYouType('BG').input('111 222 3')).to.equal('1112223')
|
|
281
281
|
|
|
282
282
|
// Deutchland
|
|
283
|
-
new AsYouType().input('+4915539898001').
|
|
283
|
+
expect(new AsYouType().input('+4915539898001')).to.equal('+49 15539 898001')
|
|
284
284
|
|
|
285
285
|
// KZ detection
|
|
286
286
|
formatter = new AsYouType()
|
|
287
287
|
formatter.input('+7 702 211 1111')
|
|
288
|
-
formatter.getCountry().
|
|
288
|
+
expect(formatter.getCountry()).to.equal('KZ')
|
|
289
289
|
// formatter.valid.should.equal(true)
|
|
290
290
|
|
|
291
291
|
// New Zealand formatting fix (issue #89)
|
|
292
|
-
new AsYouType('NZ').input('0212').
|
|
292
|
+
expect(new AsYouType('NZ').input('0212')).to.equal('021 2')
|
|
293
293
|
|
|
294
294
|
// South Korea
|
|
295
295
|
formatter = new AsYouType()
|
|
296
|
-
formatter.input('+82111111111').
|
|
297
|
-
formatter.getTemplate().
|
|
296
|
+
expect(formatter.input('+82111111111')).to.equal('+82 11 111 1111')
|
|
297
|
+
expect(formatter.getTemplate()).to.equal('xxx xx xxx xxxx')
|
|
298
298
|
})
|
|
299
299
|
|
|
300
300
|
it('should filter out formats that require a national prefix and no national prefix has been input', () => {
|
|
@@ -303,12 +303,12 @@ describe('AsYouType', () => {
|
|
|
303
303
|
|
|
304
304
|
// No national prefix, and national prefix is required in the format.
|
|
305
305
|
// (not `"national_prefix_is_optional_when_formatting": true`)
|
|
306
|
-
formatter.input('44444444').
|
|
306
|
+
expect(formatter.input('44444444')).to.equal('44444444')
|
|
307
307
|
expect(formatter.formatter.template).to.be.undefined
|
|
308
308
|
|
|
309
309
|
// With national prefix
|
|
310
|
-
formatter.reset().input('044444444').
|
|
311
|
-
formatter.formatter.template.
|
|
310
|
+
expect(formatter.reset().input('044444444')).to.equal('044 444 444')
|
|
311
|
+
expect(formatter.formatter.template).to.equal('xxx xxx xxxx')
|
|
312
312
|
})
|
|
313
313
|
|
|
314
314
|
it('should work when a digit is not a national prefix but a part of a valid national number', () => {
|
|
@@ -330,43 +330,43 @@ describe('AsYouType', () => {
|
|
|
330
330
|
// in Russia, people are used to inputting `800` numbers with national prefix `8`:
|
|
331
331
|
// `8 800 555 35 35`.
|
|
332
332
|
// formatter.input('8005553535').should.equal('(800) 555-35-35')
|
|
333
|
-
formatter.input('8005553535').
|
|
333
|
+
expect(formatter.input('8005553535')).to.equal('8005553535')
|
|
334
334
|
formatter.reset()
|
|
335
|
-
formatter.input('+78005553535').
|
|
335
|
+
expect(formatter.input('+78005553535')).to.equal('+7 800 555 35 35')
|
|
336
336
|
})
|
|
337
337
|
|
|
338
338
|
it('should match formats that require a national prefix and no national prefix has been input (national prefix is mandatory for a format)', () => {
|
|
339
339
|
const formatter = new AsYouType('FR')
|
|
340
|
-
formatter.input('612345678').
|
|
340
|
+
expect(formatter.input('612345678')).to.equal('612345678')
|
|
341
341
|
formatter.reset()
|
|
342
|
-
formatter.input('0612345678').
|
|
342
|
+
expect(formatter.input('0612345678')).to.equal('06 12 34 56 78')
|
|
343
343
|
})
|
|
344
344
|
|
|
345
345
|
it('should match formats that require a national prefix and no national prefix has been input (national prefix is not mandatory for a format)', () => {
|
|
346
346
|
const formatter = new AsYouType('RU')
|
|
347
347
|
// Without national prefix.
|
|
348
|
-
formatter.input('9991234567').
|
|
348
|
+
expect(formatter.input('9991234567')).to.equal('999 123-45-67')
|
|
349
349
|
formatter.reset()
|
|
350
350
|
// With national prefix.
|
|
351
|
-
formatter.input('89991234567').
|
|
351
|
+
expect(formatter.input('89991234567')).to.equal('8 (999) 123-45-67')
|
|
352
352
|
})
|
|
353
353
|
|
|
354
354
|
it('should not use `national_prefix_formatting_rule` when formatting international phone numbers', () => {
|
|
355
355
|
// Brazil.
|
|
356
356
|
// `national_prefix_formatting_rule` is `($1)`.
|
|
357
357
|
// Should not add braces around `12` when being input in international format.
|
|
358
|
-
new AsYouType().input('+55123456789').
|
|
359
|
-
new AsYouType('BR').input('+55123456789').
|
|
360
|
-
new AsYouType('BR').input('123456789').
|
|
358
|
+
expect(new AsYouType().input('+55123456789')).to.equal('+55 12 3456 789')
|
|
359
|
+
expect(new AsYouType('BR').input('+55123456789')).to.equal('+55 12 3456 789')
|
|
360
|
+
expect(new AsYouType('BR').input('123456789')).to.equal('(12) 3456-789')
|
|
361
361
|
})
|
|
362
362
|
|
|
363
363
|
it('should support incorrectly entered international phone numbers (with a national prefix)', () => {
|
|
364
364
|
let formatter
|
|
365
365
|
|
|
366
366
|
formatter = new AsYouType()
|
|
367
|
-
formatter.input('+1 1 877 215 5230').
|
|
367
|
+
expect(formatter.input('+1 1 877 215 5230')).to.equal('+1 1 877 215 5230')
|
|
368
368
|
// formatter.input('+1 1 877 215 5230').should.equal('+1 1 8772155230')
|
|
369
|
-
formatter.getNationalNumber().
|
|
369
|
+
expect(formatter.getNationalNumber()).to.equal('8772155230')
|
|
370
370
|
|
|
371
371
|
// They've added another number format that has `8` leading digit
|
|
372
372
|
// and 14 digits. Maybe it's something related to Kazakhstan.
|
|
@@ -379,39 +379,39 @@ describe('AsYouType', () => {
|
|
|
379
379
|
it('should return a partial template for current value', () => {
|
|
380
380
|
const asYouType = new AsYouType('US')
|
|
381
381
|
|
|
382
|
-
asYouType.input('').
|
|
383
|
-
asYouType.getTemplate().
|
|
382
|
+
expect(asYouType.input('')).to.equal('')
|
|
383
|
+
expect(asYouType.getTemplate()).to.equal('')
|
|
384
384
|
|
|
385
|
-
asYouType.input('2').
|
|
385
|
+
expect(asYouType.input('2')).to.equal('2')
|
|
386
386
|
// asYouType.getTemplate().should.equal('x')
|
|
387
387
|
// Doesn't format for a single digit.
|
|
388
|
-
asYouType.getTemplate().
|
|
388
|
+
expect(asYouType.getTemplate()).to.equal('x')
|
|
389
389
|
|
|
390
|
-
asYouType.input('1').
|
|
391
|
-
asYouType.getTemplate().
|
|
390
|
+
expect(asYouType.input('1')).to.equal('21')
|
|
391
|
+
expect(asYouType.getTemplate()).to.equal('xx')
|
|
392
392
|
|
|
393
|
-
asYouType.input('3').
|
|
394
|
-
asYouType.getTemplate().
|
|
393
|
+
expect(asYouType.input('3')).to.equal('(213)')
|
|
394
|
+
expect(asYouType.getTemplate()).to.equal('(xxx)')
|
|
395
395
|
})
|
|
396
396
|
|
|
397
397
|
it(`should fall back to the default country`, () => {
|
|
398
398
|
const formatter = new AsYouType('RU')
|
|
399
399
|
|
|
400
|
-
formatter.input('8').
|
|
401
|
-
formatter.input('9').
|
|
402
|
-
formatter.input('9').
|
|
403
|
-
formatter.input('9').
|
|
400
|
+
expect(formatter.input('8')).to.equal('8')
|
|
401
|
+
expect(formatter.input('9')).to.equal('8 9')
|
|
402
|
+
expect(formatter.input('9')).to.equal('8 99')
|
|
403
|
+
expect(formatter.input('9')).to.equal('8 (999)')
|
|
404
404
|
|
|
405
405
|
// formatter.valid.should.be.false
|
|
406
|
-
formatter.formatter.template.
|
|
407
|
-
formatter.getCountry().
|
|
406
|
+
expect(formatter.formatter.template).to.equal('x (xxx) xxx-xx-xx')
|
|
407
|
+
expect(formatter.getCountry()).to.equal('RU')
|
|
408
408
|
// formatter.getCountryCallingCode().should.equal('7')
|
|
409
409
|
|
|
410
|
-
formatter.input('000000000000').
|
|
410
|
+
expect(formatter.input('000000000000')).to.equal('8999000000000000')
|
|
411
411
|
|
|
412
412
|
// formatter.valid.should.be.false
|
|
413
413
|
expect(formatter.formatter.template).to.be.undefined
|
|
414
|
-
formatter.getCountry().
|
|
414
|
+
expect(formatter.getCountry()).to.equal('RU')
|
|
415
415
|
// formatter.getCountryCallingCode().should.equal('7')
|
|
416
416
|
|
|
417
417
|
formatter.reset()
|
|
@@ -421,12 +421,12 @@ describe('AsYouType', () => {
|
|
|
421
421
|
expect(formatter.getCountry()).to.be.undefined
|
|
422
422
|
// formatter.getCountryCallingCode().should.equal('7')
|
|
423
423
|
|
|
424
|
-
formatter.input('+1-213-373-4253').
|
|
424
|
+
expect(formatter.input('+1-213-373-4253')).to.equal('+1 213 373 4253')
|
|
425
425
|
|
|
426
426
|
// formatter.valid.should.be.true
|
|
427
|
-
formatter.getTemplate().
|
|
428
|
-
formatter.getCountry().
|
|
429
|
-
formatter.getCountryCallingCode().
|
|
427
|
+
expect(formatter.getTemplate()).to.equal('xx xxx xxx xxxx')
|
|
428
|
+
expect(formatter.getCountry()).to.equal('US')
|
|
429
|
+
expect(formatter.getCountryCallingCode()).to.equal('1')
|
|
430
430
|
})
|
|
431
431
|
|
|
432
432
|
it('should work in edge cases', () => {
|
|
@@ -435,53 +435,53 @@ describe('AsYouType', () => {
|
|
|
435
435
|
|
|
436
436
|
// No metadata
|
|
437
437
|
thrower = () => new AsYouType_('RU')
|
|
438
|
-
thrower.
|
|
438
|
+
expect(thrower).to.throw('`metadata` argument not passed')
|
|
439
439
|
|
|
440
440
|
// Second '+' sign
|
|
441
441
|
|
|
442
442
|
formatter = new AsYouType('RU')
|
|
443
443
|
|
|
444
|
-
formatter.input('+').
|
|
445
|
-
formatter.input('7').
|
|
446
|
-
formatter.input('+').
|
|
444
|
+
expect(formatter.input('+')).to.equal('+')
|
|
445
|
+
expect(formatter.input('7')).to.equal('+7')
|
|
446
|
+
expect(formatter.input('+')).to.equal('+7')
|
|
447
447
|
|
|
448
448
|
// Out-of-position '+' sign
|
|
449
449
|
|
|
450
450
|
formatter = new AsYouType('RU')
|
|
451
451
|
|
|
452
|
-
formatter.input('8').
|
|
453
|
-
formatter.input('+').
|
|
452
|
+
expect(formatter.input('8')).to.equal('8')
|
|
453
|
+
expect(formatter.input('+')).to.equal('8')
|
|
454
454
|
|
|
455
455
|
// No format matched
|
|
456
456
|
|
|
457
457
|
formatter = new AsYouType('RU')
|
|
458
458
|
|
|
459
|
-
formatter.input('88005553535').
|
|
460
|
-
formatter.input('0').
|
|
459
|
+
expect(formatter.input('88005553535')).to.equal('8 (800) 555-35-35')
|
|
460
|
+
expect(formatter.input('0')).to.equal('880055535350')
|
|
461
461
|
|
|
462
462
|
// Invalid country phone code
|
|
463
463
|
|
|
464
464
|
formatter = new AsYouType()
|
|
465
465
|
|
|
466
|
-
formatter.input('+0123').
|
|
466
|
+
expect(formatter.input('+0123')).to.equal('+0123')
|
|
467
467
|
|
|
468
468
|
// No country specified and not an international number
|
|
469
469
|
|
|
470
470
|
formatter = new AsYouType()
|
|
471
471
|
|
|
472
|
-
formatter.input('88005553535').
|
|
472
|
+
expect(formatter.input('88005553535')).to.equal('88005553535')
|
|
473
473
|
|
|
474
474
|
// Extract national prefix when no `national_prefix` is set
|
|
475
475
|
|
|
476
476
|
formatter = new AsYouType('AD')
|
|
477
477
|
|
|
478
|
-
formatter.input('155555').
|
|
478
|
+
expect(formatter.input('155555')).to.equal('155 555')
|
|
479
479
|
|
|
480
480
|
// Typing nonsense
|
|
481
481
|
|
|
482
482
|
formatter = new AsYouType('RU')
|
|
483
483
|
|
|
484
|
-
formatter.input('+1abc2').
|
|
484
|
+
expect(formatter.input('+1abc2')).to.equal('+1')
|
|
485
485
|
|
|
486
486
|
// Should reset default country when explicitly
|
|
487
487
|
// typing in an international phone number
|
|
@@ -489,8 +489,8 @@ describe('AsYouType', () => {
|
|
|
489
489
|
formatter = new AsYouType('RU')
|
|
490
490
|
|
|
491
491
|
formatter.input('+')
|
|
492
|
-
type(formatter.getCountry()).
|
|
493
|
-
type(formatter.getCountryCallingCode()).
|
|
492
|
+
expect(type(formatter.getCountry())).to.equal('undefined')
|
|
493
|
+
expect(type(formatter.getCountryCallingCode())).to.equal('undefined')
|
|
494
494
|
|
|
495
495
|
// Country not inferrable from the phone number,
|
|
496
496
|
// while the phone number itself can already be formatted "completely".
|
|
@@ -498,16 +498,16 @@ describe('AsYouType', () => {
|
|
|
498
498
|
formatter = new AsYouType()
|
|
499
499
|
|
|
500
500
|
formatter.input('+12223333333')
|
|
501
|
-
type(formatter.getCountry()).
|
|
502
|
-
formatter.getCountryCallingCode().
|
|
501
|
+
expect(type(formatter.getCountry())).to.equal('undefined')
|
|
502
|
+
expect(formatter.getCountryCallingCode()).to.equal('1')
|
|
503
503
|
|
|
504
504
|
// Reset a chosen format when it no longer applies given the new leading digits.
|
|
505
505
|
// If Google changes metadata for England then this test might not cover the case.
|
|
506
506
|
formatter = new AsYouType('GB')
|
|
507
|
-
formatter.input('0845').
|
|
507
|
+
expect(formatter.input('0845')).to.equal('0845')
|
|
508
508
|
// New leading digits don't match the format previously chosen.
|
|
509
509
|
// Reset the format.
|
|
510
|
-
formatter.input('0').
|
|
510
|
+
expect(formatter.input('0')).to.equal('0845 0')
|
|
511
511
|
})
|
|
512
512
|
|
|
513
513
|
it('should choose between matching formats based on the absence or presence of a national prefix', () => {
|
|
@@ -541,7 +541,7 @@ describe('AsYouType', () => {
|
|
|
541
541
|
const formatter = new AsYouType('CN')
|
|
542
542
|
// National prefix has been input.
|
|
543
543
|
// Chooses the first format.
|
|
544
|
-
formatter.input('01010000').
|
|
544
|
+
expect(formatter.input('01010000')).to.equal('010 10000')
|
|
545
545
|
formatter.reset()
|
|
546
546
|
// No national prefix has been input,
|
|
547
547
|
// and `national_prefix_for_parsing` not matched.
|
|
@@ -549,15 +549,15 @@ describe('AsYouType', () => {
|
|
|
549
549
|
// `"national_prefix_is_optional_when_formatting": true`.
|
|
550
550
|
// The second format will match, because it does have
|
|
551
551
|
// `"national_prefix_is_optional_when_formatting": true`.
|
|
552
|
-
formatter.input('1010000').
|
|
552
|
+
expect(formatter.input('1010000')).to.equal('10 1000 0')
|
|
553
553
|
})
|
|
554
554
|
|
|
555
555
|
it('should not accept phone number extensions', () => {
|
|
556
|
-
new AsYouType().input('+1-213-373-4253 ext. 123').
|
|
556
|
+
expect(new AsYouType().input('+1-213-373-4253 ext. 123')).to.equal('+1 213 373 4253')
|
|
557
557
|
})
|
|
558
558
|
|
|
559
559
|
it('should parse non-European digits', () => {
|
|
560
|
-
new AsYouType().input('+١٢١٢٢٣٢٣٢٣٢').
|
|
560
|
+
expect(new AsYouType().input('+١٢١٢٢٣٢٣٢٣٢')).to.equal('+1 212 232 3232')
|
|
561
561
|
})
|
|
562
562
|
|
|
563
563
|
it('should return a PhoneNumber instance', () => {
|
|
@@ -573,17 +573,17 @@ describe('AsYouType', () => {
|
|
|
573
573
|
formatter.input('213-373-4253')
|
|
574
574
|
|
|
575
575
|
let phoneNumber = formatter.getNumber()
|
|
576
|
-
phoneNumber.country.
|
|
577
|
-
phoneNumber.countryCallingCode.
|
|
578
|
-
phoneNumber.number.
|
|
579
|
-
phoneNumber.nationalNumber.
|
|
576
|
+
expect(phoneNumber.country).to.equal('US')
|
|
577
|
+
expect(phoneNumber.countryCallingCode).to.equal('1')
|
|
578
|
+
expect(phoneNumber.number).to.equal('+12133734253')
|
|
579
|
+
expect(phoneNumber.nationalNumber).to.equal('2133734253')
|
|
580
580
|
|
|
581
581
|
formatter.reset()
|
|
582
582
|
formatter.input('+1-113-373-4253')
|
|
583
583
|
|
|
584
584
|
phoneNumber = formatter.getNumber()
|
|
585
585
|
expect(phoneNumber.country).to.be.undefined
|
|
586
|
-
phoneNumber.countryCallingCode.
|
|
586
|
+
expect(phoneNumber.countryCallingCode).to.equal('1')
|
|
587
587
|
|
|
588
588
|
// An incorrect NANPA international phone number.
|
|
589
589
|
// (contains national prefix in an international phone number)
|
|
@@ -610,15 +610,15 @@ describe('AsYouType', () => {
|
|
|
610
610
|
formatter.input('1')
|
|
611
611
|
phoneNumber = formatter.getNumber()
|
|
612
612
|
expect(phoneNumber.country).to.be.undefined
|
|
613
|
-
phoneNumber.countryCallingCode.
|
|
614
|
-
phoneNumber.number.
|
|
613
|
+
expect(phoneNumber.countryCallingCode).to.equal('1')
|
|
614
|
+
expect(phoneNumber.number).to.equal('+11')
|
|
615
615
|
})
|
|
616
616
|
|
|
617
617
|
it('should work with countries that add digits to national (significant) number', () => {
|
|
618
618
|
// When formatting Argentinian mobile numbers in international format,
|
|
619
619
|
// a `9` is prepended, when compared to national format.
|
|
620
620
|
const asYouType = new AsYouType('AR')
|
|
621
|
-
asYouType.input('+5493435551212').
|
|
621
|
+
expect(asYouType.input('+5493435551212')).to.equal('+54 9 3435 55 1212')
|
|
622
622
|
asYouType.reset()
|
|
623
623
|
// Digits shouldn't be changed when formatting in national format.
|
|
624
624
|
// (no `9` is prepended).
|
|
@@ -626,7 +626,7 @@ describe('AsYouType', () => {
|
|
|
626
626
|
// and stripping `15` from it.
|
|
627
627
|
// Then uses `$2 15-$3-$4` format that strips the leading `9`
|
|
628
628
|
// and adds `15`.
|
|
629
|
-
asYouType.input('0343515551212').
|
|
629
|
+
expect(asYouType.input('0343515551212')).to.equal('03435 15-55-1212')
|
|
630
630
|
})
|
|
631
631
|
|
|
632
632
|
it('should return non-formatted phone number when no format matches and national (significant) number has digits added', () => {
|
|
@@ -641,7 +641,7 @@ describe('AsYouType', () => {
|
|
|
641
641
|
// and adds `15`.
|
|
642
642
|
// `this.nationalSignificantNumberMatchesInput` is `false` in this case,
|
|
643
643
|
// so `getNonFormattedNumber()` returns `getFullNumber(getNationalDigits())`.
|
|
644
|
-
asYouType.input('0343515551212999').
|
|
644
|
+
expect(asYouType.input('0343515551212999')).to.equal('0343515551212999')
|
|
645
645
|
})
|
|
646
646
|
|
|
647
647
|
it('should format Argentina numbers (starting with 011) (digit by digit)', () => {
|
|
@@ -652,40 +652,40 @@ describe('AsYouType', () => {
|
|
|
652
652
|
// nextDigits 0111523456789
|
|
653
653
|
// nationalNumber 91123456789
|
|
654
654
|
const formatter = new AsYouType('AR')
|
|
655
|
-
formatter.input('0').
|
|
656
|
-
formatter.getTemplate().
|
|
657
|
-
formatter.input('1').
|
|
658
|
-
formatter.getTemplate().
|
|
659
|
-
formatter.input('1').
|
|
660
|
-
formatter.getTemplate().
|
|
661
|
-
formatter.input('1').
|
|
662
|
-
formatter.getTemplate().
|
|
663
|
-
formatter.input('5').
|
|
664
|
-
formatter.getTemplate().
|
|
665
|
-
formatter.input('2').
|
|
666
|
-
formatter.getTemplate().
|
|
667
|
-
formatter.input('3').
|
|
668
|
-
formatter.getTemplate().
|
|
669
|
-
formatter.input('4').
|
|
670
|
-
formatter.getTemplate().
|
|
671
|
-
formatter.input('5').
|
|
672
|
-
formatter.getTemplate().
|
|
673
|
-
formatter.input('6').
|
|
674
|
-
formatter.getTemplate().
|
|
675
|
-
formatter.input('7').
|
|
676
|
-
formatter.getTemplate().
|
|
677
|
-
formatter.input('8').
|
|
678
|
-
formatter.getTemplate().
|
|
679
|
-
formatter.input('9').
|
|
680
|
-
formatter.getTemplate().
|
|
655
|
+
expect(formatter.input('0')).to.equal('0')
|
|
656
|
+
expect(formatter.getTemplate()).to.equal('x')
|
|
657
|
+
expect(formatter.input('1')).to.equal('01')
|
|
658
|
+
expect(formatter.getTemplate()).to.equal('xx')
|
|
659
|
+
expect(formatter.input('1')).to.equal('011')
|
|
660
|
+
expect(formatter.getTemplate()).to.equal('xxx')
|
|
661
|
+
expect(formatter.input('1')).to.equal('011 1')
|
|
662
|
+
expect(formatter.getTemplate()).to.equal('xxx x')
|
|
663
|
+
expect(formatter.input('5')).to.equal('011 15')
|
|
664
|
+
expect(formatter.getTemplate()).to.equal('xxx xx')
|
|
665
|
+
expect(formatter.input('2')).to.equal('011 152')
|
|
666
|
+
expect(formatter.getTemplate()).to.equal('xxx xxx')
|
|
667
|
+
expect(formatter.input('3')).to.equal('011 1523')
|
|
668
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx')
|
|
669
|
+
expect(formatter.input('4')).to.equal('011 1523-4')
|
|
670
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx-x')
|
|
671
|
+
expect(formatter.input('5')).to.equal('011 1523-45')
|
|
672
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx-xx')
|
|
673
|
+
expect(formatter.input('6')).to.equal('011 1523-456')
|
|
674
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx-xxx')
|
|
675
|
+
expect(formatter.input('7')).to.equal('011 1523-4567')
|
|
676
|
+
expect(formatter.getTemplate()).to.equal('xxx xxxx-xxxx')
|
|
677
|
+
expect(formatter.input('8')).to.equal('011152345678')
|
|
678
|
+
expect(formatter.getTemplate()).to.equal('xxxxxxxxxxxx')
|
|
679
|
+
expect(formatter.input('9')).to.equal('011 15-2345-6789')
|
|
680
|
+
expect(formatter.getTemplate()).to.equal('xxx xx-xxxx-xxxx')
|
|
681
681
|
// Private property (not public API).
|
|
682
|
-
formatter.state.nationalSignificantNumber.
|
|
682
|
+
expect(formatter.state.nationalSignificantNumber).to.equal('91123456789')
|
|
683
683
|
// Private property (not public API).
|
|
684
684
|
// `formatter.digits` is not always `formatter.nationalPrefix`
|
|
685
685
|
// plus `formatter.nationalNumberDigits`.
|
|
686
|
-
formatter.state.nationalPrefix.
|
|
687
|
-
formatter.isPossible().
|
|
688
|
-
formatter.isValid().
|
|
686
|
+
expect(formatter.state.nationalPrefix).to.equal('0')
|
|
687
|
+
expect(formatter.isPossible()).to.equal(true)
|
|
688
|
+
expect(formatter.isValid()).to.equal(true)
|
|
689
689
|
})
|
|
690
690
|
|
|
691
691
|
it('should format Argentina numbers (starting with 011)', () => {
|
|
@@ -696,26 +696,26 @@ describe('AsYouType', () => {
|
|
|
696
696
|
// nextDigits 0111523456789
|
|
697
697
|
// nationalNumber 91123456789
|
|
698
698
|
const formatter = new AsYouType('AR')
|
|
699
|
-
formatter.input('0111523456789').
|
|
699
|
+
expect(formatter.input('0111523456789')).to.equal('011 15-2345-6789')
|
|
700
700
|
// Private property (not public API).
|
|
701
|
-
formatter.state.nationalSignificantNumber.
|
|
701
|
+
expect(formatter.state.nationalSignificantNumber).to.equal('91123456789')
|
|
702
702
|
// Private property (not public API).
|
|
703
703
|
// `formatter.digits` is not always `formatter.nationalPrefix`
|
|
704
704
|
// plus `formatter.nationalNumberDigits`.
|
|
705
705
|
expect(formatter.state.nationalPrefix).to.equal('0')
|
|
706
706
|
// expect(formatter.nationalPrefix).to.be.undefined
|
|
707
|
-
formatter.isPossible().
|
|
708
|
-
formatter.isValid().
|
|
707
|
+
expect(formatter.isPossible()).to.equal(true)
|
|
708
|
+
expect(formatter.isValid()).to.equal(true)
|
|
709
709
|
})
|
|
710
710
|
|
|
711
711
|
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/93
|
|
712
712
|
it('should format Indonesian numbers', () => {
|
|
713
713
|
const formatter = new AsYouType('ID')
|
|
714
|
-
formatter.getChars().
|
|
714
|
+
expect(formatter.getChars()).to.equal('')
|
|
715
715
|
// Before leading digits < 3 matching was implemented:
|
|
716
716
|
// formatter.input('081').should.equal('(081)')
|
|
717
717
|
// After leading digits < 3 matching was implemented:
|
|
718
|
-
formatter.input('081').
|
|
718
|
+
expect(formatter.input('081')).to.equal('081')
|
|
719
719
|
})
|
|
720
720
|
|
|
721
721
|
it('should prepend `complexPrefixBeforeNationalSignificantNumber` (not a complete number)', () => {
|
|
@@ -723,14 +723,14 @@ describe('AsYouType', () => {
|
|
|
723
723
|
// National prefix is either not used in a format or is optional.
|
|
724
724
|
// Input phone number without a national prefix.
|
|
725
725
|
const formatter = new AsYouType('AU')
|
|
726
|
-
formatter.input('1831130345678').
|
|
726
|
+
expect(formatter.input('1831130345678')).to.equal('1831 1303 456 78')
|
|
727
727
|
// Private property (not public API).
|
|
728
|
-
formatter.state.nationalSignificantNumber.
|
|
728
|
+
expect(formatter.state.nationalSignificantNumber).to.equal('130345678')
|
|
729
729
|
// Private property (not public API).
|
|
730
730
|
// `formatter.digits` is not always `formatter.nationalPrefix`
|
|
731
731
|
// plus `formatter.nationalNumberDigits`.
|
|
732
732
|
expect(formatter.state.nationalPrefix).to.be.undefined
|
|
733
|
-
formatter.state.complexPrefixBeforeNationalSignificantNumber.
|
|
733
|
+
expect(formatter.state.complexPrefixBeforeNationalSignificantNumber).to.equal('1831')
|
|
734
734
|
})
|
|
735
735
|
|
|
736
736
|
it('should prepend `complexPrefixBeforeNationalSignificantNumber` (complete number)', () => {
|
|
@@ -738,22 +738,22 @@ describe('AsYouType', () => {
|
|
|
738
738
|
// National prefix is either not used in a format or is optional.
|
|
739
739
|
// Input phone number without a national prefix.
|
|
740
740
|
const formatter = new AsYouType('AU')
|
|
741
|
-
formatter.input('18311303456789').
|
|
741
|
+
expect(formatter.input('18311303456789')).to.equal('1831 1303 456 789')
|
|
742
742
|
// Private property (not public API).
|
|
743
|
-
formatter.state.nationalSignificantNumber.
|
|
743
|
+
expect(formatter.state.nationalSignificantNumber).to.equal('1303456789')
|
|
744
744
|
// Private property (not public API).
|
|
745
745
|
// `formatter.digits` is not always `formatter.nationalPrefix`
|
|
746
746
|
// plus `formatter.nationalNumberDigits`.
|
|
747
747
|
expect(formatter.state.nationalPrefix).to.be.undefined
|
|
748
|
-
formatter.state.complexPrefixBeforeNationalSignificantNumber.
|
|
748
|
+
expect(formatter.state.complexPrefixBeforeNationalSignificantNumber).to.equal('1831')
|
|
749
749
|
})
|
|
750
750
|
|
|
751
751
|
it('should work with Mexico numbers', () => {
|
|
752
752
|
const asYouType = new AsYouType('MX')
|
|
753
753
|
|
|
754
754
|
// Fixed line. International.
|
|
755
|
-
asYouType.input('+52(449)978-000').
|
|
756
|
-
asYouType.input('1').
|
|
755
|
+
expect(asYouType.input('+52(449)978-000')).to.equal('+52 449 978 000')
|
|
756
|
+
expect(asYouType.input('1')).to.equal('+52 449 978 0001')
|
|
757
757
|
asYouType.reset()
|
|
758
758
|
|
|
759
759
|
// "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
|
|
@@ -766,15 +766,15 @@ describe('AsYouType', () => {
|
|
|
766
766
|
// asYouType.reset()
|
|
767
767
|
|
|
768
768
|
// Fixed line. National. Without national prefix.
|
|
769
|
-
asYouType.input('(449)978-000').
|
|
770
|
-
asYouType.getTemplate().
|
|
771
|
-
asYouType.input('1').
|
|
772
|
-
asYouType.getTemplate().
|
|
769
|
+
expect(asYouType.input('(449)978-000')).to.equal('449 978 000')
|
|
770
|
+
expect(asYouType.getTemplate()).to.equal('xxx xxx xxx')
|
|
771
|
+
expect(asYouType.input('1')).to.equal('449 978 0001')
|
|
772
|
+
expect(asYouType.getTemplate()).to.equal('xxx xxx xxxx')
|
|
773
773
|
asYouType.reset()
|
|
774
774
|
|
|
775
775
|
// Mobile.
|
|
776
|
-
asYouType.input('+52331234567').
|
|
777
|
-
asYouType.input('8').
|
|
776
|
+
expect(asYouType.input('+52331234567')).to.equal('+52 33 1234 567')
|
|
777
|
+
expect(asYouType.input('8')).to.equal('+52 33 1234 5678')
|
|
778
778
|
asYouType.reset()
|
|
779
779
|
|
|
780
780
|
// "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
|
|
@@ -806,8 +806,8 @@ describe('AsYouType', () => {
|
|
|
806
806
|
// "national_prefix_formatting_rule": "8 $1"
|
|
807
807
|
// That `national_prefix_formatting_rule` isn't used
|
|
808
808
|
// because the user didn't input national prefix `8`.
|
|
809
|
-
formatter.input('0800123').
|
|
810
|
-
formatter.getTemplate().
|
|
809
|
+
expect(formatter.input('0800123')).to.equal('0 800 123')
|
|
810
|
+
expect(formatter.getTemplate()).to.equal('x xxx xxx')
|
|
811
811
|
})
|
|
812
812
|
|
|
813
813
|
it('should not duplicate area code for certain countries', () => {
|
|
@@ -816,14 +816,14 @@ describe('AsYouType', () => {
|
|
|
816
816
|
// Even though `parse("3406934")` would return a
|
|
817
817
|
// "(340) 340-6934" national number, still
|
|
818
818
|
// "As You Type" formatter should leave it as "(340) 6934".
|
|
819
|
-
asYouType.input('340693').
|
|
820
|
-
asYouType.input('4').
|
|
821
|
-
asYouType.input('123').
|
|
819
|
+
expect(asYouType.input('340693')).to.equal('(340) 693')
|
|
820
|
+
expect(asYouType.input('4')).to.equal('(340) 693-4')
|
|
821
|
+
expect(asYouType.input('123')).to.equal('(340) 693-4123')
|
|
822
822
|
})
|
|
823
823
|
|
|
824
824
|
it('shouldn\'t throw when passed a non-existent default country', () => {
|
|
825
|
-
new AsYouType('XX').input('+78005553535').
|
|
826
|
-
new AsYouType('XX').input('88005553535').
|
|
825
|
+
expect(new AsYouType('XX').input('+78005553535')).to.equal('+7 800 555 35 35')
|
|
826
|
+
expect(new AsYouType('XX').input('88005553535')).to.equal('88005553535')
|
|
827
827
|
})
|
|
828
828
|
|
|
829
829
|
it('should parse carrier codes', () => {
|
|
@@ -831,7 +831,7 @@ describe('AsYouType', () => {
|
|
|
831
831
|
|
|
832
832
|
formatter.input('0 15 21 5555-5555')
|
|
833
833
|
let phoneNumber = formatter.getNumber()
|
|
834
|
-
phoneNumber.carrierCode.
|
|
834
|
+
expect(phoneNumber.carrierCode).to.equal('15')
|
|
835
835
|
|
|
836
836
|
formatter.reset()
|
|
837
837
|
formatter.input('+1-213-373-4253')
|
|
@@ -841,9 +841,9 @@ describe('AsYouType', () => {
|
|
|
841
841
|
|
|
842
842
|
it('should format when default country calling code is configured', () => {
|
|
843
843
|
const formatter = new AsYouType({ defaultCallingCode: '7' })
|
|
844
|
-
formatter.input('88005553535').
|
|
845
|
-
formatter.getNumber().countryCallingCode.
|
|
846
|
-
formatter.getNumber().country.
|
|
844
|
+
expect(formatter.input('88005553535')).to.equal('8 (800) 555-35-35')
|
|
845
|
+
expect(formatter.getNumber().countryCallingCode).to.equal('7')
|
|
846
|
+
expect(formatter.getNumber().country).to.equal('RU')
|
|
847
847
|
})
|
|
848
848
|
|
|
849
849
|
it('shouldn\'t return PhoneNumber if country calling code hasn\'t been input yet', () => {
|
|
@@ -854,70 +854,70 @@ describe('AsYouType', () => {
|
|
|
854
854
|
|
|
855
855
|
it('should format non-geographic numbering plan phone numbers', () => {
|
|
856
856
|
const formatter = new AsYouType()
|
|
857
|
-
formatter.input('+').
|
|
858
|
-
formatter.input('8').
|
|
859
|
-
formatter.input('7').
|
|
857
|
+
expect(formatter.input('+')).to.equal('+')
|
|
858
|
+
expect(formatter.input('8')).to.equal('+8')
|
|
859
|
+
expect(formatter.input('7')).to.equal('+87')
|
|
860
860
|
expect(formatter.getCountry()).to.be.undefined
|
|
861
|
-
formatter.input('0').
|
|
861
|
+
expect(formatter.input('0')).to.equal('+870')
|
|
862
862
|
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
863
|
-
formatter.getCountry().
|
|
863
|
+
expect(formatter.getCountry()).to.equal('001')
|
|
864
864
|
} else {
|
|
865
865
|
expect(formatter.getCountry()).to.be.undefined
|
|
866
866
|
}
|
|
867
|
-
formatter.input('7').
|
|
868
|
-
formatter.input('7').
|
|
869
|
-
formatter.input('3').
|
|
870
|
-
formatter.input('1').
|
|
871
|
-
formatter.input('1').
|
|
872
|
-
formatter.input('1').
|
|
873
|
-
formatter.input('6').
|
|
874
|
-
formatter.input('3').
|
|
875
|
-
formatter.input('2').
|
|
867
|
+
expect(formatter.input('7')).to.equal('+870 7')
|
|
868
|
+
expect(formatter.input('7')).to.equal('+870 77')
|
|
869
|
+
expect(formatter.input('3')).to.equal('+870 773')
|
|
870
|
+
expect(formatter.input('1')).to.equal('+870 773 1')
|
|
871
|
+
expect(formatter.input('1')).to.equal('+870 773 11')
|
|
872
|
+
expect(formatter.input('1')).to.equal('+870 773 111')
|
|
873
|
+
expect(formatter.input('6')).to.equal('+870 773 111 6')
|
|
874
|
+
expect(formatter.input('3')).to.equal('+870 773 111 63')
|
|
875
|
+
expect(formatter.input('2')).to.equal('+870 773 111 632')
|
|
876
876
|
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
877
|
-
formatter.getNumber().country.
|
|
877
|
+
expect(formatter.getNumber().country).to.equal('001')
|
|
878
878
|
} else {
|
|
879
879
|
expect(formatter.getCountry()).to.be.undefined
|
|
880
880
|
}
|
|
881
|
-
formatter.getNumber().countryCallingCode.
|
|
881
|
+
expect(formatter.getNumber().countryCallingCode).to.equal('870')
|
|
882
882
|
})
|
|
883
883
|
|
|
884
884
|
it('should format non-geographic numbering plan phone numbers (default country calling code)', () => {
|
|
885
885
|
const formatter = new AsYouType({ defaultCallingCode: '870' })
|
|
886
886
|
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
887
|
-
formatter.getNumber().country.
|
|
887
|
+
expect(formatter.getNumber().country).to.equal('001')
|
|
888
888
|
} else {
|
|
889
889
|
expect(formatter.getCountry()).to.be.undefined
|
|
890
890
|
}
|
|
891
|
-
formatter.input('7').
|
|
892
|
-
formatter.input('7').
|
|
893
|
-
formatter.input('3').
|
|
894
|
-
formatter.input('1').
|
|
895
|
-
formatter.input('1').
|
|
896
|
-
formatter.input('1').
|
|
897
|
-
formatter.input('6').
|
|
898
|
-
formatter.input('3').
|
|
899
|
-
formatter.input('2').
|
|
891
|
+
expect(formatter.input('7')).to.equal('7')
|
|
892
|
+
expect(formatter.input('7')).to.equal('77')
|
|
893
|
+
expect(formatter.input('3')).to.equal('773')
|
|
894
|
+
expect(formatter.input('1')).to.equal('773 1')
|
|
895
|
+
expect(formatter.input('1')).to.equal('773 11')
|
|
896
|
+
expect(formatter.input('1')).to.equal('773 111')
|
|
897
|
+
expect(formatter.input('6')).to.equal('773 111 6')
|
|
898
|
+
expect(formatter.input('3')).to.equal('773 111 63')
|
|
899
|
+
expect(formatter.input('2')).to.equal('773 111 632')
|
|
900
900
|
if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
|
|
901
|
-
formatter.getNumber().country.
|
|
901
|
+
expect(formatter.getNumber().country).to.equal('001')
|
|
902
902
|
} else {
|
|
903
903
|
expect(formatter.getCountry()).to.be.undefined
|
|
904
904
|
}
|
|
905
|
-
formatter.getNumber().countryCallingCode.
|
|
905
|
+
expect(formatter.getNumber().countryCallingCode).to.equal('870')
|
|
906
906
|
})
|
|
907
907
|
|
|
908
908
|
it('should not format non-geographic numbering plan phone numbers (default country 001)', () => {
|
|
909
909
|
const formatter = new AsYouType('001')
|
|
910
910
|
expect(formatter.defaultCountry).to.be.undefined
|
|
911
911
|
expect(formatter.defaultCallingCode).to.be.undefined
|
|
912
|
-
formatter.input('7').
|
|
913
|
-
formatter.input('7').
|
|
914
|
-
formatter.input('3').
|
|
915
|
-
formatter.input('1').
|
|
916
|
-
formatter.input('1').
|
|
917
|
-
formatter.input('1').
|
|
918
|
-
formatter.input('6').
|
|
919
|
-
formatter.input('3').
|
|
920
|
-
formatter.input('2').
|
|
912
|
+
expect(formatter.input('7')).to.equal('7')
|
|
913
|
+
expect(formatter.input('7')).to.equal('77')
|
|
914
|
+
expect(formatter.input('3')).to.equal('773')
|
|
915
|
+
expect(formatter.input('1')).to.equal('7731')
|
|
916
|
+
expect(formatter.input('1')).to.equal('77311')
|
|
917
|
+
expect(formatter.input('1')).to.equal('773111')
|
|
918
|
+
expect(formatter.input('6')).to.equal('7731116')
|
|
919
|
+
expect(formatter.input('3')).to.equal('77311163')
|
|
920
|
+
expect(formatter.input('2')).to.equal('773111632')
|
|
921
921
|
expect(formatter.getCountry()).to.be.undefined
|
|
922
922
|
expect(formatter.getNumber()).to.be.undefined
|
|
923
923
|
})
|
|
@@ -925,22 +925,22 @@ describe('AsYouType', () => {
|
|
|
925
925
|
it('should return PhoneNumber (should strip national prefix `1` in E.164 value)', () => {
|
|
926
926
|
const formatter = new AsYouType('RU')
|
|
927
927
|
formatter.input('+1111')
|
|
928
|
-
formatter.getNumber().number.
|
|
928
|
+
expect(formatter.getNumber().number).to.equal('+111')
|
|
929
929
|
})
|
|
930
930
|
|
|
931
931
|
it('should return PhoneNumber with autocorrected international numbers without leading +', () => {
|
|
932
932
|
// https://github.com/catamphetamine/libphonenumber-js/issues/316
|
|
933
933
|
const formatter = new AsYouType('FR')
|
|
934
|
-
formatter.input('33612902554').
|
|
935
|
-
formatter.getNumber().country.
|
|
936
|
-
formatter.getNumber().nationalNumber.
|
|
937
|
-
formatter.getNumber().number.
|
|
934
|
+
expect(formatter.input('33612902554')).to.equal('33 6 12 90 25 54')
|
|
935
|
+
expect(formatter.getNumber().country).to.equal('FR')
|
|
936
|
+
expect(formatter.getNumber().nationalNumber).to.equal('612902554')
|
|
937
|
+
expect(formatter.getNumber().number).to.equal('+33612902554')
|
|
938
938
|
// Should also strip national prefix.
|
|
939
939
|
formatter.reset()
|
|
940
|
-
formatter.input('330612902554').
|
|
941
|
-
formatter.getNumber().country.
|
|
942
|
-
formatter.getNumber().nationalNumber.
|
|
943
|
-
formatter.getNumber().number.
|
|
940
|
+
expect(formatter.input('330612902554')).to.equal('33 06 12 90 25 54')
|
|
941
|
+
expect(formatter.getNumber().country).to.equal('FR')
|
|
942
|
+
expect(formatter.getNumber().nationalNumber).to.equal('612902554')
|
|
943
|
+
expect(formatter.getNumber().number).to.equal('+33612902554')
|
|
944
944
|
// On second thought, this "prepend default area code" feature won't be added,
|
|
945
945
|
// because when a user selects "British Virgin Islands" and inputs
|
|
946
946
|
// "2291234", then they see "(229) 123-4" which clearly indicates that
|
|
@@ -958,20 +958,20 @@ describe('AsYouType', () => {
|
|
|
958
958
|
|
|
959
959
|
it('should work with out-of-country dialing prefix (like 00)', () => {
|
|
960
960
|
const formatter = new AsYouType('DE')
|
|
961
|
-
formatter.input('00498911196611').
|
|
962
|
-
formatter.getCountry().
|
|
963
|
-
formatter.formatter.template.
|
|
964
|
-
formatter.formatter.populatedNationalNumberTemplate.
|
|
965
|
-
formatter.getTemplate().
|
|
966
|
-
formatter.getNumber().country.
|
|
967
|
-
formatter.getNumber().nationalNumber.
|
|
968
|
-
formatter.getNumber().number.
|
|
961
|
+
expect(formatter.input('00498911196611')).to.equal('00 49 89 11196611')
|
|
962
|
+
expect(formatter.getCountry()).to.equal('DE')
|
|
963
|
+
expect(formatter.formatter.template).to.equal('xx xx xx xxxxxxxx')
|
|
964
|
+
expect(formatter.formatter.populatedNationalNumberTemplate).to.equal('89 11196611')
|
|
965
|
+
expect(formatter.getTemplate()).to.equal('xx xx xx xxxxxxxx')
|
|
966
|
+
expect(formatter.getNumber().country).to.equal('DE')
|
|
967
|
+
expect(formatter.getNumber().nationalNumber).to.equal('8911196611')
|
|
968
|
+
expect(formatter.getNumber().number).to.equal('+498911196611')
|
|
969
969
|
})
|
|
970
970
|
|
|
971
971
|
it('shouldn\'t choose a format when there\'re too many digits for any of them', () => {
|
|
972
972
|
const formatter = new AsYouType('RU')
|
|
973
973
|
formatter.input('89991112233')
|
|
974
|
-
formatter.formatter.chosenFormat.format().
|
|
974
|
+
expect(formatter.formatter.chosenFormat.format()).to.equal('$1 $2-$3-$4')
|
|
975
975
|
formatter.reset()
|
|
976
976
|
formatter.input('899911122334')
|
|
977
977
|
expect(formatter.formatter.chosenFormat).to.be.undefined
|
|
@@ -982,51 +982,51 @@ describe('AsYouType', () => {
|
|
|
982
982
|
// Has separator after national prefix.
|
|
983
983
|
const formatter = new AsYouType('RU')
|
|
984
984
|
const format = formatter.metadata.formats()[0]
|
|
985
|
-
format.nationalPrefixFormattingRule().
|
|
986
|
-
formatter.formatter.getSeparatorAfterNationalPrefix(format).
|
|
985
|
+
expect(format.nationalPrefixFormattingRule()).to.equal('8 ($1)')
|
|
986
|
+
expect(formatter.formatter.getSeparatorAfterNationalPrefix(format)).to.equal(' ')
|
|
987
987
|
// Britain.
|
|
988
988
|
// Has no separator after national prefix.
|
|
989
989
|
const formatter2 = new AsYouType('GB')
|
|
990
990
|
const format2 = formatter2.metadata.formats()[0]
|
|
991
|
-
format2.nationalPrefixFormattingRule().
|
|
992
|
-
formatter2.formatter.getSeparatorAfterNationalPrefix(format2).
|
|
991
|
+
expect(format2.nationalPrefixFormattingRule()).to.equal('0$1')
|
|
992
|
+
expect(formatter2.formatter.getSeparatorAfterNationalPrefix(format2)).to.equal('')
|
|
993
993
|
})
|
|
994
994
|
|
|
995
995
|
it('should return if the number is possible', () => {
|
|
996
996
|
// National. Russia.
|
|
997
997
|
const formatter = new AsYouType('RU')
|
|
998
|
-
formatter.isPossible().
|
|
998
|
+
expect(formatter.isPossible()).to.equal(false)
|
|
999
999
|
formatter.input('8')
|
|
1000
|
-
formatter.isPossible().
|
|
1000
|
+
expect(formatter.isPossible()).to.equal(false)
|
|
1001
1001
|
formatter.input('8005553535')
|
|
1002
|
-
formatter.isPossible().
|
|
1002
|
+
expect(formatter.isPossible()).to.equal(true)
|
|
1003
1003
|
formatter.input('5')
|
|
1004
|
-
formatter.isPossible().
|
|
1004
|
+
expect(formatter.isPossible()).to.equal(false)
|
|
1005
1005
|
})
|
|
1006
1006
|
|
|
1007
1007
|
it('should return if the number is valid', () => {
|
|
1008
1008
|
// National. Russia.
|
|
1009
1009
|
const formatter = new AsYouType('RU')
|
|
1010
|
-
formatter.isValid().
|
|
1010
|
+
expect(formatter.isValid()).to.equal(false)
|
|
1011
1011
|
formatter.input('88005553535')
|
|
1012
|
-
formatter.isValid().
|
|
1012
|
+
expect(formatter.isValid()).to.equal(true)
|
|
1013
1013
|
formatter.input('5')
|
|
1014
|
-
formatter.isValid().
|
|
1014
|
+
expect(formatter.isValid()).to.equal(false)
|
|
1015
1015
|
})
|
|
1016
1016
|
|
|
1017
1017
|
it('should return if the number is international', () => {
|
|
1018
1018
|
// National. Russia.
|
|
1019
1019
|
const formatter = new AsYouType('RU')
|
|
1020
|
-
formatter.isInternational().
|
|
1020
|
+
expect(formatter.isInternational()).to.equal(false)
|
|
1021
1021
|
formatter.input('88005553535')
|
|
1022
|
-
formatter.isInternational().
|
|
1022
|
+
expect(formatter.isInternational()).to.equal(false)
|
|
1023
1023
|
// International. Russia.
|
|
1024
1024
|
const formatterInt = new AsYouType()
|
|
1025
|
-
formatterInt.isInternational().
|
|
1025
|
+
expect(formatterInt.isInternational()).to.equal(false)
|
|
1026
1026
|
formatterInt.input('+')
|
|
1027
|
-
formatterInt.isInternational().
|
|
1027
|
+
expect(formatterInt.isInternational()).to.equal(true)
|
|
1028
1028
|
formatterInt.input('78005553535')
|
|
1029
|
-
formatterInt.isInternational().
|
|
1029
|
+
expect(formatterInt.isInternational()).to.equal(true)
|
|
1030
1030
|
})
|
|
1031
1031
|
|
|
1032
1032
|
it('should return country calling code part of the number', () => {
|
|
@@ -1077,30 +1077,30 @@ describe('AsYouType', () => {
|
|
|
1077
1077
|
it('should parse a long IDD prefix', () => {
|
|
1078
1078
|
const formatter = new AsYouType('AU')
|
|
1079
1079
|
// `14880011` is a long IDD prefix in Australia.
|
|
1080
|
-
formatter.input('1').
|
|
1081
|
-
formatter.input('4').
|
|
1082
|
-
formatter.input('8').
|
|
1083
|
-
formatter.input('8').
|
|
1084
|
-
formatter.input('0').
|
|
1085
|
-
formatter.input('0').
|
|
1086
|
-
formatter.input('1').
|
|
1087
|
-
formatter.input('1').
|
|
1080
|
+
expect(formatter.input('1')).to.equal('1')
|
|
1081
|
+
expect(formatter.input('4')).to.equal('14')
|
|
1082
|
+
expect(formatter.input('8')).to.equal('148')
|
|
1083
|
+
expect(formatter.input('8')).to.equal('1488')
|
|
1084
|
+
expect(formatter.input('0')).to.equal('14880')
|
|
1085
|
+
expect(formatter.input('0')).to.equal('148800')
|
|
1086
|
+
expect(formatter.input('1')).to.equal('1488001')
|
|
1087
|
+
expect(formatter.input('1')).to.equal('14880011')
|
|
1088
1088
|
// As if were calling US using `14880011` IDD prefix,
|
|
1089
1089
|
// though that prefix could mean something else.
|
|
1090
|
-
formatter.input('1').
|
|
1091
|
-
formatter.input('2').
|
|
1092
|
-
formatter.input('1').
|
|
1093
|
-
formatter.input('3').
|
|
1090
|
+
expect(formatter.input('1')).to.equal('14880011 1')
|
|
1091
|
+
expect(formatter.input('2')).to.equal('14880011 1 2')
|
|
1092
|
+
expect(formatter.input('1')).to.equal('14880011 1 21')
|
|
1093
|
+
expect(formatter.input('3')).to.equal('14880011 1 213')
|
|
1094
1094
|
})
|
|
1095
1095
|
|
|
1096
1096
|
it('should return the phone number characters entered by the user', () => {
|
|
1097
1097
|
const formatter = new AsYouType('RU')
|
|
1098
|
-
formatter.getChars().
|
|
1098
|
+
expect(formatter.getChars()).to.equal('')
|
|
1099
1099
|
formatter.input('+123')
|
|
1100
|
-
formatter.getChars().
|
|
1100
|
+
expect(formatter.getChars()).to.equal('+123')
|
|
1101
1101
|
formatter.reset()
|
|
1102
1102
|
formatter.input('123')
|
|
1103
|
-
formatter.getChars().
|
|
1103
|
+
expect(formatter.getChars()).to.equal('123')
|
|
1104
1104
|
})
|
|
1105
1105
|
|
|
1106
1106
|
// A test confirming the case when input `"11"` for country `"US"`
|
|
@@ -1116,8 +1116,8 @@ describe('AsYouType', () => {
|
|
|
1116
1116
|
// So it acts as if the leading `"+"` is there,
|
|
1117
1117
|
// as if the user's input is `"+11"`.
|
|
1118
1118
|
// See `AsYouType.fixMissingPlus()` function.
|
|
1119
|
-
formatter.input('1 122 222 2222 3').
|
|
1120
|
-
formatter.getNumber().nationalNumber.
|
|
1119
|
+
expect(formatter.input('1 122 222 2222 3')).to.equal('1 1 222 222 2223')
|
|
1120
|
+
expect(formatter.getNumber().nationalNumber).to.equal('2222222223')
|
|
1121
1121
|
})
|
|
1122
1122
|
})
|
|
1123
1123
|
|
|
@@ -1128,17 +1128,17 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1128
1128
|
formatter.input('')
|
|
1129
1129
|
expect(formatter.getNumberValue()).to.be.undefined
|
|
1130
1130
|
formatter.input('1')
|
|
1131
|
-
formatter.getNumberValue().
|
|
1131
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1132
1132
|
formatter.input('2')
|
|
1133
|
-
formatter.getNumberValue().
|
|
1133
|
+
expect(formatter.getNumberValue()).to.equal('+12')
|
|
1134
1134
|
formatter.input('1')
|
|
1135
|
-
formatter.getNumberValue().
|
|
1135
|
+
expect(formatter.getNumberValue()).to.equal('+121')
|
|
1136
1136
|
formatter.input('3')
|
|
1137
|
-
formatter.getNumberValue().
|
|
1137
|
+
expect(formatter.getNumberValue()).to.equal('+1213')
|
|
1138
1138
|
formatter.input('373-4253')
|
|
1139
|
-
formatter.getNumberValue().
|
|
1139
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253')
|
|
1140
1140
|
formatter.input('4')
|
|
1141
|
-
formatter.getNumberValue().
|
|
1141
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534')
|
|
1142
1142
|
})
|
|
1143
1143
|
|
|
1144
1144
|
it('should return E.164 number value (national number, with national prefix, default calling code: 1)', () => {
|
|
@@ -1147,17 +1147,17 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1147
1147
|
formatter.input('')
|
|
1148
1148
|
expect(formatter.getNumberValue()).to.be.undefined
|
|
1149
1149
|
formatter.input('1')
|
|
1150
|
-
formatter.getNumberValue().
|
|
1150
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1151
1151
|
formatter.input('2')
|
|
1152
|
-
formatter.getNumberValue().
|
|
1152
|
+
expect(formatter.getNumberValue()).to.equal('+12')
|
|
1153
1153
|
formatter.input('1')
|
|
1154
|
-
formatter.getNumberValue().
|
|
1154
|
+
expect(formatter.getNumberValue()).to.equal('+121')
|
|
1155
1155
|
formatter.input('3')
|
|
1156
|
-
formatter.getNumberValue().
|
|
1156
|
+
expect(formatter.getNumberValue()).to.equal('+1213')
|
|
1157
1157
|
formatter.input('373-4253')
|
|
1158
|
-
formatter.getNumberValue().
|
|
1158
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253')
|
|
1159
1159
|
formatter.input('4')
|
|
1160
|
-
formatter.getNumberValue().
|
|
1160
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534')
|
|
1161
1161
|
})
|
|
1162
1162
|
|
|
1163
1163
|
it('should return E.164 number value (national number, default country: US)', () => {
|
|
@@ -1166,15 +1166,15 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1166
1166
|
formatter.input('')
|
|
1167
1167
|
expect(formatter.getNumberValue()).to.be.undefined
|
|
1168
1168
|
formatter.input('2')
|
|
1169
|
-
formatter.getNumberValue().
|
|
1169
|
+
expect(formatter.getNumberValue()).to.equal('+12')
|
|
1170
1170
|
formatter.input('1')
|
|
1171
|
-
formatter.getNumberValue().
|
|
1171
|
+
expect(formatter.getNumberValue()).to.equal('+121')
|
|
1172
1172
|
formatter.input('3')
|
|
1173
|
-
formatter.getNumberValue().
|
|
1173
|
+
expect(formatter.getNumberValue()).to.equal('+1213')
|
|
1174
1174
|
formatter.input('373-4253')
|
|
1175
|
-
formatter.getNumberValue().
|
|
1175
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253')
|
|
1176
1176
|
formatter.input('4')
|
|
1177
|
-
formatter.getNumberValue().
|
|
1177
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534')
|
|
1178
1178
|
})
|
|
1179
1179
|
|
|
1180
1180
|
it('should return E.164 number value (national number, default calling code: 1)', () => {
|
|
@@ -1183,15 +1183,15 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1183
1183
|
formatter.input('')
|
|
1184
1184
|
expect(formatter.getNumberValue()).to.be.undefined
|
|
1185
1185
|
formatter.input('2')
|
|
1186
|
-
formatter.getNumberValue().
|
|
1186
|
+
expect(formatter.getNumberValue()).to.equal('+12')
|
|
1187
1187
|
formatter.input('1')
|
|
1188
|
-
formatter.getNumberValue().
|
|
1188
|
+
expect(formatter.getNumberValue()).to.equal('+121')
|
|
1189
1189
|
formatter.input('3')
|
|
1190
|
-
formatter.getNumberValue().
|
|
1190
|
+
expect(formatter.getNumberValue()).to.equal('+1213')
|
|
1191
1191
|
formatter.input('373-4253')
|
|
1192
|
-
formatter.getNumberValue().
|
|
1192
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253')
|
|
1193
1193
|
formatter.input('4')
|
|
1194
|
-
formatter.getNumberValue().
|
|
1194
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534')
|
|
1195
1195
|
})
|
|
1196
1196
|
|
|
1197
1197
|
it('should return E.164 number value (international number, not a valid calling code)', () => {
|
|
@@ -1202,7 +1202,7 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1202
1202
|
formatter.input('+')
|
|
1203
1203
|
expect(formatter.getNumberValue()).to.be.undefined
|
|
1204
1204
|
formatter.input('2150')
|
|
1205
|
-
formatter.getNumberValue().
|
|
1205
|
+
expect(formatter.getNumberValue()).to.equal('+2150')
|
|
1206
1206
|
})
|
|
1207
1207
|
|
|
1208
1208
|
it('should return E.164 number value (international number, default country: US)', () => {
|
|
@@ -1213,19 +1213,19 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1213
1213
|
formatter.input('+')
|
|
1214
1214
|
expect(formatter.getNumberValue()).to.be.undefined
|
|
1215
1215
|
formatter.input('1')
|
|
1216
|
-
formatter.getNumberValue().
|
|
1216
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1217
1217
|
formatter.input('1')
|
|
1218
|
-
formatter.getNumberValue().
|
|
1218
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1219
1219
|
formatter.input('2')
|
|
1220
|
-
formatter.getNumberValue().
|
|
1220
|
+
expect(formatter.getNumberValue()).to.equal('+12')
|
|
1221
1221
|
formatter.input('1')
|
|
1222
|
-
formatter.getNumberValue().
|
|
1222
|
+
expect(formatter.getNumberValue()).to.equal('+121')
|
|
1223
1223
|
formatter.input('3')
|
|
1224
|
-
formatter.getNumberValue().
|
|
1224
|
+
expect(formatter.getNumberValue()).to.equal('+1213')
|
|
1225
1225
|
formatter.input('373-4253')
|
|
1226
|
-
formatter.getNumberValue().
|
|
1226
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253')
|
|
1227
1227
|
formatter.input('4')
|
|
1228
|
-
formatter.getNumberValue().
|
|
1228
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534')
|
|
1229
1229
|
})
|
|
1230
1230
|
|
|
1231
1231
|
it('should return E.164 number value (international number, other default country: RU)', () => {
|
|
@@ -1236,19 +1236,19 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1236
1236
|
formatter.input('+')
|
|
1237
1237
|
expect(formatter.getNumberValue()).to.be.undefined
|
|
1238
1238
|
formatter.input('1')
|
|
1239
|
-
formatter.getNumberValue().
|
|
1239
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1240
1240
|
formatter.input('1')
|
|
1241
|
-
formatter.getNumberValue().
|
|
1241
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1242
1242
|
formatter.input('2')
|
|
1243
|
-
formatter.getNumberValue().
|
|
1243
|
+
expect(formatter.getNumberValue()).to.equal('+12')
|
|
1244
1244
|
formatter.input('1')
|
|
1245
|
-
formatter.getNumberValue().
|
|
1245
|
+
expect(formatter.getNumberValue()).to.equal('+121')
|
|
1246
1246
|
formatter.input('3')
|
|
1247
|
-
formatter.getNumberValue().
|
|
1247
|
+
expect(formatter.getNumberValue()).to.equal('+1213')
|
|
1248
1248
|
formatter.input('373-4253')
|
|
1249
|
-
formatter.getNumberValue().
|
|
1249
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253')
|
|
1250
1250
|
formatter.input('4')
|
|
1251
|
-
formatter.getNumberValue().
|
|
1251
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534')
|
|
1252
1252
|
})
|
|
1253
1253
|
|
|
1254
1254
|
it('should return E.164 number value (international number, default calling code: 1)', () => {
|
|
@@ -1259,19 +1259,19 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1259
1259
|
formatter.input('+')
|
|
1260
1260
|
expect(formatter.getNumberValue()).to.be.undefined
|
|
1261
1261
|
formatter.input('1')
|
|
1262
|
-
formatter.getNumberValue().
|
|
1262
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1263
1263
|
formatter.input('1')
|
|
1264
|
-
formatter.getNumberValue().
|
|
1264
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1265
1265
|
formatter.input('2')
|
|
1266
|
-
formatter.getNumberValue().
|
|
1266
|
+
expect(formatter.getNumberValue()).to.equal('+12')
|
|
1267
1267
|
formatter.input('1')
|
|
1268
|
-
formatter.getNumberValue().
|
|
1268
|
+
expect(formatter.getNumberValue()).to.equal('+121')
|
|
1269
1269
|
formatter.input('3')
|
|
1270
|
-
formatter.getNumberValue().
|
|
1270
|
+
expect(formatter.getNumberValue()).to.equal('+1213')
|
|
1271
1271
|
formatter.input('373-4253')
|
|
1272
|
-
formatter.getNumberValue().
|
|
1272
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253')
|
|
1273
1273
|
formatter.input('4')
|
|
1274
|
-
formatter.getNumberValue().
|
|
1274
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534')
|
|
1275
1275
|
})
|
|
1276
1276
|
|
|
1277
1277
|
it('should return E.164 number value (international number, other default calling code: 7)', () => {
|
|
@@ -1282,19 +1282,19 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1282
1282
|
formatter.input('+')
|
|
1283
1283
|
expect(formatter.getNumberValue()).to.be.undefined
|
|
1284
1284
|
formatter.input('1')
|
|
1285
|
-
formatter.getNumberValue().
|
|
1285
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1286
1286
|
formatter.input('1')
|
|
1287
|
-
formatter.getNumberValue().
|
|
1287
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1288
1288
|
formatter.input('2')
|
|
1289
|
-
formatter.getNumberValue().
|
|
1289
|
+
expect(formatter.getNumberValue()).to.equal('+12')
|
|
1290
1290
|
formatter.input('1')
|
|
1291
|
-
formatter.getNumberValue().
|
|
1291
|
+
expect(formatter.getNumberValue()).to.equal('+121')
|
|
1292
1292
|
formatter.input('3')
|
|
1293
|
-
formatter.getNumberValue().
|
|
1293
|
+
expect(formatter.getNumberValue()).to.equal('+1213')
|
|
1294
1294
|
formatter.input('373-4253')
|
|
1295
|
-
formatter.getNumberValue().
|
|
1295
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253')
|
|
1296
1296
|
formatter.input('4')
|
|
1297
|
-
formatter.getNumberValue().
|
|
1297
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534')
|
|
1298
1298
|
})
|
|
1299
1299
|
|
|
1300
1300
|
it('should return E.164 number value (international number)', () => {
|
|
@@ -1305,19 +1305,19 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1305
1305
|
formatter.input('+')
|
|
1306
1306
|
expect(formatter.getNumberValue()).to.be.undefined
|
|
1307
1307
|
formatter.input('1')
|
|
1308
|
-
formatter.getNumberValue().
|
|
1308
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1309
1309
|
formatter.input('1')
|
|
1310
|
-
formatter.getNumberValue().
|
|
1310
|
+
expect(formatter.getNumberValue()).to.equal('+1')
|
|
1311
1311
|
formatter.input('2')
|
|
1312
|
-
formatter.getNumberValue().
|
|
1312
|
+
expect(formatter.getNumberValue()).to.equal('+12')
|
|
1313
1313
|
formatter.input('1')
|
|
1314
|
-
formatter.getNumberValue().
|
|
1314
|
+
expect(formatter.getNumberValue()).to.equal('+121')
|
|
1315
1315
|
formatter.input('3')
|
|
1316
|
-
formatter.getNumberValue().
|
|
1316
|
+
expect(formatter.getNumberValue()).to.equal('+1213')
|
|
1317
1317
|
formatter.input('373-4253')
|
|
1318
|
-
formatter.getNumberValue().
|
|
1318
|
+
expect(formatter.getNumberValue()).to.equal('+12133734253')
|
|
1319
1319
|
formatter.input('4')
|
|
1320
|
-
formatter.getNumberValue().
|
|
1320
|
+
expect(formatter.getNumberValue()).to.equal('+121337342534')
|
|
1321
1321
|
})
|
|
1322
1322
|
|
|
1323
1323
|
it('should return E.164 number value (national number) (no default country or calling code)', () => {
|
|
@@ -1341,23 +1341,23 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1341
1341
|
// Test "+529011234567" number, proactively ensuring that no formatting is applied,
|
|
1342
1342
|
// where a format is chosen that would otherwise have led to some digits being dropped.
|
|
1343
1343
|
const formatter = new AsYouType('MX')
|
|
1344
|
-
formatter.input('9').
|
|
1345
|
-
formatter.input('0').
|
|
1346
|
-
formatter.input('1').
|
|
1347
|
-
formatter.input('1').
|
|
1348
|
-
formatter.input('2').
|
|
1349
|
-
formatter.input('3').
|
|
1350
|
-
formatter.input('4').
|
|
1351
|
-
formatter.input('5').
|
|
1352
|
-
formatter.input('6').
|
|
1353
|
-
formatter.input('7').
|
|
1344
|
+
expect(formatter.input('9')).to.equal('9')
|
|
1345
|
+
expect(formatter.input('0')).to.equal('90')
|
|
1346
|
+
expect(formatter.input('1')).to.equal('901')
|
|
1347
|
+
expect(formatter.input('1')).to.equal('901 1')
|
|
1348
|
+
expect(formatter.input('2')).to.equal('901 12')
|
|
1349
|
+
expect(formatter.input('3')).to.equal('901 123')
|
|
1350
|
+
expect(formatter.input('4')).to.equal('901 123 4')
|
|
1351
|
+
expect(formatter.input('5')).to.equal('901 123 45')
|
|
1352
|
+
expect(formatter.input('6')).to.equal('901 123 456')
|
|
1353
|
+
expect(formatter.input('7')).to.equal('901 123 4567')
|
|
1354
1354
|
})
|
|
1355
1355
|
|
|
1356
1356
|
it('should work for formats with no leading digits (`leadingDigitsPatternsCount === 0`)', function() {
|
|
1357
1357
|
const formatter = new AsYouType({
|
|
1358
1358
|
defaultCallingCode: 888
|
|
1359
1359
|
})
|
|
1360
|
-
formatter.input('1').
|
|
1360
|
+
expect(formatter.input('1')).to.equal('1')
|
|
1361
1361
|
})
|
|
1362
1362
|
|
|
1363
1363
|
it('should work for SK phone numbers', function() {
|
|
@@ -1366,18 +1366,18 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1366
1366
|
// while it should've been `undefined`.
|
|
1367
1367
|
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/66
|
|
1368
1368
|
const formatter = new AsYouType('SK')
|
|
1369
|
-
formatter.input('090').
|
|
1369
|
+
expect(formatter.input('090')).to.equal('090')
|
|
1370
1370
|
formatter.reset()
|
|
1371
|
-
formatter.input('080').
|
|
1371
|
+
expect(formatter.input('080')).to.equal('080')
|
|
1372
1372
|
formatter.reset()
|
|
1373
|
-
formatter.input('059').
|
|
1373
|
+
expect(formatter.input('059')).to.equal('059')
|
|
1374
1374
|
})
|
|
1375
1375
|
|
|
1376
1376
|
it('should work for SK phone numbers (2)', function() {
|
|
1377
1377
|
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/69
|
|
1378
1378
|
const formatter = new AsYouType('SK')
|
|
1379
|
-
formatter.input('421901222333').
|
|
1380
|
-
formatter.getTemplate().
|
|
1379
|
+
expect(formatter.input('421901222333')).to.equal('421 901 222 333')
|
|
1380
|
+
expect(formatter.getTemplate()).to.equal('xxx xxx xxx xxx')
|
|
1381
1381
|
})
|
|
1382
1382
|
|
|
1383
1383
|
it('should not choose `defaultCountry` over the "main" one when both the `defaultCountry` and the "main" one match the phone number', function() {
|
|
@@ -1386,19 +1386,19 @@ describe('AsYouType.getNumberValue()', () => {
|
|
|
1386
1386
|
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103
|
|
1387
1387
|
const formatter = new AsYouType('CA')
|
|
1388
1388
|
formatter.input('8004001000')
|
|
1389
|
-
formatter.getNumber().country.
|
|
1390
|
-
formatter.getNumber().country.
|
|
1389
|
+
expect(formatter.getNumber().country).not.to.equal('CA')
|
|
1390
|
+
expect(formatter.getNumber().country).to.equal('US')
|
|
1391
1391
|
|
|
1392
1392
|
// This phone number is specific to CA.
|
|
1393
1393
|
const formatter2 = new AsYouType('US')
|
|
1394
1394
|
formatter2.input('4389999999')
|
|
1395
|
-
formatter2.getNumber().country.
|
|
1395
|
+
expect(formatter2.getNumber().country).to.equal('CA')
|
|
1396
1396
|
|
|
1397
1397
|
// This phone number doesn't belong neither to CA nor to US.
|
|
1398
1398
|
// In fact, it doesn't belong to any country from the "NANPA" zone.
|
|
1399
1399
|
const formatter3 = new AsYouType('US')
|
|
1400
1400
|
formatter3.input('1111111111')
|
|
1401
|
-
formatter3.getNumber().country.
|
|
1401
|
+
expect(formatter3.getNumber().country).to.equal('US')
|
|
1402
1402
|
})
|
|
1403
1403
|
})
|
|
1404
1404
|
|