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