libphonenumber-js 1.12.43 → 1.13.0
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/CHANGELOG.md +131 -104
- package/README.md +36 -6
- package/core/es6/index.d.cts +2 -0
- package/core/es6/index.d.ts +2 -0
- package/core/es6/index.js +39 -0
- package/core/es6/package.json +12 -0
- package/core/index.cjs +5 -0
- package/core/index.cjs.js +5 -0
- package/core/index.d.cts +3 -1
- package/core/index.d.ts +3 -1
- package/core/index.js +5 -0
- package/custom.d.ts +6 -4
- package/custom.js +5 -5
- package/es6-modern/AsYouType.js +445 -0
- package/es6-modern/AsYouType.js.map +1 -0
- package/es6-modern/AsYouType.test.js.map +1 -0
- package/es6-modern/AsYouTypeFormatter.PatternMatcher.js +195 -0
- package/es6-modern/AsYouTypeFormatter.PatternMatcher.js.map +1 -0
- package/es6-modern/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -0
- package/es6-modern/AsYouTypeFormatter.PatternParser.js +184 -0
- package/es6-modern/AsYouTypeFormatter.PatternParser.js.map +1 -0
- package/es6-modern/AsYouTypeFormatter.PatternParser.test.js.map +1 -0
- package/es6-modern/AsYouTypeFormatter.complete.js +120 -0
- package/es6-modern/AsYouTypeFormatter.complete.js.map +1 -0
- package/es6-modern/AsYouTypeFormatter.js +659 -0
- package/es6-modern/AsYouTypeFormatter.js.map +1 -0
- package/es6-modern/AsYouTypeFormatter.util.js +96 -0
- package/es6-modern/AsYouTypeFormatter.util.js.map +1 -0
- package/es6-modern/AsYouTypeFormatter.util.test.js.map +1 -0
- package/es6-modern/AsYouTypeParser.js +435 -0
- package/es6-modern/AsYouTypeParser.js.map +1 -0
- package/es6-modern/AsYouTypeState.js +104 -0
- package/es6-modern/AsYouTypeState.js.map +1 -0
- package/es6-modern/ParseError.js +15 -0
- package/es6-modern/ParseError.js.map +1 -0
- package/es6-modern/PhoneNumber.js +166 -0
- package/es6-modern/PhoneNumber.js.map +1 -0
- package/es6-modern/PhoneNumber.test.js.map +1 -0
- package/es6-modern/PhoneNumberMatcher.js +330 -0
- package/es6-modern/PhoneNumberMatcher.js.map +1 -0
- package/es6-modern/PhoneNumberMatcher.test.js.map +1 -0
- package/es6-modern/constants.js +31 -0
- package/es6-modern/constants.js.map +1 -0
- package/es6-modern/findNumbers/LRUCache.js +98 -0
- package/es6-modern/findNumbers/LRUCache.js.map +1 -0
- package/es6-modern/findNumbers/Leniency.js +311 -0
- package/es6-modern/findNumbers/Leniency.js.map +1 -0
- package/es6-modern/findNumbers/RegExpCache.js +20 -0
- package/es6-modern/findNumbers/RegExpCache.js.map +1 -0
- package/es6-modern/findNumbers/isValidCandidate.js +66 -0
- package/es6-modern/findNumbers/isValidCandidate.js.map +1 -0
- package/es6-modern/findNumbers/isValidPreCandidate.js +26 -0
- package/es6-modern/findNumbers/isValidPreCandidate.js.map +1 -0
- package/es6-modern/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +63 -0
- package/es6-modern/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -0
- package/es6-modern/findNumbers/parsePreCandidate.js +18 -0
- package/es6-modern/findNumbers/parsePreCandidate.js.map +1 -0
- package/es6-modern/findNumbers/utf-8.js +63 -0
- package/es6-modern/findNumbers/utf-8.js.map +1 -0
- package/es6-modern/findNumbers/util.js +26 -0
- package/es6-modern/findNumbers/util.js.map +1 -0
- package/es6-modern/findNumbers/util.test.js.map +1 -0
- package/es6-modern/findPhoneNumbersInText.js +19 -0
- package/es6-modern/findPhoneNumbersInText.js.map +1 -0
- package/es6-modern/findPhoneNumbersInText.test.js.map +1 -0
- package/es6-modern/format.js +204 -0
- package/es6-modern/format.js.map +1 -0
- package/es6-modern/format.test.js.map +1 -0
- package/es6-modern/formatIncompletePhoneNumber.js +18 -0
- package/es6-modern/formatIncompletePhoneNumber.js.map +1 -0
- package/es6-modern/formatIncompletePhoneNumber.test.js.map +1 -0
- package/es6-modern/formatPhoneNumberForMobileDialing.js +190 -0
- package/es6-modern/formatPhoneNumberForMobileDialing.js.map +1 -0
- package/es6-modern/getCountries.js +5 -0
- package/es6-modern/getCountries.js.map +1 -0
- package/es6-modern/getCountries.test.js.map +1 -0
- package/es6-modern/getCountryCallingCode.js +3 -0
- package/es6-modern/getCountryCallingCode.js.map +1 -0
- package/es6-modern/getCountryCallingCode.test.js.map +1 -0
- package/es6-modern/getExampleNumber.js +7 -0
- package/es6-modern/getExampleNumber.js.map +1 -0
- package/es6-modern/getExampleNumber.test.js.map +1 -0
- package/es6-modern/helpers/RFC3966.js +63 -0
- package/es6-modern/helpers/RFC3966.js.map +1 -0
- package/es6-modern/helpers/RFC3966.test.js.map +1 -0
- package/es6-modern/helpers/applyInternationalSeparatorStyle.js +36 -0
- package/es6-modern/helpers/applyInternationalSeparatorStyle.js.map +1 -0
- package/es6-modern/helpers/applyInternationalSeparatorStyle.test.js.map +1 -0
- package/es6-modern/helpers/checkNumberLength.js +112 -0
- package/es6-modern/helpers/checkNumberLength.js.map +1 -0
- package/es6-modern/helpers/checkNumberLength.test.js.map +1 -0
- package/es6-modern/helpers/extension/createExtensionPattern.js +93 -0
- package/es6-modern/helpers/extension/createExtensionPattern.js.map +1 -0
- package/es6-modern/helpers/extension/extractExtension.js +30 -0
- package/es6-modern/helpers/extension/extractExtension.js.map +1 -0
- package/es6-modern/helpers/extractCountryCallingCode.js +142 -0
- package/es6-modern/helpers/extractCountryCallingCode.js.map +1 -0
- package/es6-modern/helpers/extractCountryCallingCode.test.js.map +1 -0
- package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +49 -0
- package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -0
- package/es6-modern/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +66 -0
- package/es6-modern/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -0
- package/es6-modern/helpers/extractNationalNumber.js +117 -0
- package/es6-modern/helpers/extractNationalNumber.js.map +1 -0
- package/es6-modern/helpers/extractNationalNumber.test.js.map +1 -0
- package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +102 -0
- package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -0
- package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -0
- package/es6-modern/helpers/extractPhoneContext.js +82 -0
- package/es6-modern/helpers/extractPhoneContext.js.map +1 -0
- package/es6-modern/helpers/extractPhoneContext.test.js.map +1 -0
- package/es6-modern/helpers/formatNationalNumberUsingFormat.js +34 -0
- package/es6-modern/helpers/formatNationalNumberUsingFormat.js.map +1 -0
- package/es6-modern/helpers/getCountryByCallingCode.js +30 -0
- package/es6-modern/helpers/getCountryByCallingCode.js.map +1 -0
- package/es6-modern/helpers/getCountryByNationalNumber.js +76 -0
- package/es6-modern/helpers/getCountryByNationalNumber.js.map +1 -0
- package/es6-modern/helpers/getIddPrefix.js +26 -0
- package/es6-modern/helpers/getIddPrefix.js.map +1 -0
- package/es6-modern/helpers/getNumberType.js +81 -0
- package/es6-modern/helpers/getNumberType.js.map +1 -0
- package/es6-modern/helpers/getNumberType.test.js.map +1 -0
- package/es6-modern/helpers/getPossibleCountriesForNumber.js +28 -0
- package/es6-modern/helpers/getPossibleCountriesForNumber.js.map +1 -0
- package/es6-modern/helpers/isObject.js +5 -0
- package/es6-modern/helpers/isObject.js.map +1 -0
- package/es6-modern/helpers/isViablePhoneNumber.js +77 -0
- package/es6-modern/helpers/isViablePhoneNumber.js.map +1 -0
- package/es6-modern/helpers/matchesEntirely.js +12 -0
- package/es6-modern/helpers/matchesEntirely.js.map +1 -0
- package/es6-modern/helpers/matchesEntirely.test.js.map +1 -0
- package/es6-modern/helpers/mergeArrays.js +23 -0
- package/es6-modern/helpers/mergeArrays.js.map +1 -0
- package/es6-modern/helpers/mergeArrays.test.js.map +1 -0
- package/es6-modern/helpers/parseDigits.js +111 -0
- package/es6-modern/helpers/parseDigits.js.map +1 -0
- package/es6-modern/helpers/parseDigits.test.js.map +1 -0
- package/es6-modern/helpers/stripIddPrefix.js +29 -0
- package/es6-modern/helpers/stripIddPrefix.js.map +1 -0
- package/es6-modern/helpers/stripIddPrefix.test.js.map +1 -0
- package/es6-modern/isPossible.js +77 -0
- package/es6-modern/isPossible.js.map +1 -0
- package/es6-modern/isPossible.test.js.map +1 -0
- package/es6-modern/isPossiblePhoneNumber.js +16 -0
- package/es6-modern/isPossiblePhoneNumber.js.map +1 -0
- package/es6-modern/isPossiblePhoneNumber.test.js.map +1 -0
- package/es6-modern/isValid.js +57 -0
- package/es6-modern/isValid.js.map +1 -0
- package/es6-modern/isValid.test.js.map +1 -0
- package/es6-modern/isValidPhoneNumber.js +16 -0
- package/es6-modern/isValidPhoneNumber.js.map +1 -0
- package/es6-modern/isValidPhoneNumber.test.js.map +1 -0
- package/es6-modern/legacy/PhoneNumberSearch.js +109 -0
- package/es6-modern/legacy/PhoneNumberSearch.js.map +1 -0
- package/es6-modern/legacy/findNumbers.js +16 -0
- package/es6-modern/legacy/findNumbers.js.map +1 -0
- package/es6-modern/legacy/findNumbers.test.js.map +1 -0
- package/es6-modern/legacy/findPhoneNumbers.js +26 -0
- package/es6-modern/legacy/findPhoneNumbers.js.map +1 -0
- package/es6-modern/legacy/findPhoneNumbers.test.js.map +1 -0
- package/es6-modern/legacy/findPhoneNumbersInitialImplementation.js +79 -0
- package/es6-modern/legacy/findPhoneNumbersInitialImplementation.js.map +1 -0
- package/es6-modern/legacy/format.js +97 -0
- package/es6-modern/legacy/format.js.map +1 -0
- package/es6-modern/legacy/format.test.js.map +1 -0
- package/es6-modern/legacy/getNumberType.js +104 -0
- package/es6-modern/legacy/getNumberType.js.map +1 -0
- package/es6-modern/legacy/getNumberType.test.js.map +1 -0
- package/es6-modern/legacy/isPossibleNumber.js +30 -0
- package/es6-modern/legacy/isPossibleNumber.js.map +1 -0
- package/es6-modern/legacy/isPossibleNumber.test.js.map +1 -0
- package/es6-modern/legacy/isValidNumber.js +17 -0
- package/es6-modern/legacy/isValidNumber.js.map +1 -0
- package/es6-modern/legacy/isValidNumber.test.js.map +1 -0
- package/es6-modern/legacy/isValidNumberForRegion.js +65 -0
- package/es6-modern/legacy/isValidNumberForRegion.js.map +1 -0
- package/es6-modern/legacy/isValidNumberForRegion.test.js.map +1 -0
- package/es6-modern/legacy/isValidNumberForRegion_.js +14 -0
- package/es6-modern/legacy/isValidNumberForRegion_.js.map +1 -0
- package/es6-modern/legacy/parse.js +11 -0
- package/es6-modern/legacy/parse.js.map +1 -0
- package/es6-modern/legacy/parse.test.js.map +1 -0
- package/es6-modern/legacy/searchNumbers.js +32 -0
- package/es6-modern/legacy/searchNumbers.js.map +1 -0
- package/es6-modern/legacy/searchNumbers.test.js.map +1 -0
- package/es6-modern/metadata.js +494 -0
- package/es6-modern/metadata.js.map +1 -0
- package/es6-modern/metadata.test.js.map +1 -0
- package/es6-modern/normalizeArguments.js +52 -0
- package/es6-modern/normalizeArguments.js.map +1 -0
- package/es6-modern/parse.js +341 -0
- package/es6-modern/parse.js.map +1 -0
- package/es6-modern/parse.test.js.map +1 -0
- package/es6-modern/parseIncompletePhoneNumber.js +70 -0
- package/es6-modern/parseIncompletePhoneNumber.js.map +1 -0
- package/es6-modern/parseIncompletePhoneNumber.test.js.map +1 -0
- package/es6-modern/parsePhoneNumber.js +11 -0
- package/es6-modern/parsePhoneNumber.js.map +1 -0
- package/es6-modern/parsePhoneNumber.test.js.map +1 -0
- package/es6-modern/parsePhoneNumberWithError.js +11 -0
- package/es6-modern/parsePhoneNumberWithError.js.map +1 -0
- package/es6-modern/parsePhoneNumberWithError.test.js.map +1 -0
- package/es6-modern/parsePhoneNumberWithError_.js +8 -0
- package/es6-modern/parsePhoneNumberWithError_.js.map +1 -0
- package/es6-modern/parsePhoneNumber_.js +24 -0
- package/es6-modern/parsePhoneNumber_.js.map +1 -0
- package/es6-modern/searchPhoneNumbersInText.js +31 -0
- package/es6-modern/searchPhoneNumbersInText.js.map +1 -0
- package/es6-modern/searchPhoneNumbersInText.test.js.map +1 -0
- package/es6-modern/tools/semver-compare.js +27 -0
- package/es6-modern/tools/semver-compare.js.map +1 -0
- package/es6-modern/tools/semver-compare.test.js.map +1 -0
- package/es6-modern/validatePhoneNumberLength.js +35 -0
- package/es6-modern/validatePhoneNumberLength.js.map +1 -0
- package/es6-modern/validatePhoneNumberLength.test.js.map +1 -0
- package/index.cjs +4 -0
- package/index.cjs.js +4 -0
- package/index.d.cts +5 -3
- package/index.d.ts +5 -3
- package/index.js +5 -0
- package/max/es6/exports/AsYouType.js +11 -0
- package/max/es6/exports/Metadata.js +11 -0
- package/max/es6/exports/PhoneNumber.js +11 -0
- package/max/es6/exports/PhoneNumberMatcher.js +11 -0
- package/max/es6/exports/findNumbers.js +6 -0
- package/max/es6/exports/findPhoneNumbersInText.js +6 -0
- package/max/es6/exports/formatIncompletePhoneNumber.js +6 -0
- package/max/es6/exports/getCountries.js +6 -0
- package/max/es6/exports/getCountryCallingCode.js +6 -0
- package/max/es6/exports/getExampleNumber.js +6 -0
- package/max/es6/exports/getExtPrefix.js +6 -0
- package/max/es6/exports/isPossiblePhoneNumber.js +6 -0
- package/max/es6/exports/isSupportedCountry.js +6 -0
- package/max/es6/exports/isValidPhoneNumber.js +6 -0
- package/max/es6/exports/parsePhoneNumber.js +7 -0
- package/max/es6/exports/parsePhoneNumberWithError.js +7 -0
- package/max/es6/exports/searchNumbers.js +6 -0
- package/max/es6/exports/searchPhoneNumbersInText.js +6 -0
- package/max/es6/exports/validatePhoneNumberLength.js +6 -0
- package/max/es6/exports/withMetadataArgument.js +13 -0
- package/max/es6/index.d.cts +2 -0
- package/max/es6/index.d.ts +2 -0
- package/max/es6/index.js +44 -0
- package/max/es6/package.json +12 -0
- package/max/index.cjs +5 -0
- package/max/index.cjs.js +5 -0
- package/max/index.d.cts +3 -1
- package/max/index.d.ts +3 -1
- package/max/index.js +4 -0
- package/min/es6/exports/AsYouType.js +11 -0
- package/min/es6/exports/Metadata.js +11 -0
- package/min/es6/exports/PhoneNumber.js +11 -0
- package/min/es6/exports/PhoneNumberMatcher.js +11 -0
- package/min/es6/exports/findNumbers.js +6 -0
- package/min/es6/exports/findPhoneNumbersInText.js +6 -0
- package/min/es6/exports/formatIncompletePhoneNumber.js +6 -0
- package/min/es6/exports/getCountries.js +6 -0
- package/min/es6/exports/getCountryCallingCode.js +6 -0
- package/min/es6/exports/getExampleNumber.js +6 -0
- package/min/es6/exports/getExtPrefix.js +6 -0
- package/min/es6/exports/isPossiblePhoneNumber.js +6 -0
- package/min/es6/exports/isSupportedCountry.js +6 -0
- package/min/es6/exports/isValidPhoneNumber.js +6 -0
- package/min/es6/exports/parsePhoneNumber.js +7 -0
- package/min/es6/exports/parsePhoneNumberWithError.js +7 -0
- package/min/es6/exports/searchNumbers.js +6 -0
- package/min/es6/exports/searchPhoneNumbersInText.js +6 -0
- package/min/es6/exports/validatePhoneNumberLength.js +6 -0
- package/min/es6/exports/withMetadataArgument.js +13 -0
- package/min/es6/index.d.cts +2 -0
- package/min/es6/index.d.ts +2 -0
- package/min/es6/index.js +44 -0
- package/min/es6/package.json +12 -0
- package/min/index.cjs +5 -0
- package/min/index.cjs.js +5 -0
- package/min/index.d.cts +3 -1
- package/min/index.d.ts +3 -1
- package/min/index.js +3 -0
- package/mobile/es6/exports/AsYouType.js +11 -0
- package/mobile/es6/exports/Metadata.js +11 -0
- package/mobile/es6/exports/PhoneNumber.js +11 -0
- package/mobile/es6/exports/PhoneNumberMatcher.js +11 -0
- package/mobile/es6/exports/findNumbers.js +6 -0
- package/mobile/es6/exports/findPhoneNumbersInText.js +6 -0
- package/mobile/es6/exports/formatIncompletePhoneNumber.js +6 -0
- package/mobile/es6/exports/getCountries.js +6 -0
- package/mobile/es6/exports/getCountryCallingCode.js +6 -0
- package/mobile/es6/exports/getExampleNumber.js +6 -0
- package/mobile/es6/exports/getExtPrefix.js +6 -0
- package/mobile/es6/exports/isPossiblePhoneNumber.js +6 -0
- package/mobile/es6/exports/isSupportedCountry.js +6 -0
- package/mobile/es6/exports/isValidPhoneNumber.js +6 -0
- package/mobile/es6/exports/parsePhoneNumber.js +7 -0
- package/mobile/es6/exports/parsePhoneNumberWithError.js +7 -0
- package/mobile/es6/exports/searchNumbers.js +6 -0
- package/mobile/es6/exports/searchPhoneNumbersInText.js +6 -0
- package/mobile/es6/exports/validatePhoneNumberLength.js +6 -0
- package/mobile/es6/exports/withMetadataArgument.js +13 -0
- package/mobile/es6/index.d.cts +2 -0
- package/mobile/es6/index.d.ts +2 -0
- package/mobile/es6/index.js +44 -0
- package/mobile/es6/package.json +12 -0
- package/mobile/index.cjs +5 -0
- package/mobile/index.cjs.js +5 -0
- package/mobile/index.d.cts +3 -1
- package/mobile/index.d.ts +3 -1
- package/mobile/index.js +4 -0
- package/package.json +28 -9
- package/types.d.cts +54 -21
- package/types.d.ts +54 -21
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","names":["matchesEntirely","formatNationalNumberUsingFormat","Metadata","getCountryCallingCode","getIddPrefix","formatRFC3966","DEFAULT_OPTIONS","formatExtension","formattedNumber","extension","metadata","ext","formatNumber","input","format","options","merge","country","hasCountry","Error","selectNumberingPlan","countryCallingCode","phone","nationalNumber","v2","number","formatNationalNumber","carrierCode","addExtension","fromCountry","formatIDD","formatAs","chooseFormatForNumber","formats","useInternationalFormat","withNationalPrefix","nationalPrefixIsOptionalWhenFormattingInNationalFormat","nationalPrefix","availableFormats","pickFirstMatchingElement","leadingDigitsPatterns","length","lastLeadingDigitsPattern","search","pattern","fromCountryCallingCode","iddPrefix","undefined","objects","i","key","elements","testFunction"],"sources":["../source/format.js"],"sourcesContent":["// This is a port of Google Android `libphonenumber`'s\r\n// `phonenumberutil.js` of December 31th, 2018.\r\n//\r\n// https://github.com/googlei18n/libphonenumber/commits/master/javascript/i18n/phonenumbers/phonenumberutil.js\r\n\r\nimport matchesEntirely from './helpers/matchesEntirely.js'\r\nimport formatNationalNumberUsingFormat from './helpers/formatNationalNumberUsingFormat.js'\r\nimport Metadata, { getCountryCallingCode } from './metadata.js'\r\nimport getIddPrefix from './helpers/getIddPrefix.js'\r\nimport { formatRFC3966 } from './helpers/RFC3966.js'\r\n\r\nconst DEFAULT_OPTIONS = {\r\n\tformatExtension: (formattedNumber, extension, metadata) => `${formattedNumber}${metadata.ext()}${extension}`\r\n}\r\n\r\n/**\r\n * Formats a phone number.\r\n *\r\n * format(phoneNumberInstance, 'INTERNATIONAL', { ..., v2: true }, metadata)\r\n * format(phoneNumberInstance, 'NATIONAL', { ..., v2: true }, metadata)\r\n *\r\n * format({ phone: '8005553535', country: 'RU' }, 'INTERNATIONAL', { ... }, metadata)\r\n * format({ phone: '8005553535', country: 'RU' }, 'NATIONAL', undefined, metadata)\r\n *\r\n * @param {object|PhoneNumber} input — If `options.v2: true` flag is passed, the `input` should be a `PhoneNumber` instance. Otherwise, it should be an object of shape `{ phone: '...', country: '...' }`.\r\n * @param {string} format\r\n * @param {object} [options]\r\n * @param {object} metadata\r\n * @return {string}\r\n */\r\nexport default function formatNumber(input, format, options, metadata) {\r\n\t// Apply default options.\r\n\tif (options) {\r\n\t\t// Using ES6 \"rest spread\" syntax here didn't work with `babel`/`istanbul`\r\n\t\t// for some weird reason: this line of code would cause the code coverage\r\n\t\t// to show as not 100%. That's because `babel`/`istanbul`, for some weird reason,\r\n\t\t// apparently doesn't know how to properly exclude Babel polyfills from code coverage.\r\n\t\t//\r\n\t\t// options = { ...DEFAULT_OPTIONS, ...options }\r\n\t\t//\r\n\t\toptions = merge({}, DEFAULT_OPTIONS, options)\r\n\t} else {\r\n\t\toptions = DEFAULT_OPTIONS\r\n\t}\r\n\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\t// Normally, the `input` object is supposed to be a `PhoneNumber` class instance.\r\n\t// Also, according to the `PhoneNumber` class source code, `country` can't be \"001\".\r\n\t// It means that normally `input.country` or `input.countryCallingCode` is supposed\r\n\t// to be present because either of the two is always required to exist in a `PhoneNumber` instance.\r\n\t// This means that realistically, it's gonna step into either the first `if`\r\n\t// or the following `else if`, and normally it won't even reach the legacy-compatibility\r\n\t// `else return input.phone || ''` part.\r\n\t// So normally, it won't ever return an empty string here.\r\n\tif (input.country && input.country !== '001') {\r\n\t\t// Validate `input.country`.\r\n\t\tif (!metadata.hasCountry(input.country)) {\r\n\t\t\tthrow new Error(`Unknown country: ${input.country}`)\r\n\t\t}\r\n\t\tmetadata.selectNumberingPlan(input.country)\r\n\t}\r\n\telse if (input.countryCallingCode) {\r\n\t\tmetadata.selectNumberingPlan(input.countryCallingCode)\r\n\t}\r\n\telse return input.phone || ''\r\n\r\n\tconst countryCallingCode = metadata.countryCallingCode()\r\n\r\n\tconst nationalNumber = options.v2 ? input.nationalNumber : input.phone\r\n\r\n\t// This variable should have been declared inside `case`s\r\n\t// but Babel has a bug and it says \"duplicate variable declaration\".\r\n\tlet number\r\n\r\n\tswitch (format) {\r\n\t\tcase 'NATIONAL':\r\n\t\t\t// Normally, the `input` object is supposed to be a `PhoneNumber` class instance,\r\n\t\t\t// and a `PhoneNumber` class instance is always required to have a `nationalNumber`.\r\n\t\t\t// This means that the `if (!nationalNumber)` below is just for legacy-compatibility\r\n\t\t\t// and it normally can't really happen, so normally it won't ever return an empty string here.\r\n\t\t\tif (!nationalNumber) {\r\n\t\t\t\treturn ''\r\n\t\t\t}\r\n\t\t\tnumber = formatNationalNumber(nationalNumber, input.carrierCode, 'NATIONAL', metadata, options)\r\n\t\t\treturn addExtension(number, input.ext, metadata, options.formatExtension)\r\n\r\n\t\tcase 'INTERNATIONAL':\r\n\t\t\t// Legacy argument support.\r\n\t\t\t// (`{ country: ..., phone: '' }`)\r\n\t\t\tif (!nationalNumber) {\r\n\t\t\t\treturn `+${countryCallingCode}`\r\n\t\t\t}\r\n\t\t\tnumber = formatNationalNumber(nationalNumber, null, 'INTERNATIONAL', metadata, options)\r\n\t\t\tnumber = `+${countryCallingCode} ${number}`\r\n\t\t\treturn addExtension(number, input.ext, metadata, options.formatExtension)\r\n\r\n\t\tcase 'E.164':\r\n\t\t\t// `E.164` doesn't define \"phone number extensions\".\r\n\t\t\treturn `+${countryCallingCode}${nationalNumber}`\r\n\r\n\t\tcase 'RFC3966':\r\n\t\t\treturn formatRFC3966({\r\n\t\t\t\tnumber: `+${countryCallingCode}${nationalNumber}`,\r\n\t\t\t\text: input.ext\r\n\t\t\t})\r\n\r\n\t\t// For reference, here's Google's IDD formatter:\r\n\t\t// https://github.com/google/libphonenumber/blob/32719cf74e68796788d1ca45abc85dcdc63ba5b9/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L1546\r\n\t\t// Not saying that this IDD formatter replicates it 1:1, but it seems to work.\r\n\t\t// Who would even need to format phone numbers in IDD format anyway?\r\n\t\tcase 'IDD':\r\n\t\t\t// If the required `fromCountry` parameter is not passed, it will return `undefined`.\r\n\t\t\tif (!options.fromCountry) {\r\n\t\t\t\treturn\r\n\t\t\t\t// throw new Error('`fromCountry` option not passed for IDD-prefixed formatting.')\r\n\t\t\t}\r\n\t\t\tconst formattedNumber = formatIDD(\r\n\t\t\t\tnationalNumber,\r\n\t\t\t\tinput.carrierCode,\r\n\t\t\t\tcountryCallingCode,\r\n\t\t\t\toptions.fromCountry,\r\n\t\t\t\tmetadata\r\n\t\t\t)\r\n\t\t\t// If the country of the phone number doesn't support IDD calling, it will return `undefined`.\r\n\t\t\tif (!formattedNumber) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\treturn addExtension(formattedNumber, input.ext, metadata, options.formatExtension)\r\n\r\n\t\tdefault:\r\n\t\t\tthrow new Error(`Unknown \"format\" argument passed to \"formatNumber()\": \"${format}\"`)\r\n\t}\r\n}\r\n\r\nfunction formatNationalNumber(number, carrierCode, formatAs, metadata, options) {\r\n\tconst format = chooseFormatForNumber(metadata.formats(), number)\r\n\tif (!format) {\r\n\t\treturn number\r\n\t}\r\n\treturn formatNationalNumberUsingFormat(\r\n\t\tnumber,\r\n\t\tformat,\r\n\t\t{\r\n\t\t\tuseInternationalFormat: formatAs === 'INTERNATIONAL',\r\n\t\t\twithNationalPrefix: format.nationalPrefixIsOptionalWhenFormattingInNationalFormat() && (options && options.nationalPrefix === false) ? false : true,\r\n\t\t\tcarrierCode,\r\n\t\t\tmetadata\r\n\t\t}\r\n\t)\r\n}\r\n\r\nexport function chooseFormatForNumber(availableFormats, nationalNumber) {\r\n\t// Using a `for ... of` loop here didn't work with `babel`/`istanbul`:\r\n\t// for some weird reason, it showed code coverage less than 100%.\r\n\t// That's because `babel`/`istanbul`, for some weird reason,\r\n\t// apparently doesn't know how to properly exclude Babel polyfills from code coverage.\r\n\t//\r\n\t// for (const format of availableFormats) { ... }\r\n\t//\r\n\treturn pickFirstMatchingElement(availableFormats, (format) => {\r\n\t\t// Validate leading digits.\r\n\t\t// The test case for \"else path\" could be found by searching for\r\n\t\t// \"format.leadingDigitsPatterns().length === 0\".\r\n\t\tif (format.leadingDigitsPatterns().length > 0) {\r\n\t\t\t// The last leading_digits_pattern is used here, as it is the most detailed\r\n\t\t\tconst lastLeadingDigitsPattern = format.leadingDigitsPatterns()[format.leadingDigitsPatterns().length - 1]\r\n\t\t\t// If leading digits don't match then move on to the next phone number format\r\n\t\t\tif (nationalNumber.search(lastLeadingDigitsPattern) !== 0) {\r\n\t\t\t\treturn false\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Check that the national number matches the phone number format regular expression\r\n\t\treturn matchesEntirely(nationalNumber, format.pattern())\r\n\t})\r\n}\r\n\r\nfunction addExtension(formattedNumber, ext, metadata, formatExtension) {\r\n\treturn ext ? formatExtension(formattedNumber, ext, metadata) : formattedNumber\r\n}\r\n\r\nfunction formatIDD(\r\n\tnationalNumber,\r\n\tcarrierCode,\r\n\tcountryCallingCode,\r\n\tfromCountry,\r\n\tmetadata\r\n) {\r\n\tconst fromCountryCallingCode = getCountryCallingCode(fromCountry, metadata.metadata)\r\n\t// When calling within the same country calling code.\r\n\tif (fromCountryCallingCode === countryCallingCode) {\r\n\t\tconst formattedNumber = formatNationalNumber(nationalNumber, carrierCode, 'NATIONAL', metadata)\r\n\t\t// For NANPA regions, return the national format for these regions\r\n\t\t// but prefix it with the country calling code.\r\n\t\tif (countryCallingCode === '1') {\r\n\t\t\treturn countryCallingCode + ' ' + formattedNumber\r\n\t\t}\r\n\t\t// If regions share a country calling code, the country calling code need\r\n\t\t// not be dialled. This also applies when dialling within a region, so this\r\n\t\t// if clause covers both these cases. Technically this is the case for\r\n\t\t// dialling from La Reunion to other overseas departments of France (French\r\n\t\t// Guiana, Martinique, Guadeloupe), but not vice versa - so we don't cover\r\n\t\t// this edge case for now and for those cases return the version including\r\n\t\t// country calling code. Details here:\r\n\t\t// http://www.petitfute.com/voyage/225-info-pratiques-reunion\r\n\t\t//\r\n\t\treturn formattedNumber\r\n\t}\r\n\tconst iddPrefix = getIddPrefix(fromCountry, undefined, metadata.metadata)\r\n\tif (iddPrefix) {\r\n\t\treturn `${iddPrefix} ${countryCallingCode} ${formatNationalNumber(nationalNumber, null, 'INTERNATIONAL', metadata)}`\r\n\t}\r\n}\r\n\r\nfunction merge(...objects) {\r\n\tlet i = 1\r\n\twhile (i < objects.length) {\r\n\t\tif (objects[i]) {\r\n\t\t\tfor (const key in objects[i]) {\r\n\t\t\t\tobjects[0][key] = objects[i][key]\r\n\t\t\t}\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\treturn objects[0]\r\n}\r\n\r\nfunction pickFirstMatchingElement(elements, testFunction) {\r\n\tlet i = 0\r\n\twhile (i < elements.length) {\r\n\t\tif (testFunction(elements[i])) {\r\n\t\t\treturn elements[i]\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n}"],"mappings":"AAAA;AACA;AACA;AACA;;AAEA,OAAOA,eAAe,MAAM,8BAA8B;AAC1D,OAAOC,+BAA+B,MAAM,8CAA8C;AAC1F,OAAOC,QAAQ,IAAIC,qBAAqB,QAAQ,eAAe;AAC/D,OAAOC,YAAY,MAAM,2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AC,EAAE;QAC7BD,OAAO,CAAC,CAAC,CAAC,CAACE,GAAG,CAAC,GAAGF,OAAO,CAACC,CAAC,CAAC,CAACC,GAAG,CAAC;MAClC;IACD;IACAD,CAAC,EAAE;EACJ;EACA,OAAOD,OAAO,CAAC,CAAC,CAAC;AAClB;AAEA,SAAST,wBAAwBA,CAACY,QAAQ,EAAEC,YAAY,EAAE;EACzD,IAAIH,CAAC,GAAG,CAAC;EACT,OAAOA,CAAC,GAAGE,QAAQ,CAACV,MAAM,EAAE;IAC3B,IAAIW,YAAY,CAACD,QAAQ,CAACF,CAAC,CAAC,CAAC,EAAE;MAC9B,OAAOE,QAAQ,CAACF,CAAC,CAAC;IACnB;IACAA,CAAC,EAAE;EACJ;AACD","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.test.js","names":["describe","it","expect","metadata","type","formatNumber_","parsePhoneNumber","formatNumber","parameters","v2","length","push","undefined","_extends","extract","apply","to","equal","defaultCountry","phone","countryCallingCode","options","formatExtension","number","extension","country","ext","nationalPrefix","thrower","throw","be","fromCountry"],"sources":["../source/format.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\nimport formatNumber_ from './format.js'\r\nimport parsePhoneNumber from './parsePhoneNumber.js'\r\n\r\nfunction formatNumber(...parameters) {\r\n\tlet v2\r\n\tif (parameters.length < 1) {\r\n\t\t// `input` parameter.\r\n\t\tparameters.push(undefined)\r\n\t} else {\r\n\t\t// Convert string `input` to a `PhoneNumber` instance.\r\n\t\tif (typeof parameters[0] === 'string') {\r\n\t\t\tv2 = true\r\n\t\t\tparameters[0] = parsePhoneNumber(parameters[0], {\r\n\t\t\t\t...parameters[2],\r\n\t\t\t\textract: false\r\n\t\t\t}, metadata)\r\n\t\t}\r\n\t}\r\n\tif (parameters.length < 2) {\r\n\t\t// `format` parameter.\r\n\t\tparameters.push(undefined)\r\n\t}\r\n\tif (parameters.length < 3) {\r\n\t\t// `options` parameter.\r\n\t\tparameters.push(undefined)\r\n\t}\r\n\t// Set `v2` flag.\r\n\tparameters[2] = {\r\n\t\tv2,\r\n\t\t...parameters[2]\r\n\t}\r\n\t// Add `metadata` parameter.\r\n\tparameters.push(metadata)\r\n\t// Call the function.\r\n\treturn formatNumber_.apply(this, parameters)\r\n}\r\n\r\ndescribe('format', () => {\r\n\tit('should work with the first argument being a E.164 number', () => {\r\n\t\texpect(formatNumber('+12133734253', 'NATIONAL')).to.equal('(213) 373-4253')\r\n\t\texpect(formatNumber('+12133734253', 'INTERNATIONAL')).to.equal('+1 213 373 4253')\r\n\r\n\t\t// Invalid number.\r\n\t\texpect(formatNumber('+12111111111', 'NATIONAL')).to.equal('(211) 111-1111')\r\n\r\n\t\t// Formatting invalid E.164 numbers.\r\n\t\texpect(formatNumber('+11111', 'INTERNATIONAL')).to.equal('+1 1111')\r\n\t\texpect(formatNumber('+11111', 'NATIONAL')).to.equal('1111')\r\n\t})\r\n\r\n\tit('should work with the first object argument expanded', () => {\r\n\t\texpect(formatNumber('2133734253', 'NATIONAL', { defaultCountry: 'US' })).to.equal('(213) 373-4253')\r\n\t\texpect(formatNumber('2133734253', 'INTERNATIONAL', { defaultCountry: 'US' })).to.equal('+1 213 373 4253')\r\n\t})\r\n\r\n\tit('should format using formats with no leading digits (`format.leadingDigitsPatterns().length === 0`)', () => {\r\n\t\texpect(\r\n formatNumber({ phone: '12345678901', countryCallingCode: 888 }, 'INTERNATIONAL')\r\n ).to.equal('+888 123 456 78901')\r\n\t})\r\n\r\n\tit('should sort out the arguments', () => {\r\n\t\tconst options = {\r\n\t\t\tformatExtension: (number, extension) => `${number} доб. ${extension}`\r\n\t\t}\r\n\r\n\t\texpect(formatNumber({\r\n\t\t\tphone : '8005553535',\r\n\t\t\tcountry : 'RU',\r\n\t\t\text : '123'\r\n\t\t},\r\n\t\t'NATIONAL', options)).to.equal('8 (800) 555-35-35 доб. 123')\r\n\r\n\t\t// Parse number from string.\r\n\t\texpect(formatNumber('+78005553535', 'NATIONAL', options)).to.equal('8 (800) 555-35-35')\r\n\t\texpect(\r\n formatNumber('8005553535', 'NATIONAL', { ...options, defaultCountry: 'RU' })\r\n ).to.equal('8 (800) 555-35-35')\r\n\t})\r\n\r\n\tit('should format with national prefix when specifically instructed', () => {\r\n\t\t// With national prefix.\r\n\t\texpect(formatNumber('88005553535', 'NATIONAL', { defaultCountry: 'RU' })).to.equal('8 (800) 555-35-35')\r\n\t\t// Without national prefix via an explicitly set option.\r\n\t\texpect(\r\n formatNumber('88005553535', 'NATIONAL', { nationalPrefix: false, defaultCountry: 'RU' })\r\n ).to.equal('800 555-35-35')\r\n\t})\r\n\r\n\tit('should format valid phone numbers', () => {\r\n\t\t// Switzerland\r\n\t\texpect(formatNumber({ country: 'CH', phone: '446681800' }, 'INTERNATIONAL')).to.equal('+41 44 668 18 00')\r\n\t\texpect(formatNumber({ country: 'CH', phone: '446681800' }, 'E.164')).to.equal('+41446681800')\r\n\t\texpect(formatNumber({ country: 'CH', phone: '446681800' }, 'RFC3966')).to.equal('tel:+41446681800')\r\n\t\texpect(formatNumber({ country: 'CH', phone: '446681800' }, 'NATIONAL')).to.equal('044 668 18 00')\r\n\r\n\t\t// France\r\n\t\texpect(formatNumber({ country: 'FR', phone: '169454850' }, 'NATIONAL')).to.equal('01 69 45 48 50')\r\n\r\n\t\t// Kazakhstan\r\n\t\texpect(formatNumber('+7 702 211 1111', 'NATIONAL')).to.equal('8 (702) 211 1111')\r\n\t})\r\n\r\n\tit('should format national numbers with national prefix even if it\\'s optional', () => {\r\n\t\t// Russia\r\n\t\texpect(formatNumber({ country: 'RU', phone: '9991234567' }, 'NATIONAL')).to.equal('8 (999) 123-45-67')\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\tlet thrower\r\n\r\n\t\t// // No phone number\r\n\t\t// formatNumber('', 'INTERNATIONAL', { defaultCountry: 'RU' }).should.equal('')\r\n\t\t// formatNumber('', 'NATIONAL', { defaultCountry: 'RU' }).should.equal('')\r\n\r\n\t\texpect(formatNumber({ country: 'RU', phone: '' }, 'INTERNATIONAL')).to.equal('+7')\r\n\t\texpect(formatNumber({ country: 'RU', phone: '' }, 'NATIONAL')).to.equal('')\r\n\r\n\t\t// No suitable format\r\n\t\texpect(formatNumber('+121337342530', 'NATIONAL', { defaultCountry: 'US' })).to.equal('21337342530')\r\n\t\t// No suitable format (leading digits mismatch)\r\n\t\texpect(formatNumber('28199999', 'NATIONAL', { defaultCountry: 'AD' })).to.equal('28199999')\r\n\r\n\t\t// // Numerical `value`\r\n\t\t// thrower = () => formatNumber(89150000000, 'NATIONAL', { defaultCountry: 'RU' })\r\n\t\t// thrower.should.throw('A phone number must either be a string or an object of shape { phone, [country] }.')\r\n\r\n\t\t// // No metadata for country\r\n\t\t// expect(() => formatNumber('+121337342530', 'NATIONAL', { defaultCountry: 'USA' })).to.throw('Unknown country')\r\n\t\t// expect(() => formatNumber('21337342530', 'NATIONAL', { defaultCountry: 'USA' })).to.throw('Unknown country')\r\n\r\n\t\t// No format type\r\n\t\tthrower = () => formatNumber('+123')\r\n\t\texpect(thrower).to.throw('Unknown \"format\" argument')\r\n\r\n\t\t// Unknown format type\r\n\t\tthrower = () => formatNumber('123', 'Gay', { defaultCountry: 'US' })\r\n\t\texpect(thrower).to.throw('Unknown \"format\" argument')\r\n\r\n\t\t// // No metadata\r\n\t\t// thrower = () => _formatNumber('123', 'E.164', { defaultCountry: 'RU' })\r\n\t\t// thrower.should.throw('`metadata`')\r\n\r\n\t\t// No formats\r\n\t\texpect(formatNumber('012345', 'NATIONAL', { defaultCountry: 'AC' })).to.equal('012345')\r\n\r\n\t\t// No `fromCountry` for `IDD` format.\r\n\t\texpect(formatNumber('+78005553535', 'IDD')).to.be.undefined\r\n\r\n\t\t// `fromCountry` has no default IDD prefix.\r\n\t\texpect(formatNumber('+78005553535', 'IDD', { fromCountry: 'BO' })).to.be.undefined\r\n\r\n\t\t// No such country.\r\n\t\texpect(() => formatNumber({ phone: '123', country: 'USA' }, 'NATIONAL')).to.throw('Unknown country')\r\n\t})\r\n\r\n\tit('should format phone number extensions', () => {\r\n\t\t// National\r\n\t\texpect(formatNumber({\r\n\t\t\tcountry: 'US',\r\n\t\t\tphone: '2133734253',\r\n\t\t\text: '123'\r\n\t\t},\r\n\t\t'NATIONAL')).to.equal('(213) 373-4253 ext. 123')\r\n\r\n\t\t// International\r\n\t\texpect(formatNumber({\r\n\t\t\tcountry : 'US',\r\n\t\t\tphone : '2133734253',\r\n\t\t\text : '123'\r\n\t\t},\r\n\t\t'INTERNATIONAL')).to.equal('+1 213 373 4253 ext. 123')\r\n\r\n\t\t// International\r\n\t\texpect(formatNumber({\r\n\t\t\tcountry : 'US',\r\n\t\t\tphone : '2133734253',\r\n\t\t\text : '123'\r\n\t\t},\r\n\t\t'INTERNATIONAL')).to.equal('+1 213 373 4253 ext. 123')\r\n\r\n\t\t// E.164\r\n\t\texpect(formatNumber({\r\n\t\t\tcountry : 'US',\r\n\t\t\tphone : '2133734253',\r\n\t\t\text : '123'\r\n\t\t},\r\n\t\t'E.164')).to.equal('+12133734253')\r\n\r\n\t\t// RFC3966\r\n\t\texpect(formatNumber({\r\n\t\t\tcountry : 'US',\r\n\t\t\tphone : '2133734253',\r\n\t\t\text : '123'\r\n\t\t},\r\n\t\t'RFC3966')).to.equal('tel:+12133734253;ext=123')\r\n\r\n\t\t// Custom ext prefix.\r\n\t\texpect(formatNumber({\r\n\t\t\tcountry : 'GB',\r\n\t\t\tphone : '7912345678',\r\n\t\t\text : '123'\r\n\t\t},\r\n\t\t'INTERNATIONAL')).to.equal('+44 7912 345678 x123')\r\n\t})\r\n\r\n\tit('should work with Argentina numbers', () => {\r\n\t\t// The same mobile number is written differently\r\n\t\t// in different formats in Argentina:\r\n\t\t// `9` gets prepended in international format.\r\n\t\texpect(formatNumber({ country: 'AR', phone: '3435551212' }, 'INTERNATIONAL')).to.equal('+54 3435 55 1212')\r\n\t\texpect(formatNumber({ country: 'AR', phone: '3435551212' }, 'NATIONAL')).to.equal('03435 55-1212')\r\n\t})\r\n\r\n\tit('should work with Mexico numbers', () => {\r\n\t\t// Fixed line.\r\n\t\texpect(formatNumber({ country: 'MX', phone: '4499780001' }, 'INTERNATIONAL')).to.equal('+52 449 978 0001')\r\n\t\texpect(formatNumber({ country: 'MX', phone: '4499780001' }, 'NATIONAL')).to.equal('449 978 0001')\r\n\t\t\t// or '(449)978-0001'.\r\n\t\t// Mobile.\r\n\t\t// `1` is prepended before area code to mobile numbers in international format.\r\n\t\texpect(formatNumber({ country: 'MX', phone: '3312345678' }, 'INTERNATIONAL')).to.equal('+52 33 1234 5678')\r\n\t\texpect(formatNumber({ country: 'MX', phone: '3312345678' }, 'NATIONAL')).to.equal('33 1234 5678')\r\n\t\t\t// or '045 33 1234-5678'.\r\n\t})\r\n\r\n\tit('should format possible numbers', () => {\r\n\t\texpect(formatNumber({ countryCallingCode: '7', phone: '1111111111' }, 'E.164')).to.equal('+71111111111')\r\n\r\n\t\texpect(formatNumber({ countryCallingCode: '7', phone: '1111111111' }, 'NATIONAL')).to.equal('1111111111')\r\n\r\n\t\texpect(\r\n formatNumber({ countryCallingCode: '7', phone: '1111111111' }, 'INTERNATIONAL')\r\n ).to.equal('+7 1111111111')\r\n\t})\r\n\r\n\tit('should format IDD-prefixed number', () => {\r\n\t\t// No `fromCountry`.\r\n\t\texpect(formatNumber('+78005553535', 'IDD')).to.be.undefined\r\n\r\n\t\t// No default IDD prefix.\r\n\t\texpect(formatNumber('+78005553535', 'IDD', { fromCountry: 'BO' })).to.be.undefined\r\n\r\n\t\t// Same country calling code.\r\n\t\texpect(\r\n formatNumber('+12133734253', 'IDD', { fromCountry: 'CA' })\r\n ).to.equal('1 (213) 373-4253')\r\n\t\texpect(\r\n formatNumber('+78005553535', 'IDD', { fromCountry: 'KZ' })\r\n ).to.equal('8 (800) 555-35-35')\r\n\r\n\t\t// formatNumber('+78005553535', 'IDD', { fromCountry: 'US' }).should.equal('01178005553535')\r\n\t\texpect(\r\n formatNumber('+78005553535', 'IDD', { fromCountry: 'US' })\r\n ).to.equal('011 7 800 555 35 35')\r\n\t})\r\n\r\n\tit('should format non-geographic numbering plan phone numbers', () => {\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/323\r\n\t\texpect(formatNumber('+870773111632', 'INTERNATIONAL')).to.equal('+870 773 111 632')\r\n\t\texpect(formatNumber('+870773111632', 'NATIONAL')).to.equal('773 111 632')\r\n\t})\r\n\r\n\tit('should use the default IDD prefix when formatting a phone number', () => {\r\n\t\t// Testing preferred international prefixes with ~ are supported.\r\n\t\t// (\"~\" designates waiting on a line until proceeding with the input).\r\n\t\texpect(formatNumber('+390236618300', 'IDD', { fromCountry: 'BY' })).to.equal('8~10 39 02 3661 8300')\r\n\t})\r\n})"],"mappings":";AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,QAAQ,MAAM,sBAAsB,QAAQC,IAAI,EAAE,MAAM;AAC/D,OAAOC,aAAa,MAAM,aAAa;AACvC,OAAOC,gBAAgB,MAAM,uBAAuB;AAEpD,SAASC,YAAYA,CAAC,GAAGC,UAAU,EAAE;EACpC,IAAIC,EAAE;EACN,IAAID,UAAU,CAACE,MAAM,GAAG,CAAC,EAAE;IAC1B;IACAF,UAAU,CAACG,IAAI,CAACC,SAAS,CAAC;EAC3B,CAAC,MAAM;IACN;IACA,IAAI,OAAOJ,UAAU,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;MACtCC,EAAE,GAAG,IAAI;MACTD,UAAU,CAAC,CAAC,CAAC,GAAGF,gBAAgB,CAACE,UAAU,CAAC,CAAC,CAAC,EAAAK,QAAA,KAC1CL,UAAU,CAAC,CAAC,CAAC;QAChBM,OAAO,EAAE;MAAK,IACZX,QAAQ,CAAC;IACb;EACD;EACA,IAAIK,UAAU,CAACE,MAAM,GAAG,CAAC,E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,cAAc,EAAE,KAAK,EAAE;MAAEwB,WAAW,EAAE;IAAK,CAAC,CAC7D,CAAC,CAACf,EAAE,CAACC,KAAK,CAAC,kBAAkB,CAAC;IACpCf,MAAM,CACIK,YAAY,CAAC,cAAc,EAAE,KAAK,EAAE;MAAEwB,WAAW,EAAE;IAAK,CAAC,CAC7D,CAAC,CAACf,EAAE,CAACC,KAAK,CAAC,mBAAmB,CAAC;;IAErC;IACAf,MAAM,CACIK,YAAY,CAAC,cAAc,EAAE,KAAK,EAAE;MAAEwB,WAAW,EAAE;IAAK,CAAC,CAC7D,CAAC,CAACf,EAAE,CAACC,KAAK,CAAC,qBAAqB,CAAC;EACxC,CAAC,CAAC;EAEFhB,EAAE,CAAC,2DAA2D,EAAE,MAAM;IACrE;IACAC,MAAM,CAACK,YAAY,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC,CAACS,EAAE,CAACC,KAAK,CAAC,kBAAkB,CAAC;IACnFf,MAAM,CAACK,YAAY,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC,CAACS,EAAE,CAACC,KAAK,CAAC,aAAa,CAAC;EAC1E,CAAC,CAAC;EAEFhB,EAAE,CAAC,kEAAkE,EAAE,MAAM;IAC5E;IACA;IACAC,MAAM,CAACK,YAAY,CAAC,eAAe,EAAE,KAAK,EAAE;MAAEwB,WAAW,EAAE;IAAK,CAAC,CAAC,CAAC,CAACf,EAAE,CAACC,KAAK,CAAC,sBAAsB,CAAC;EACrG,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import AsYouType from './AsYouType.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Formats a (possibly incomplete) phone number.
|
|
5
|
+
* The phone number can be either in E.164 format
|
|
6
|
+
* or in a form of national number digits.
|
|
7
|
+
* @param {string} value - A possibly incomplete phone number. Either in E.164 format or in a form of national number digits.
|
|
8
|
+
* @param {string|object} [optionsOrDefaultCountry] - A two-letter ("ISO 3166-1 alpha-2") country code, or an object of shape `{ defaultCountry?: string, defaultCallingCode?: string }`.
|
|
9
|
+
* @return {string} Formatted (possibly incomplete) phone number.
|
|
10
|
+
*/
|
|
11
|
+
export default function formatIncompletePhoneNumber(value, optionsOrDefaultCountry, metadata) {
|
|
12
|
+
if (!metadata) {
|
|
13
|
+
metadata = optionsOrDefaultCountry;
|
|
14
|
+
optionsOrDefaultCountry = undefined;
|
|
15
|
+
}
|
|
16
|
+
return new AsYouType(optionsOrDefaultCountry, metadata).input(value);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=formatIncompletePhoneNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatIncompletePhoneNumber.js","names":["AsYouType","formatIncompletePhoneNumber","value","optionsOrDefaultCountry","metadata","undefined","input"],"sources":["../source/formatIncompletePhoneNumber.js"],"sourcesContent":["import AsYouType from './AsYouType.js'\r\n\r\n/**\r\n * Formats a (possibly incomplete) phone number.\r\n * The phone number can be either in E.164 format\r\n * or in a form of national number digits.\r\n * @param {string} value - A possibly incomplete phone number. Either in E.164 format or in a form of national number digits.\r\n * @param {string|object} [optionsOrDefaultCountry] - A two-letter (\"ISO 3166-1 alpha-2\") country code, or an object of shape `{ defaultCountry?: string, defaultCallingCode?: string }`.\r\n * @return {string} Formatted (possibly incomplete) phone number.\r\n */\r\nexport default function formatIncompletePhoneNumber(value, optionsOrDefaultCountry, metadata) {\r\n\tif (!metadata) {\r\n\t\tmetadata = optionsOrDefaultCountry\r\n\t\toptionsOrDefaultCountry = undefined\r\n\t}\r\n\treturn new AsYouType(optionsOrDefaultCountry, metadata).input(value)\r\n}"],"mappings":"AAAA,OAAOA,SAAS,MAAM,gBAAgB;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,2BAA2BA,CAACC,KAAK,EAAEC,uBAAuB,EAAEC,QAAQ,EAAE;EAC7F,IAAI,CAACA,QAAQ,EAAE;IACdA,QAAQ,GAAGD,uBAAuB;IAClCA,uBAAuB,GAAGE,SAAS;EACpC;EACA,OAAO,IAAIL,SAAS,CAACG,uBAAuB,EAAEC,QAAQ,CAAC,CAACE,KAAK,CAACJ,KAAK,CAAC;AACrE","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatIncompletePhoneNumber.test.js","names":["describe","it","expect","formatIncompletePhoneNumber","metadata","type","result","to","equal","defaultCountry","defaultCallingCode"],"sources":["../source/formatIncompletePhoneNumber.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport formatIncompletePhoneNumber from './formatIncompletePhoneNumber.js'\r\n\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\n\r\ndescribe('formatIncompletePhoneNumber', () => {\r\n\tit('should format parsed input value', () => {\r\n\t\tlet result\r\n\r\n\t\t// National input.\r\n\t\texpect(formatIncompletePhoneNumber('880055535', 'RU', metadata)).to.equal('8 (800) 555-35')\r\n\r\n\t\t// International input, no country.\r\n\t\texpect(formatIncompletePhoneNumber('+780055535', null, metadata)).to.equal('+7 800 555 35')\r\n\r\n\t\t// International input, no country argument.\r\n\t\texpect(formatIncompletePhoneNumber('+780055535', metadata)).to.equal('+7 800 555 35')\r\n\r\n\t\t// International input, with country.\r\n\t\texpect(formatIncompletePhoneNumber('+780055535', 'RU', metadata)).to.equal('+7 800 555 35')\r\n\t})\r\n\r\n\tit('should support an object argument', () => {\r\n\t\texpect(\r\n formatIncompletePhoneNumber('880055535', { defaultCountry: 'RU' }, metadata)\r\n ).to.equal('8 (800) 555-35')\r\n\t\texpect(\r\n formatIncompletePhoneNumber('880055535', { defaultCallingCode: '7' }, metadata)\r\n ).to.equal('8 (800) 555-35')\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,2BAA2B,MAAM,kCAAkC;AAE1E,OAAOC,QAAQ,MAAM,sBAAsB,QAAQC,IAAI,EAAE,MAAM;AAE/DL,QAAQ,CAAC,6BAA6B,EAAE,MAAM;EAC7CC,EAAE,CAAC,kCAAkC,EAAE,MAAM;IAC5C,IAAIK,MAAM;;IAEV;IACAJ,MAAM,CAACC,2BAA2B,CAAC,WAAW,EAAE,IAAI,EAAEC,QAAQ,CAAC,CAAC,CAACG,EAAE,CAACC,KAAK,CAAC,gBAAgB,CAAC;;IAE3F;IACAN,MAAM,CAACC,2BAA2B,CAAC,YAAY,EAAE,IAAI,EAAEC,QAAQ,CAAC,CAAC,CAACG,EAAE,CAACC,KAAK,CAAC,eAAe,CAAC;;IAE3F;IACAN,MAAM,CAACC,2BAA2B,CAAC,YAAY,EAAEC,QAAQ,CAAC,CAAC,CAACG,EAAE,CAACC,KAAK,CAAC,eAAe,CAAC;;IAErF;IACAN,MAAM,CAACC,2BAA2B,CAAC,YAAY,EAAE,IAAI,EAAEC,QAAQ,CAAC,CAAC,CAACG,EAAE,CAACC,KAAK,CAAC,eAAe,CAAC;EAC5F,CAAC,CAAC;EAEFP,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC7CC,MAAM,CACIC,2BAA2B,CAAC,WAAW,EAAE;MAAEM,cAAc,EAAE;IAAK,CAAC,EAAEL,QAAQ,CAC/E,CAAC,CAACG,EAAE,CAACC,KAAK,CAAC,gBAAgB,CAAC;IAClCN,MAAM,CACIC,2BAA2B,CAAC,WAAW,EAAE;MAAEO,kBAAkB,EAAE;IAAI,CAAC,EAAEN,QAAQ,CAClF,CAAC,CAACG,EAAE,CAACC,KAAK,CAAC,gBAAgB,CAAC;EACnC,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// This function is copy-pasted from
|
|
2
|
+
// https://github.com/googlei18n/libphonenumber/blob/master/javascript/i18n/phonenumbers/phonenumberutil.js
|
|
3
|
+
// It hasn't been tested. It's not currently exported.
|
|
4
|
+
// Carriers codes aren't part of this library.
|
|
5
|
+
// Send a PR if you want to add them.
|
|
6
|
+
|
|
7
|
+
import Metadata from './metadata.js';
|
|
8
|
+
import format from './format.js';
|
|
9
|
+
import getNumberType from './helpers/getNumberType.js';
|
|
10
|
+
import checkNumberLength from './helpers/checkNumberLength.js';
|
|
11
|
+
import getCountryCallingCode from './getCountryCallingCode.js';
|
|
12
|
+
const REGION_CODE_FOR_NON_GEO_ENTITY = '001';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns a number formatted in such a way that it can be dialed from a mobile
|
|
16
|
+
* phone in a specific region. If the number cannot be reached from the region
|
|
17
|
+
* (e.g. some countries block toll-free numbers from being called outside of the
|
|
18
|
+
* country), the method returns an empty string.
|
|
19
|
+
*
|
|
20
|
+
* @param {object} number - a `parse()`d phone number to be formatted.
|
|
21
|
+
* @param {string} from_country - the region where the call is being placed.
|
|
22
|
+
* @param {boolean} with_formatting - whether the number should be returned with
|
|
23
|
+
* formatting symbols, such as spaces and dashes.
|
|
24
|
+
* @return {string}
|
|
25
|
+
*/
|
|
26
|
+
export default function (number, from_country, with_formatting, metadata) {
|
|
27
|
+
metadata = new Metadata(metadata);
|
|
28
|
+
|
|
29
|
+
// Validate `from_country`.
|
|
30
|
+
if (!metadata.hasCountry(from_country)) {
|
|
31
|
+
throw new Error(`Unknown country: ${from_country}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Not using the extension, as that part cannot normally be dialed
|
|
35
|
+
// together with the main number.
|
|
36
|
+
number = {
|
|
37
|
+
phone: number.phone,
|
|
38
|
+
country: number.country
|
|
39
|
+
};
|
|
40
|
+
const number_type = getNumberType(number, undefined, metadata.metadata);
|
|
41
|
+
const is_valid_number = number_type === number;
|
|
42
|
+
let formatted_number;
|
|
43
|
+
if (country === from_country) {
|
|
44
|
+
const is_fixed_line_or_mobile = number_type === 'FIXED_LINE' || number_type === 'MOBILE' || number_type === 'FIXED_LINE_OR_MOBILE';
|
|
45
|
+
|
|
46
|
+
// Carrier codes may be needed in some countries. We handle this here.
|
|
47
|
+
if (country == 'BR' && is_fixed_line_or_mobile) {
|
|
48
|
+
formatted_number = carrierCode ? formatNationalNumberWithPreferredCarrierCode(number) :
|
|
49
|
+
// Brazilian fixed line and mobile numbers need to be dialed with a
|
|
50
|
+
// carrier code when called within Brazil. Without that, most of the
|
|
51
|
+
// carriers won't connect the call. Because of that, we return an
|
|
52
|
+
// empty string here.
|
|
53
|
+
'';
|
|
54
|
+
} else if (getCountryCallingCode(country, metadata.metadata) === '1') {
|
|
55
|
+
// For NANPA countries, we output international format for numbers that
|
|
56
|
+
// can be dialed internationally, since that always works, except for
|
|
57
|
+
// numbers which might potentially be short numbers, which are always
|
|
58
|
+
// dialled in national format.
|
|
59
|
+
|
|
60
|
+
// Select country for `checkNumberLength()`.
|
|
61
|
+
metadata.selectNumberingPlan(country);
|
|
62
|
+
if (can_be_internationally_dialled(number) && checkNumberLength(number.phone, country, metadata) !== 'TOO_SHORT') {
|
|
63
|
+
formatted_number = format(number, 'INTERNATIONAL', metadata.metadata);
|
|
64
|
+
} else {
|
|
65
|
+
formatted_number = format(number, 'NATIONAL', metadata.metadata);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
// For non-geographic countries, Mexican and Chilean fixed line and
|
|
69
|
+
// mobile numbers, we output international format for numbers that can be
|
|
70
|
+
// dialed internationally, as that always works.
|
|
71
|
+
if ((country === REGION_CODE_FOR_NON_GEO_ENTITY ||
|
|
72
|
+
// MX fixed line and mobile numbers should always be formatted in
|
|
73
|
+
// international format, even when dialed within MX. For national
|
|
74
|
+
// format to work, a carrier code needs to be used, and the correct
|
|
75
|
+
// carrier code depends on if the caller and callee are from the
|
|
76
|
+
// same local area. It is trickier to get that to work correctly than
|
|
77
|
+
// using international format, which is tested to work fine on all
|
|
78
|
+
// carriers.
|
|
79
|
+
//
|
|
80
|
+
// CL fixed line numbers need the national prefix when dialing in the
|
|
81
|
+
// national format, but don't have it when used for display. The
|
|
82
|
+
// reverse is true for mobile numbers. As a result, we output them in
|
|
83
|
+
// the international format to make it work.
|
|
84
|
+
//
|
|
85
|
+
// UZ mobile and fixed-line numbers have to be formatted in
|
|
86
|
+
// international format or prefixed with special codes like 03, 04
|
|
87
|
+
// (for fixed-line) and 05 (for mobile) for dialling successfully
|
|
88
|
+
// from mobile devices. As we do not have complete information on
|
|
89
|
+
// special codes and to be consistent with formatting across all
|
|
90
|
+
// phone types we return the number in international format here.
|
|
91
|
+
//
|
|
92
|
+
(country === 'MX' || country === 'CL' || country == 'UZ') && is_fixed_line_or_mobile) && can_be_internationally_dialled(number)) {
|
|
93
|
+
formatted_number = format(number, 'INTERNATIONAL');
|
|
94
|
+
} else {
|
|
95
|
+
formatted_number = format(number, 'NATIONAL');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} else if (is_valid_number && can_be_internationally_dialled(number)) {
|
|
99
|
+
// We assume that short numbers are not diallable from outside their region,
|
|
100
|
+
// so if a number is not a valid regular length phone number, we treat it as
|
|
101
|
+
// if it cannot be internationally dialled.
|
|
102
|
+
return with_formatting ? format(number, 'INTERNATIONAL', metadata.metadata) : format(number, 'E.164', metadata.metadata);
|
|
103
|
+
}
|
|
104
|
+
if (!with_formatting) {
|
|
105
|
+
return diallable_chars(formatted_number);
|
|
106
|
+
}
|
|
107
|
+
return formatted_number;
|
|
108
|
+
}
|
|
109
|
+
function can_be_internationally_dialled(number) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A map that contains characters that are essential when dialling. That means
|
|
115
|
+
* any of the characters in this map must not be removed from a number when
|
|
116
|
+
* dialling, otherwise the call will not reach the intended destination.
|
|
117
|
+
*/
|
|
118
|
+
const DIALLABLE_CHARACTERS = {
|
|
119
|
+
'0': '0',
|
|
120
|
+
'1': '1',
|
|
121
|
+
'2': '2',
|
|
122
|
+
'3': '3',
|
|
123
|
+
'4': '4',
|
|
124
|
+
'5': '5',
|
|
125
|
+
'6': '6',
|
|
126
|
+
'7': '7',
|
|
127
|
+
'8': '8',
|
|
128
|
+
'9': '9',
|
|
129
|
+
'+': '+',
|
|
130
|
+
'*': '*',
|
|
131
|
+
'#': '#'
|
|
132
|
+
};
|
|
133
|
+
function diallable_chars(formatted_number) {
|
|
134
|
+
let result = '';
|
|
135
|
+
let i = 0;
|
|
136
|
+
while (i < formatted_number.length) {
|
|
137
|
+
const character = formatted_number[i];
|
|
138
|
+
if (DIALLABLE_CHARACTERS[character]) {
|
|
139
|
+
result += character;
|
|
140
|
+
}
|
|
141
|
+
i++;
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
function getPreferredDomesticCarrierCodeOrDefault() {
|
|
146
|
+
throw new Error('carrier codes are not part of this library');
|
|
147
|
+
}
|
|
148
|
+
function formatNationalNumberWithCarrierCode() {
|
|
149
|
+
throw new Error('carrier codes are not part of this library');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Formats a phone number in national format for dialing using the carrier as
|
|
154
|
+
* specified in the preferred_domestic_carrier_code field of the PhoneNumber
|
|
155
|
+
* object passed in. If that is missing, use the {@code fallbackCarrierCode}
|
|
156
|
+
* passed in instead. If there is no {@code preferred_domestic_carrier_code},
|
|
157
|
+
* and the {@code fallbackCarrierCode} contains an empty string, return the
|
|
158
|
+
* number in national format without any carrier code.
|
|
159
|
+
*
|
|
160
|
+
* <p>Use {@link #formatNationalNumberWithCarrierCode} instead if the carrier
|
|
161
|
+
* code passed in should take precedence over the number's
|
|
162
|
+
* {@code preferred_domestic_carrier_code} when formatting.
|
|
163
|
+
*
|
|
164
|
+
* @param {i18n.phonenumbers.PhoneNumber} number the phone number to be
|
|
165
|
+
* formatted.
|
|
166
|
+
* @param {string} fallbackCarrierCode the carrier selection code to be used, if
|
|
167
|
+
* none is found in the phone number itself.
|
|
168
|
+
* @return {string} the formatted phone number in national format for dialing
|
|
169
|
+
* using the number's preferred_domestic_carrier_code, or the
|
|
170
|
+
* {@code fallbackCarrierCode} passed in if none is found.
|
|
171
|
+
*/
|
|
172
|
+
function formatNationalNumberWithPreferredCarrierCode(number) {
|
|
173
|
+
return formatNationalNumberWithCarrierCode(number, carrierCode);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Google's tests:
|
|
177
|
+
// https://github.com/googlei18n/libphonenumber/blob/597983dc4d56ed7e5337a8e74316dc7a3d02d794/javascript/i18n/phonenumbers/phonenumberutil_test.js
|
|
178
|
+
//
|
|
179
|
+
// import metadata from '../metadata.min.json' with { type: 'json' }
|
|
180
|
+
//
|
|
181
|
+
// import formatPhoneNumberForMobileDialing from './formatPhoneNumberForMobileDialing.js'
|
|
182
|
+
//
|
|
183
|
+
// describe('formatPhoneNumberForMobileDialing', () => {
|
|
184
|
+
// it('should format for mobile dialing', () => {
|
|
185
|
+
// formatPhoneNumberForMobileDialing({ phone: '8005553535', country: 'RU' }, 'US', true, metadata).should.equal('+7 800 555 3535')
|
|
186
|
+
// formatPhoneNumberForMobileDialing({ phone: '8005553535', country: 'RU' }, 'US', false, metadata).should.equal('+78005553535')
|
|
187
|
+
// formatPhoneNumberForMobileDialing({ phone: '8005553535', country: 'RU' }, 'RU', false, metadata).should.equal('8005553535')
|
|
188
|
+
// })
|
|
189
|
+
// })
|
|
190
|
+
//# sourceMappingURL=formatPhoneNumberForMobileDialing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatPhoneNumberForMobileDialing.js","names":["Metadata","format","getNumberType","checkNumberLength","getCountryCallingCode","REGION_CODE_FOR_NON_GEO_ENTITY","number","from_country","with_formatting","metadata","hasCountry","Error","phone","country","number_type","undefined","is_valid_number","formatted_number","is_fixed_line_or_mobile","carrierCode","formatNationalNumberWithPreferredCarrierCode","selectNumberingPlan","can_be_internationally_dialled","diallable_chars","DIALLABLE_CHARACTERS","result","i","length","character","getPreferredDomesticCarrierCodeOrDefault","formatNationalNumberWithCarrierCode"],"sources":["../source/formatPhoneNumberForMobileDialing.js"],"sourcesContent":["// This function is copy-pasted from\r\n// https://github.com/googlei18n/libphonenumber/blob/master/javascript/i18n/phonenumbers/phonenumberutil.js\r\n// It hasn't been tested. It's not currently exported.\r\n// Carriers codes aren't part of this library.\r\n// Send a PR if you want to add them.\r\n\r\nimport Metadata from './metadata.js'\r\nimport format from './format.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\nimport checkNumberLength from './helpers/checkNumberLength.js'\r\nimport getCountryCallingCode from './getCountryCallingCode.js'\r\n\r\nconst REGION_CODE_FOR_NON_GEO_ENTITY = '001'\r\n\r\n/**\r\n * Returns a number formatted in such a way that it can be dialed from a mobile\r\n * phone in a specific region. If the number cannot be reached from the region\r\n * (e.g. some countries block toll-free numbers from being called outside of the\r\n * country), the method returns an empty string.\r\n *\r\n * @param {object} number - a `parse()`d phone number to be formatted.\r\n * @param {string} from_country - the region where the call is being placed.\r\n * @param {boolean} with_formatting - whether the number should be returned with\r\n * formatting symbols, such as spaces and dashes.\r\n * @return {string}\r\n */\r\nexport default function(number, from_country, with_formatting, metadata) {\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\t// Validate `from_country`.\r\n\tif (!metadata.hasCountry(from_country)) {\r\n\t\tthrow new Error(`Unknown country: ${from_country}`)\r\n\t}\r\n\r\n\t// Not using the extension, as that part cannot normally be dialed\r\n\t// together with the main number.\r\n\tnumber = {\r\n\t\tphone: number.phone,\r\n\t\tcountry: number.country\r\n\t}\r\n\r\n\tconst number_type = getNumberType(number, undefined, metadata.metadata)\r\n\tconst is_valid_number = number_type === number\r\n\r\n\tlet formatted_number\r\n\r\n\tif (country === from_country) {\r\n\t\tconst is_fixed_line_or_mobile =\r\n\t\t\tnumber_type === 'FIXED_LINE' ||\r\n\t\t\tnumber_type === 'MOBILE' ||\r\n\t\t\tnumber_type === 'FIXED_LINE_OR_MOBILE'\r\n\r\n\t\t// Carrier codes may be needed in some countries. We handle this here.\r\n\t\tif (country == 'BR' && is_fixed_line_or_mobile) {\r\n\t\t\tformatted_number =\r\n\t\t\t\tcarrierCode ?\r\n\t\t\t\tformatNationalNumberWithPreferredCarrierCode(number) :\r\n\t\t\t\t// Brazilian fixed line and mobile numbers need to be dialed with a\r\n\t\t\t\t// carrier code when called within Brazil. Without that, most of the\r\n\t\t\t\t// carriers won't connect the call. Because of that, we return an\r\n\t\t\t\t// empty string here.\r\n\t\t\t\t''\r\n\t\t} else if (getCountryCallingCode(country, metadata.metadata) === '1') {\r\n\t\t\t// For NANPA countries, we output international format for numbers that\r\n\t\t\t// can be dialed internationally, since that always works, except for\r\n\t\t\t// numbers which might potentially be short numbers, which are always\r\n\t\t\t// dialled in national format.\r\n\r\n\t\t\t// Select country for `checkNumberLength()`.\r\n\t\t\tmetadata.selectNumberingPlan(country)\r\n\r\n\t\t\tif (can_be_internationally_dialled(number) &&\r\n\t\t\t\tcheckNumberLength(number.phone, country, metadata) !== 'TOO_SHORT') {\r\n\t\t\t\tformatted_number = format(number, 'INTERNATIONAL', metadata.metadata)\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tformatted_number = format(number, 'NATIONAL', metadata.metadata)\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\t// For non-geographic countries, Mexican and Chilean fixed line and\r\n\t\t\t// mobile numbers, we output international format for numbers that can be\r\n\t\t\t// dialed internationally, as that always works.\r\n\t\t\tif (\r\n\t\t\t\t(\r\n\t\t\t\t\tcountry === REGION_CODE_FOR_NON_GEO_ENTITY\r\n\t\t\t\t\t||\r\n\t\t\t\t\t// MX fixed line and mobile numbers should always be formatted in\r\n\t\t\t\t\t// international format, even when dialed within MX. For national\r\n\t\t\t\t\t// format to work, a carrier code needs to be used, and the correct\r\n\t\t\t\t\t// carrier code depends on if the caller and callee are from the\r\n\t\t\t\t\t// same local area. It is trickier to get that to work correctly than\r\n\t\t\t\t\t// using international format, which is tested to work fine on all\r\n\t\t\t\t\t// carriers.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// CL fixed line numbers need the national prefix when dialing in the\r\n\t\t\t\t\t// national format, but don't have it when used for display. The\r\n\t\t\t\t\t// reverse is true for mobile numbers. As a result, we output them in\r\n\t\t\t\t\t// the international format to make it work.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// UZ mobile and fixed-line numbers have to be formatted in\r\n\t\t\t\t\t// international format or prefixed with special codes like 03, 04\r\n\t\t\t\t\t// (for fixed-line) and 05 (for mobile) for dialling successfully\r\n\t\t\t\t\t// from mobile devices. As we do not have complete information on\r\n\t\t\t\t\t// special codes and to be consistent with formatting across all\r\n\t\t\t\t\t// phone types we return the number in international format here.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t((country === 'MX' || country === 'CL' || country == 'UZ') && is_fixed_line_or_mobile)\r\n\t\t\t\t)\r\n\t\t\t\t&&\r\n\t\t\t\tcan_be_internationally_dialled(number)\r\n\t\t\t) {\r\n\t\t\t\tformatted_number = format(number, 'INTERNATIONAL')\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tformatted_number = format(number, 'NATIONAL')\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\telse if (is_valid_number && can_be_internationally_dialled(number)) {\r\n\t\t// We assume that short numbers are not diallable from outside their region,\r\n\t\t// so if a number is not a valid regular length phone number, we treat it as\r\n\t\t// if it cannot be internationally dialled.\r\n\t\treturn with_formatting ?\r\n\t\t\tformat(number, 'INTERNATIONAL', metadata.metadata) :\r\n\t\t\tformat(number, 'E.164', metadata.metadata)\r\n\t}\r\n\r\n\tif (!with_formatting) {\r\n\t\treturn diallable_chars(formatted_number)\r\n\t}\r\n\r\n\treturn formatted_number\r\n}\r\n\r\nfunction can_be_internationally_dialled(number) {\r\n\treturn true\r\n}\r\n\r\n/**\r\n * A map that contains characters that are essential when dialling. That means\r\n * any of the characters in this map must not be removed from a number when\r\n * dialling, otherwise the call will not reach the intended destination.\r\n */\r\nconst DIALLABLE_CHARACTERS = {\r\n\t'0': '0',\r\n\t'1': '1',\r\n\t'2': '2',\r\n\t'3': '3',\r\n\t'4': '4',\r\n\t'5': '5',\r\n\t'6': '6',\r\n\t'7': '7',\r\n\t'8': '8',\r\n\t'9': '9',\r\n\t'+': '+',\r\n\t'*': '*',\r\n\t'#': '#'\r\n}\r\n\r\nfunction diallable_chars(formatted_number) {\r\n\tlet result = ''\r\n\r\n\tlet i = 0\r\n\twhile (i < formatted_number.length) {\r\n\t\tconst character = formatted_number[i]\r\n\t\tif (DIALLABLE_CHARACTERS[character]) {\r\n\t\t\tresult += character\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\r\n\treturn result\r\n}\r\n\r\nfunction getPreferredDomesticCarrierCodeOrDefault() {\r\n\tthrow new Error('carrier codes are not part of this library')\r\n}\r\n\r\nfunction formatNationalNumberWithCarrierCode() {\r\n\tthrow new Error('carrier codes are not part of this library')\r\n}\r\n\r\n/**\r\n * Formats a phone number in national format for dialing using the carrier as\r\n * specified in the preferred_domestic_carrier_code field of the PhoneNumber\r\n * object passed in. If that is missing, use the {@code fallbackCarrierCode}\r\n * passed in instead. If there is no {@code preferred_domestic_carrier_code},\r\n * and the {@code fallbackCarrierCode} contains an empty string, return the\r\n * number in national format without any carrier code.\r\n *\r\n * <p>Use {@link #formatNationalNumberWithCarrierCode} instead if the carrier\r\n * code passed in should take precedence over the number's\r\n * {@code preferred_domestic_carrier_code} when formatting.\r\n *\r\n * @param {i18n.phonenumbers.PhoneNumber} number the phone number to be\r\n * formatted.\r\n * @param {string} fallbackCarrierCode the carrier selection code to be used, if\r\n * none is found in the phone number itself.\r\n * @return {string} the formatted phone number in national format for dialing\r\n * using the number's preferred_domestic_carrier_code, or the\r\n * {@code fallbackCarrierCode} passed in if none is found.\r\n */\r\nfunction formatNationalNumberWithPreferredCarrierCode(number) {\r\n\treturn formatNationalNumberWithCarrierCode(\r\n\t\tnumber,\r\n\t\tcarrierCode\r\n\t);\r\n}\r\n\r\n// Google's tests:\r\n// https://github.com/googlei18n/libphonenumber/blob/597983dc4d56ed7e5337a8e74316dc7a3d02d794/javascript/i18n/phonenumbers/phonenumberutil_test.js\r\n//\r\n// import metadata from '../metadata.min.json' with { type: 'json' }\r\n//\r\n// import formatPhoneNumberForMobileDialing from './formatPhoneNumberForMobileDialing.js'\r\n//\r\n// describe('formatPhoneNumberForMobileDialing', () => {\r\n// \tit('should format for mobile dialing', () => {\r\n// \t\tformatPhoneNumberForMobileDialing({ phone: '8005553535', country: 'RU' }, 'US', true, metadata).should.equal('+7 800 555 3535')\r\n// \t\tformatPhoneNumberForMobileDialing({ phone: '8005553535', country: 'RU' }, 'US', false, metadata).should.equal('+78005553535')\r\n// \t\tformatPhoneNumberForMobileDialing({ phone: '8005553535', country: 'RU' }, 'RU', false, metadata).should.equal('8005553535')\r\n// \t})\r\n// })"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,QAAQ,MAAM,eAAe;AACpC,OAAOC,MAAM,MAAM,aAAa;AAChC,OAAOC,aAAa,MAAM,4BAA4B;AACtD,OAAOC,iBAAiB,MAAM,gCAAgC;AAC9D,OAAOC,qBAAqB,MAAM,4BAA4B;AAE9D,MAAMC,8BAA8B,GAAG,KAAK;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,UAASC,MAAM,EAAEC,YAAY,EAAEC,eAAe,EAAEC,QAAQ,EAAE;EACxEA,QAAQ,GAAG,IAAIT,QAAQ,CAACS,QAAQ,CAAC;;EAEjC;EACA,IAAI,CAACA,QAAQ,CAACC,UAAU,CAACH,YAAY,CAAC,EAAE;IACvC,MAAM,IAAII,KAAK,CAAC,oBAAoBJ,YAAY,EAAE,CAAC;EACpD;;EAEA;EACA;EACAD,MAAM,GAAG;IACRM,KAAK,EAAEN,MAAM,CAACM,KAAK;IACnBC,OAAO,EAAEP,MAAM,CAACO;EACjB,CAAC;EAED,MAAMC,WAAW,GAAGZ,aAAa,CAACI,MAAM,EAAES,SAAS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MAAM;AACd;AAEA,SAASI,wCAAwCA,CAAA,EAAG;EACnD,MAAM,IAAIlB,KAAK,CAAC,4CAA4C,CAAC;AAC9D;AAEA,SAASmB,mCAAmCA,CAAA,EAAG;EAC9C,MAAM,IAAInB,KAAK,CAAC,4CAA4C,CAAC;AAC9D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASS,4CAA4CA,CAACd,MAAM,EAAE;EAC7D,OAAOwB,mCAAmC,CACzCxB,MAAM,EACNa,WACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCountries.js","names":["Metadata","getCountries","metadata"],"sources":["../source/getCountries.js"],"sourcesContent":["import Metadata from './metadata.js'\r\n\r\nexport default function getCountries(metadata) {\r\n\treturn new Metadata(metadata).getCountries()\r\n}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,eAAe;AAEpC,eAAe,SAASC,YAAYA,CAACC,QAAQ,EAAE;EAC9C,OAAO,IAAIF,QAAQ,CAACE,QAAQ,CAAC,CAACD,YAAY,CAAC,CAAC;AAC7C","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCountries.test.js","names":["describe","it","expect","metadata","type","getCountries","indexOf","to","equal"],"sources":["../source/getCountries.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\n\r\nimport getCountries from './getCountries.js'\r\n\r\ndescribe('getCountries', () => {\r\n\tit('should get countries list', () => {\r\n\t\texpect(getCountries(metadata).indexOf('RU') > 0).to.equal(true);\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,QAAQ,MAAM,sBAAsB,QAAQC,IAAI,EAAE,MAAM;AAE/D,OAAOC,YAAY,MAAM,mBAAmB;AAE5CL,QAAQ,CAAC,cAAc,EAAE,MAAM;EAC9BC,EAAE,CAAC,2BAA2B,EAAE,MAAM;IACrCC,MAAM,CAACG,YAAY,CAACF,QAAQ,CAAC,CAACG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;EAChE,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCountryCallingCode.js","names":["getCountryCallingCode","default"],"sources":["../source/getCountryCallingCode.js"],"sourcesContent":["// Deprecated. Import from 'metadata.js' directly instead.\r\nexport { getCountryCallingCode as default } from './metadata.js'"],"mappings":"AAAA;AACA,SAASA,qBAAqB,IAAIC,OAAO,QAAQ,eAAe","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCountryCallingCode.test.js","names":["describe","it","expect","metadata","type","getCountryCallingCode","to","equal","throw"],"sources":["../source/getCountryCallingCode.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\n\r\nimport getCountryCallingCode from './getCountryCallingCode.js'\r\n\r\ndescribe('getCountryCallingCode', () => {\r\n\tit('should get country calling code', () => {\r\n\t\texpect(getCountryCallingCode('US', metadata)).to.equal('1')\r\n\t})\r\n\r\n\tit('should throw if country is unknown', () => {\r\n\t\texpect(() => getCountryCallingCode('ZZ', metadata)).to.throw('Unknown country: ZZ')\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,QAAQ,MAAM,sBAAsB,QAAQC,IAAI,EAAE,MAAM;AAE/D,OAAOC,qBAAqB,MAAM,4BAA4B;AAE9DL,QAAQ,CAAC,uBAAuB,EAAE,MAAM;EACvCC,EAAE,CAAC,iCAAiC,EAAE,MAAM;IAC3CC,MAAM,CAACG,qBAAqB,CAAC,IAAI,EAAEF,QAAQ,CAAC,CAAC,CAACG,EAAE,CAACC,KAAK,CAAC,GAAG,CAAC;EAC5D,CAAC,CAAC;EAEFN,EAAE,CAAC,oCAAoC,EAAE,MAAM;IAC9CC,MAAM,CAAC,MAAMG,qBAAqB,CAAC,IAAI,EAAEF,QAAQ,CAAC,CAAC,CAACG,EAAE,CAACE,KAAK,CAAC,qBAAqB,CAAC;EACpF,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getExampleNumber.js","names":["PhoneNumber","getExampleNumber","country","examples","metadata"],"sources":["../source/getExampleNumber.js"],"sourcesContent":["import PhoneNumber from './PhoneNumber.js'\r\n\r\nexport default function getExampleNumber(country, examples, metadata) {\r\n\tif (examples[country]) {\r\n\t\treturn new PhoneNumber(country, examples[country], metadata)\r\n\t}\r\n}"],"mappings":"AAAA,OAAOA,WAAW,MAAM,kBAAkB;AAE1C,eAAe,SAASC,gBAAgBA,CAACC,OAAO,EAAEC,QAAQ,EAAEC,QAAQ,EAAE;EACrE,IAAID,QAAQ,CAACD,OAAO,CAAC,EAAE;IACtB,OAAO,IAAIF,WAAW,CAACE,OAAO,EAAEC,QAAQ,CAACD,OAAO,CAAC,EAAEE,QAAQ,CAAC;EAC7D;AACD","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getExampleNumber.test.js","names":["describe","it","expect","examples","type","metadata","getExampleNumber","phoneNumber","nationalNumber","to","equal","number","countryCallingCode","country","be","undefined"],"sources":["../source/getExampleNumber.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport examples from '../examples.mobile.json' with { type: 'json' }\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\nimport getExampleNumber from './getExampleNumber.js'\r\n\r\ndescribe('getExampleNumber', () => {\r\n\tit('should get an example number', () => {\r\n\t\tconst phoneNumber = getExampleNumber('RU', examples, metadata)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('9123456789')\r\n\t\texpect(phoneNumber.number).to.equal('+79123456789')\r\n\t\texpect(phoneNumber.countryCallingCode).to.equal('7')\r\n\t\texpect(phoneNumber.country).to.equal('RU')\r\n\t})\r\n\r\n\tit('should handle a non-existing country', () => {\r\n\t\texpect(getExampleNumber('XX', examples, metadata)).to.be.undefined\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,QAAQ,MAAM,yBAAyB,QAAQC,IAAI,EAAE,MAAM;AAClE,OAAOC,QAAQ,MAAM,sBAAsB,QAAQD,IAAI,EAAE,MAAM;AAC/D,OAAOE,gBAAgB,MAAM,uBAAuB;AAEpDN,QAAQ,CAAC,kBAAkB,EAAE,MAAM;EAClCC,EAAE,CAAC,8BAA8B,EAAE,MAAM;IACxC,MAAMM,WAAW,GAAGD,gBAAgB,CAAC,IAAI,EAAEH,QAAQ,EAAEE,QAAQ,CAAC;IAC9DH,MAAM,CAACK,WAAW,CAACC,cAAc,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,YAAY,CAAC;IACzDR,MAAM,CAACK,WAAW,CAACI,MAAM,CAAC,CAACF,EAAE,CAACC,KAAK,CAAC,cAAc,CAAC;IACnDR,MAAM,CAACK,WAAW,CAACK,kBAAkB,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,GAAG,CAAC;IACpDR,MAAM,CAACK,WAAW,CAACM,OAAO,CAAC,CAACJ,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;EAC3C,CAAC,CAAC;EAEFT,EAAE,CAAC,sCAAsC,EAAE,MAAM;IAChDC,MAAM,CAACI,gBAAgB,CAAC,IAAI,EAAEH,QAAQ,EAAEE,QAAQ,CAAC,CAAC,CAACI,EAAE,CAACK,EAAE,CAACC,SAAS;EACnE,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import isViablePhoneNumber from './isViablePhoneNumber.js';
|
|
2
|
+
|
|
3
|
+
// https://www.ietf.org/rfc/rfc3966.txt
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} text - Phone URI (RFC 3966).
|
|
7
|
+
* @return {object} `{ ?number, ?ext }`.
|
|
8
|
+
*/
|
|
9
|
+
export function parseRFC3966(text) {
|
|
10
|
+
let number;
|
|
11
|
+
let ext;
|
|
12
|
+
|
|
13
|
+
// Replace "tel:" with "tel=" for parsing convenience.
|
|
14
|
+
text = text.replace(/^tel:/, 'tel=');
|
|
15
|
+
for (const part of text.split(';')) {
|
|
16
|
+
const [name, value] = part.split('=');
|
|
17
|
+
switch (name) {
|
|
18
|
+
case 'tel':
|
|
19
|
+
number = value;
|
|
20
|
+
break;
|
|
21
|
+
case 'ext':
|
|
22
|
+
ext = value;
|
|
23
|
+
break;
|
|
24
|
+
case 'phone-context':
|
|
25
|
+
// Only "country contexts" are supported.
|
|
26
|
+
// "Domain contexts" are ignored.
|
|
27
|
+
if (value[0] === '+') {
|
|
28
|
+
number = value + number;
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// If the phone number is not viable, then abort.
|
|
35
|
+
if (!isViablePhoneNumber(number)) {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
const result = {
|
|
39
|
+
number
|
|
40
|
+
};
|
|
41
|
+
if (ext) {
|
|
42
|
+
result.ext = ext;
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {object} - `{ ?number, ?extension }`.
|
|
49
|
+
* @return {string} Phone URI (RFC 3966).
|
|
50
|
+
*/
|
|
51
|
+
export function formatRFC3966({
|
|
52
|
+
number,
|
|
53
|
+
ext
|
|
54
|
+
}) {
|
|
55
|
+
if (!number) {
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
if (number[0] !== '+') {
|
|
59
|
+
throw new Error(`"formatRFC3966()" expects "number" to be in E.164 format.`);
|
|
60
|
+
}
|
|
61
|
+
return `tel:${number}${ext ? ';ext=' + ext : ''}`;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=RFC3966.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RFC3966.js","names":["isViablePhoneNumber","parseRFC3966","text","number","ext","replace","part","split","name","value","result","formatRFC3966","Error"],"sources":["../../source/helpers/RFC3966.js"],"sourcesContent":["import isViablePhoneNumber from './isViablePhoneNumber.js'\r\n\r\n// https://www.ietf.org/rfc/rfc3966.txt\r\n\r\n/**\r\n * @param {string} text - Phone URI (RFC 3966).\r\n * @return {object} `{ ?number, ?ext }`.\r\n */\r\nexport function parseRFC3966(text) {\r\n\tlet number\r\n\tlet ext\r\n\r\n\t// Replace \"tel:\" with \"tel=\" for parsing convenience.\r\n\ttext = text.replace(/^tel:/, 'tel=')\r\n\r\n\tfor (const part of text.split(';')) {\r\n\t\tconst [name, value] = part.split('=')\r\n\t\tswitch (name) {\r\n\t\t\tcase 'tel':\r\n\t\t\t\tnumber = value\r\n\t\t\t\tbreak\r\n\t\t\tcase 'ext':\r\n\t\t\t\text = value\r\n\t\t\t\tbreak\r\n\t\t\tcase 'phone-context':\r\n\t\t\t\t// Only \"country contexts\" are supported.\r\n\t\t\t\t// \"Domain contexts\" are ignored.\r\n\t\t\t\tif (value[0] === '+') {\r\n\t\t\t\t\tnumber = value + number\r\n\t\t\t\t}\r\n\t\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\r\n\t// If the phone number is not viable, then abort.\r\n\tif (!isViablePhoneNumber(number)) {\r\n\t\treturn {}\r\n\t}\r\n\r\n\tconst result = { number }\r\n\tif (ext) {\r\n\t\tresult.ext = ext\r\n\t}\r\n\treturn result\r\n}\r\n\r\n/**\r\n * @param {object} - `{ ?number, ?extension }`.\r\n * @return {string} Phone URI (RFC 3966).\r\n */\r\nexport function formatRFC3966({ number, ext }) {\r\n\tif (!number) {\r\n\t\treturn ''\r\n\t}\r\n\tif (number[0] !== '+') {\r\n\t\tthrow new Error(`\"formatRFC3966()\" expects \"number\" to be in E.164 format.`)\r\n\t}\r\n\treturn `tel:${number}${ext ? ';ext=' + ext : ''}`\r\n}"],"mappings":"AAAA,OAAOA,mBAAmB,MAAM,0BAA0B;;AAE1D;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAACC,IAAI,EAAE;EAClC,IAAIC,MAAM;EACV,IAAIC,GAAG;;EAEP;EACAF,IAAI,GAAGA,IAAI,CAACG,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC;EAEpC,KAAK,MAAMC,IAAI,IAAIJ,IAAI,CAACK,KAAK,CAAC,GAAG,CAAC,EAAE;IACnC,MAAM,CAACC,IAAI,EAAEC,KAAK,CAAC,GAAGH,IAAI,CAACC,KAAK,CAAC,GAAG,CAAC;IACrC,QAAQC,IAAI;MACX,KAAK,KAAK;QACTL,MAAM,GAAGM,KAAK;QACd;MACD,KAAK,KAAK;QACTL,GAAG,GAAGK,KAAK;QACX;MACD,KAAK,eAAe;QACnB;QACA;QACA,IAAIA,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;UACrBN,MAAM,GAAGM,KAAK,GAAGN,MAAM;QACxB;QACA;IACF;EACD;;EAEA;EACA,IAAI,CAACH,mBAAmB,CAACG,MAAM,CAAC,EAAE;IACjC,OAAO,CAAC,CAAC;EACV;EAEA,MAAMO,MAAM,GAAG;IAAEP;EAAO,CAAC;EACzB,IAAIC,GAAG,EAAE;IACRM,MAAM,CAACN,GAAG,GAAGA,GAAG;EACjB;EACA,OAAOM,MAAM;AACd;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAAC;EAAER,MAAM;EAAEC;AAAI,CAAC,EAAE;EAC9C,IAAI,CAACD,MAAM,EAAE;IACZ,OAAO,EAAE;EACV;EACA,IAAIA,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;IACtB,MAAM,IAAIS,KAAK,CAAC,2DAA2D,CAAC;EAC7E;EACA,OAAO,OAAOT,MAAM,GAAGC,GAAG,GAAG,OAAO,GAAGA,GAAG,GAAG,EAAE,EAAE;AAClD","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RFC3966.test.js","names":["describe","it","expect","parseRFC3966","formatRFC3966","number","to","throw","equal","ext","deep"],"sources":["../../source/helpers/RFC3966.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport { parseRFC3966, formatRFC3966 } from './RFC3966.js'\r\n\r\ndescribe('RFC3966', () => {\r\n\tit('should format', () => {\r\n\t\texpect(() => formatRFC3966({ number: '123' })).to.throw('expects \"number\" to be in E.164 format')\r\n\t\texpect(formatRFC3966({})).to.equal('')\r\n\t\texpect(formatRFC3966({ number: '+78005553535' })).to.equal('tel:+78005553535')\r\n\t\texpect(formatRFC3966({ number: '+78005553535', ext: '123' })).to.equal('tel:+78005553535;ext=123')\r\n\t})\r\n\r\n\tit('should parse', () => {\r\n\t\texpect(parseRFC3966('tel:+78005553535')).to.deep.equal({\r\n\t\t\tnumber : '+78005553535'\r\n\t\t})\r\n\r\n\t\texpect(parseRFC3966('tel:+78005553535;ext=123')).to.deep.equal({\r\n\t\t\tnumber : '+78005553535',\r\n\t\t\text : '123'\r\n\t\t})\r\n\r\n\t\t// With `phone-context`\r\n\t\texpect(parseRFC3966('tel:8005553535;ext=123;phone-context=+7')).to.deep.equal({\r\n\t\t\tnumber : '+78005553535',\r\n\t\t\text : '123'\r\n\t\t})\r\n\r\n\t\t// \"Domain contexts\" are ignored\r\n\t\texpect(parseRFC3966('tel:8005553535;ext=123;phone-context=www.leningrad.spb.ru')).to.deep.equal({\r\n\t\t\tnumber : '8005553535',\r\n\t\t\text : '123'\r\n\t\t})\r\n\r\n\t\t// Not a viable phone number.\r\n\t\texpect(parseRFC3966('tel:3')).to.deep.equal({})\r\n\t})\r\n})\r\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,SAASC,YAAY,EAAEC,aAAa,QAAQ,cAAc;AAE1DJ,QAAQ,CAAC,SAAS,EAAE,MAAM;EACzBC,EAAE,CAAC,eAAe,EAAE,MAAM;IACzBC,MAAM,CAAC,MAAME,aAAa,CAAC;MAAEC,MAAM,EAAE;IAAM,CAAC,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,wCAAwC,CAAC;IACjGL,MAAM,CAACE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAACE,EAAE,CAACE,KAAK,CAAC,EAAE,CAAC;IACtCN,MAAM,CAACE,aAAa,CAAC;MAAEC,MAAM,EAAE;IAAe,CAAC,CAAC,CAAC,CAACC,EAAE,CAACE,KAAK,CAAC,kBAAkB,CAAC;IAC9EN,MAAM,CAACE,aAAa,CAAC;MAAEC,MAAM,EAAE,cAAc;MAAEI,GAAG,EAAE;IAAM,CAAC,CAAC,CAAC,CAACH,EAAE,CAACE,KAAK,CAAC,0BAA0B,CAAC;EACnG,CAAC,CAAC;EAEFP,EAAE,CAAC,cAAc,EAAE,MAAM;IACxBC,MAAM,CAACC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAACG,EAAE,CAACI,IAAI,CAACF,KAAK,CAAC;MACtDH,MAAM,EAAG;IACV,CAAC,CAAC;IAEFH,MAAM,CAACC,YAAY,CAAC,0BAA0B,CAAC,CAAC,CAACG,EAAE,CAACI,IAAI,CAACF,KAAK,CAAC;MAC9DH,MAAM,EAAG,cAAc;MACvBI,GAAG,EAAM;IACV,CAAC,CAAC;;IAEF;IACAP,MAAM,CAACC,YAAY,CAAC,yCAAyC,CAAC,CAAC,CAACG,EAAE,CAACI,IAAI,CAACF,KAAK,CAAC;MAC7EH,MAAM,EAAG,cAAc;MACvBI,GAAG,EAAM;IACV,CAAC,CAAC;;IAEF;IACAP,MAAM,CAACC,YAAY,CAAC,2DAA2D,CAAC,CAAC,CAACG,EAAE,CAACI,IAAI,CAACF,KAAK,CAAC;MAC/FH,MAAM,EAAG,YAAY;MACrBI,GAAG,EAAM;IACV,CAAC,CAAC;;IAEF;IACAP,MAAM,CAACC,YAAY,CAAC,OAAO,CAAC,CAAC,CAACG,EAAE,CAACI,IAAI,CAACF,KAAK,CAAC,CAAC,CAAC,CAAC;EAChD,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { VALID_PUNCTUATION } from '../constants.js';
|
|
2
|
+
|
|
3
|
+
// Removes brackets and replaces dashes with spaces.
|
|
4
|
+
//
|
|
5
|
+
// E.g. "(999) 111-22-33" -> "999 111 22 33"
|
|
6
|
+
//
|
|
7
|
+
// For some reason Google's metadata contains `<intlFormat/>`s with brackets and dashes.
|
|
8
|
+
// Meanwhile, there's no single opinion about using punctuation in international phone numbers.
|
|
9
|
+
//
|
|
10
|
+
// For example, Google's `<intlFormat/>` for USA is `+1 213-373-4253`.
|
|
11
|
+
// And here's a quote from WikiPedia's "North American Numbering Plan" page:
|
|
12
|
+
// https://en.wikipedia.org/wiki/North_American_Numbering_Plan
|
|
13
|
+
//
|
|
14
|
+
// "The country calling code for all countries participating in the NANP is 1.
|
|
15
|
+
// In international format, an NANP number should be listed as +1 301 555 01 00,
|
|
16
|
+
// where 301 is an area code (Maryland)."
|
|
17
|
+
//
|
|
18
|
+
// I personally prefer the international format without any punctuation.
|
|
19
|
+
// For example, brackets are remnants of the old age, meaning that the
|
|
20
|
+
// phone number part in brackets (so called "area code") can be omitted
|
|
21
|
+
// if dialing within the same "area".
|
|
22
|
+
// And hyphens were clearly introduced for splitting local numbers into memorizable groups.
|
|
23
|
+
// For example, remembering "5553535" is difficult but "555-35-35" is much simpler.
|
|
24
|
+
// Imagine a man taking a bus from home to work and seeing an ad with a phone number.
|
|
25
|
+
// He has a couple of seconds to memorize that number until it passes by.
|
|
26
|
+
// If it were spaces instead of hyphens the man wouldn't necessarily get it,
|
|
27
|
+
// but with hyphens instead of spaces the grouping is more explicit.
|
|
28
|
+
// I personally think that hyphens introduce visual clutter,
|
|
29
|
+
// so I prefer replacing them with spaces in international numbers.
|
|
30
|
+
// In the modern age all output is done on displays where spaces are clearly distinguishable
|
|
31
|
+
// so hyphens can be safely replaced with spaces without losing any legibility.
|
|
32
|
+
//
|
|
33
|
+
export default function applyInternationalSeparatorStyle(formattedNumber) {
|
|
34
|
+
return formattedNumber.replace(new RegExp(`[${VALID_PUNCTUATION}]+`, 'g'), ' ').trim();
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=applyInternationalSeparatorStyle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyInternationalSeparatorStyle.js","names":["VALID_PUNCTUATION","applyInternationalSeparatorStyle","formattedNumber","replace","RegExp","trim"],"sources":["../../source/helpers/applyInternationalSeparatorStyle.js"],"sourcesContent":["import { VALID_PUNCTUATION } from '../constants.js'\r\n\r\n// Removes brackets and replaces dashes with spaces.\r\n//\r\n// E.g. \"(999) 111-22-33\" -> \"999 111 22 33\"\r\n//\r\n// For some reason Google's metadata contains `<intlFormat/>`s with brackets and dashes.\r\n// Meanwhile, there's no single opinion about using punctuation in international phone numbers.\r\n//\r\n// For example, Google's `<intlFormat/>` for USA is `+1 213-373-4253`.\r\n// And here's a quote from WikiPedia's \"North American Numbering Plan\" page:\r\n// https://en.wikipedia.org/wiki/North_American_Numbering_Plan\r\n//\r\n// \"The country calling code for all countries participating in the NANP is 1.\r\n// In international format, an NANP number should be listed as +1 301 555 01 00,\r\n// where 301 is an area code (Maryland).\"\r\n//\r\n// I personally prefer the international format without any punctuation.\r\n// For example, brackets are remnants of the old age, meaning that the\r\n// phone number part in brackets (so called \"area code\") can be omitted\r\n// if dialing within the same \"area\".\r\n// And hyphens were clearly introduced for splitting local numbers into memorizable groups.\r\n// For example, remembering \"5553535\" is difficult but \"555-35-35\" is much simpler.\r\n// Imagine a man taking a bus from home to work and seeing an ad with a phone number.\r\n// He has a couple of seconds to memorize that number until it passes by.\r\n// If it were spaces instead of hyphens the man wouldn't necessarily get it,\r\n// but with hyphens instead of spaces the grouping is more explicit.\r\n// I personally think that hyphens introduce visual clutter,\r\n// so I prefer replacing them with spaces in international numbers.\r\n// In the modern age all output is done on displays where spaces are clearly distinguishable\r\n// so hyphens can be safely replaced with spaces without losing any legibility.\r\n//\r\nexport default function applyInternationalSeparatorStyle(formattedNumber) {\r\n\treturn formattedNumber.replace(new RegExp(`[${VALID_PUNCTUATION}]+`, 'g'), ' ').trim()\r\n}"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,iBAAiB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,gCAAgCA,CAACC,eAAe,EAAE;EACzE,OAAOA,eAAe,CAACC,OAAO,CAAC,IAAIC,MAAM,CAAC,IAAIJ,iBAAiB,IAAI,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAACK,IAAI,CAAC,CAAC;AACvF","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyInternationalSeparatorStyle.test.js","names":["describe","it","expect","applyInternationalSeparatorStyle","to","equal"],"sources":["../../source/helpers/applyInternationalSeparatorStyle.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport applyInternationalSeparatorStyle from './applyInternationalSeparatorStyle.js'\r\n\r\ndescribe('applyInternationalSeparatorStyle', () => {\r\n\tit('should change Google\\'s international format style', () => {\r\n\t\texpect(applyInternationalSeparatorStyle('(xxx) xxx-xx-xx')).to.equal('xxx xxx xx xx')\r\n\t\texpect(applyInternationalSeparatorStyle('(xxx)xxx')).to.equal('xxx xxx')\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,gCAAgC,MAAM,uCAAuC;AAEpFH,QAAQ,CAAC,kCAAkC,EAAE,MAAM;EAClDC,EAAE,CAAC,oDAAoD,EAAE,MAAM;IAC9DC,MAAM,CAACC,gCAAgC,CAAC,iBAAiB,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,eAAe,CAAC;IACrFH,MAAM,CAACC,gCAAgC,CAAC,UAAU,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,SAAS,CAAC;EACzE,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|