libphonenumber-js 1.10.46 → 1.10.48

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.
Files changed (69) hide show
  1. package/README.md +15 -2
  2. package/build/AsYouType.js +5 -3
  3. package/build/AsYouType.js.map +1 -1
  4. package/build/formatIncompletePhoneNumber.js +5 -5
  5. package/build/formatIncompletePhoneNumber.js.map +1 -1
  6. package/build/formatIncompletePhoneNumber.test.js +8 -0
  7. package/build/formatIncompletePhoneNumber.test.js.map +1 -1
  8. package/build/helpers/isObject.js +12 -0
  9. package/build/helpers/isObject.js.map +1 -0
  10. package/build/legacy/format.js +4 -12
  11. package/build/legacy/format.js.map +1 -1
  12. package/build/legacy/getNumberType.js +5 -13
  13. package/build/legacy/getNumberType.js.map +1 -1
  14. package/build/metadata.js +5 -11
  15. package/build/metadata.js.map +1 -1
  16. package/build/normalizeArguments.js +5 -10
  17. package/build/normalizeArguments.js.map +1 -1
  18. package/bundle/libphonenumber-js.min.js +1 -1
  19. package/bundle/libphonenumber-js.min.js.map +1 -1
  20. package/bundle/libphonenumber-max.js +1 -1
  21. package/bundle/libphonenumber-max.js.map +1 -1
  22. package/bundle/libphonenumber-min.js +1 -1
  23. package/bundle/libphonenumber-min.js.map +1 -1
  24. package/bundle/libphonenumber-mobile.js +1 -1
  25. package/bundle/libphonenumber-mobile.js.map +1 -1
  26. package/core/index.d.cts +1 -1
  27. package/core/index.d.ts +1 -1
  28. package/custom.d.ts +1 -1
  29. package/es6/AsYouType.js +2 -3
  30. package/es6/AsYouType.js.map +1 -1
  31. package/es6/formatIncompletePhoneNumber.js +5 -5
  32. package/es6/formatIncompletePhoneNumber.js.map +1 -1
  33. package/es6/formatIncompletePhoneNumber.test.js +8 -0
  34. package/es6/formatIncompletePhoneNumber.test.js.map +1 -1
  35. package/es6/helpers/isObject.js +5 -0
  36. package/es6/helpers/isObject.js.map +1 -0
  37. package/es6/legacy/format.js +3 -12
  38. package/es6/legacy/format.js.map +1 -1
  39. package/es6/legacy/getNumberType.js +4 -12
  40. package/es6/legacy/getNumberType.js.map +1 -1
  41. package/es6/metadata.js +5 -12
  42. package/es6/metadata.js.map +1 -1
  43. package/es6/normalizeArguments.js +3 -10
  44. package/es6/normalizeArguments.js.map +1 -1
  45. package/index.d.cts +1 -0
  46. package/index.d.ts +1 -0
  47. package/max/index.d.cts +1 -1
  48. package/max/index.d.ts +1 -1
  49. package/metadata.full.json +1 -1
  50. package/metadata.full.json.js +1 -1
  51. package/metadata.max.json +1 -1
  52. package/metadata.max.json.js +1 -1
  53. package/metadata.min.json +1 -1
  54. package/metadata.min.json.js +1 -1
  55. package/metadata.mobile.json +1 -1
  56. package/metadata.mobile.json.js +1 -1
  57. package/min/index.d.cts +1 -1
  58. package/min/index.d.ts +1 -1
  59. package/mobile/index.d.cts +1 -1
  60. package/mobile/index.d.ts +1 -1
  61. package/package.json +1 -1
  62. package/source/AsYouType.js +2 -1
  63. package/source/formatIncompletePhoneNumber.js +5 -5
  64. package/source/formatIncompletePhoneNumber.test.js +5 -0
  65. package/source/helpers/isObject.js +5 -0
  66. package/source/legacy/format.js +3 -7
  67. package/source/legacy/getNumberType.js +4 -8
  68. package/source/metadata.js +4 -8
  69. package/source/normalizeArguments.js +3 -5
package/core/index.d.cts CHANGED
@@ -88,7 +88,7 @@ export function getExtPrefix(countryCode: CountryCode, metadata: MetadataJson):
88
88
  export function getExampleNumber(country: CountryCode, examples: Examples, metadata: MetadataJson): PhoneNumber | undefined;
89
89
 
90
90
  export function formatIncompletePhoneNumber(number: string, metadata: MetadataJson): string;
91
- export function formatIncompletePhoneNumber(number: string, countryCode: CountryCode, metadata: MetadataJson): string;
91
+ export function formatIncompletePhoneNumber(number: string, defaultCountryCode: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string } | undefined, metadata: MetadataJson): string;
92
92
  export function parseIncompletePhoneNumber(text: string): string;
93
93
  export function parsePhoneNumberCharacter(character: string): string;
94
94
  export function parseDigits(character: string): string;
package/core/index.d.ts CHANGED
@@ -88,7 +88,7 @@ export function getExtPrefix(countryCode: CountryCode, metadata: MetadataJson):
88
88
  export function getExampleNumber(country: CountryCode, examples: Examples, metadata: MetadataJson): PhoneNumber | undefined;
89
89
 
90
90
  export function formatIncompletePhoneNumber(number: string, metadata: MetadataJson): string;
91
- export function formatIncompletePhoneNumber(number: string, countryCode: CountryCode, metadata: MetadataJson): string;
91
+ export function formatIncompletePhoneNumber(number: string, defaultCountryCode: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string } | undefined, metadata: MetadataJson): string;
92
92
  export function parseIncompletePhoneNumber(text: string): string;
93
93
  export function parsePhoneNumberCharacter(character: string): string;
94
94
  export function parseDigits(character: string): string;
package/custom.d.ts CHANGED
@@ -140,7 +140,7 @@ export function getExtPrefix(countryCode: CountryCode, metadata: MetadataJson):
140
140
  export function isSupportedCountry(countryCode: CountryCode, metadata: MetadataJson): boolean;
141
141
 
142
142
  export function formatIncompletePhoneNumber(number: string, metadata: MetadataJson): string;
143
- export function formatIncompletePhoneNumber(number: string, countryCode: CountryCode, metadata: MetadataJson): string;
143
+ export function formatIncompletePhoneNumber(number: string, defaultCountryCode: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string } | undefined, metadata: MetadataJson): string;
144
144
  export function parseIncompletePhoneNumber(text: string): string;
145
145
  export function parsePhoneNumberCharacter(character: string): string;
146
146
  export function parseDigits(character: string): string;
package/es6/AsYouType.js CHANGED
@@ -1,5 +1,3 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
-
3
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
2
 
5
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -25,6 +23,7 @@ import AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.js';
25
23
  import AsYouTypeParser, { extractFormattedDigitsAndPlus } from './AsYouTypeParser.js';
26
24
  import getCountryByCallingCode from './helpers/getCountryByCallingCode.js';
27
25
  import getCountryByNationalNumber from './helpers/getCountryByNationalNumber.js';
26
+ import isObject from './helpers/isObject.js';
28
27
  var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
29
28
 
30
29
  var AsYouType = /*#__PURE__*/function () {
@@ -58,7 +57,7 @@ var AsYouType = /*#__PURE__*/function () {
58
57
  var defaultCallingCode; // Turns out `null` also has type "object". Weird.
59
58
 
60
59
  if (optionsOrDefaultCountry) {
61
- if (_typeof(optionsOrDefaultCountry) === 'object') {
60
+ if (isObject(optionsOrDefaultCountry)) {
62
61
  defaultCountry = optionsOrDefaultCountry.defaultCountry;
63
62
  defaultCallingCode = optionsOrDefaultCountry.defaultCallingCode;
64
63
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"AsYouType.js","names":["Metadata","PhoneNumber","AsYouTypeState","AsYouTypeFormatter","DIGIT_PLACEHOLDER","AsYouTypeParser","extractFormattedDigitsAndPlus","getCountryByCallingCode","getCountryByNationalNumber","USE_NON_GEOGRAPHIC_COUNTRY_CODE","AsYouType","optionsOrDefaultCountry","metadata","getCountryAndCallingCode","defaultCountry","defaultCallingCode","reset","hasCountry","undefined","isNonGeographicCallingCode","text","parser","input","state","digits","justLeadingPlus","formattedOutput","determineTheCountryIfNeeded","nationalSignificantNumber","formatter","narrowDownMatchingFormats","formattedNationalNumber","hasSelectedNumberingPlan","format","reExtractNationalSignificantNumber","nationalDigits","getNationalDigits","getFullNumber","getNonFormattedNumber","onCountryChange","country","onCallingCodeChange","callingCode","selectNumberingPlan","numberingPlan","onNationalSignificantNumberChange","international","isInternational","getCallingCode","_getCountry","isCountryCallingCodeAmbiguous","determineTheCountry","prefix","getInternationalPrefixBeforeCountryCallingCode","spacing","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","nationalPrefix","number","nationalSignificantNumberMatchesInput","getNonFormattedNationalNumberWithPrefix","replace","countryCodes","getCountryCodesForCallingCode","length","setCountry","nationalNumber","callingCode_","countryCallingCode","carrierCode","ambiguousCountries","exactCountry","countries","phoneNumber","getNumber","isPossible","isValid","getTemplate","getNonFormattedTemplate"],"sources":["../source/AsYouType.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport PhoneNumber from './PhoneNumber.js'\r\nimport AsYouTypeState from './AsYouTypeState.js'\r\nimport AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.js'\r\nimport AsYouTypeParser, { extractFormattedDigitsAndPlus } from './AsYouTypeParser.js'\r\nimport getCountryByCallingCode from './helpers/getCountryByCallingCode.js'\r\nimport getCountryByNationalNumber from './helpers/getCountryByNationalNumber.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default class AsYouType {\r\n\t/**\r\n\t * @param {(string|object)?} [optionsOrDefaultCountry] - The default country used for parsing non-international phone numbers. Can also be an `options` object.\r\n\t * @param {Object} metadata\r\n\t */\r\n\tconstructor(optionsOrDefaultCountry, metadata) {\r\n\t\tthis.metadata = new Metadata(metadata)\r\n\t\tconst [defaultCountry, defaultCallingCode] = this.getCountryAndCallingCode(optionsOrDefaultCountry)\r\n\t\t// `this.defaultCountry` and `this.defaultCallingCode` aren't required to be in sync.\r\n\t\t// For example, `this.defaultCountry` could be `\"AR\"` and `this.defaultCallingCode` could be `undefined`.\r\n\t\t// So `this.defaultCountry` and `this.defaultCallingCode` are totally independent.\r\n\t\tthis.defaultCountry = defaultCountry\r\n\t\tthis.defaultCallingCode = defaultCallingCode\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\tgetCountryAndCallingCode(optionsOrDefaultCountry) {\r\n\t\t// Set `defaultCountry` and `defaultCallingCode` options.\r\n\t\tlet defaultCountry\r\n\t\tlet defaultCallingCode\r\n\t\t// Turns out `null` also has type \"object\". Weird.\r\n\t\tif (optionsOrDefaultCountry) {\r\n\t\t\tif (typeof optionsOrDefaultCountry === 'object') {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry.defaultCountry\r\n\t\t\t\tdefaultCallingCode = optionsOrDefaultCountry.defaultCallingCode\r\n\t\t\t} else {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (defaultCountry && !this.metadata.hasCountry(defaultCountry)) {\r\n\t\t\tdefaultCountry = undefined\r\n\t\t}\r\n\t\tif (defaultCallingCode) {\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t\tif (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {\r\n\t\t\t\t\tdefaultCountry = '001'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn [defaultCountry, defaultCallingCode]\r\n\t}\r\n\r\n\t/**\r\n\t * Inputs \"next\" phone number characters.\r\n\t * @param {string} text\r\n\t * @return {string} Formatted phone number characters that have been input so far.\r\n\t */\r\n\tinput(text) {\r\n\t\tconst {\r\n\t\t\tdigits,\r\n\t\t\tjustLeadingPlus\r\n\t\t} = this.parser.input(text, this.state)\r\n\t\tif (justLeadingPlus) {\r\n\t\t\tthis.formattedOutput = '+'\r\n\t\t} else if (digits) {\r\n\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t// Match the available formats by the currently available leading digits.\r\n\t\t\tif (this.state.nationalSignificantNumber) {\r\n\t\t\t\tthis.formatter.narrowDownMatchingFormats(this.state)\r\n\t\t\t}\r\n\t\t\tlet formattedNationalNumber\r\n\t\t\tif (this.metadata.hasSelectedNumberingPlan()) {\r\n\t\t\t\tformattedNationalNumber = this.formatter.format(digits, this.state)\r\n\t\t\t}\r\n\t\t\tif (formattedNationalNumber === undefined) {\r\n\t\t\t\t// See if another national (significant) number could be re-extracted.\r\n\t\t\t\tif (this.parser.reExtractNationalSignificantNumber(this.state)) {\r\n\t\t\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t\t\t// If it could, then re-try formatting the new national (significant) number.\r\n\t\t\t\t\tconst nationalDigits = this.state.getNationalDigits()\r\n\t\t\t\t\tif (nationalDigits) {\r\n\t\t\t\t\t\tformattedNationalNumber = this.formatter.format(nationalDigits, this.state)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tthis.formattedOutput = formattedNationalNumber\r\n\t\t\t\t? this.getFullNumber(formattedNationalNumber)\r\n\t\t\t\t: this.getNonFormattedNumber()\r\n\t\t}\r\n\t\treturn this.formattedOutput\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.state = new AsYouTypeState({\r\n\t\t\tonCountryChange: (country) => {\r\n\t\t\t\t// Before version `1.6.0`, the official `AsYouType` formatter API\r\n\t\t\t\t// included the `.country` property of an `AsYouType` instance.\r\n\t\t\t\t// Since that property (along with the others) have been moved to\r\n\t\t\t\t// `this.state`, `this.country` property is emulated for compatibility\r\n\t\t\t\t// with the old versions.\r\n\t\t\t\tthis.country = country\r\n\t\t\t},\r\n\t\t\tonCallingCodeChange: (callingCode, country) => {\r\n\t\t\t\tthis.metadata.selectNumberingPlan(country, callingCode)\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t\tthis.parser.reset(this.metadata.numberingPlan)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.formatter = new AsYouTypeFormatter({\r\n\t\t\tstate: this.state,\r\n\t\t\tmetadata: this.metadata\r\n\t\t})\r\n\t\tthis.parser = new AsYouTypeParser({\r\n\t\t\tdefaultCountry: this.defaultCountry,\r\n\t\t\tdefaultCallingCode: this.defaultCallingCode,\r\n\t\t\tmetadata: this.metadata,\r\n\t\t\tstate: this.state,\r\n\t\t\tonNationalSignificantNumberChange: () => {\r\n\t\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.state.reset({\r\n\t\t\tcountry: this.defaultCountry,\r\n\t\t\tcallingCode: this.defaultCallingCode\r\n\t\t})\r\n\t\tthis.formattedOutput = ''\r\n\t\treturn this\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is being input in international format.\r\n\t * In other words, returns `true` if and only if the parsed phone number starts with a `\"+\"`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisInternational() {\r\n\t\treturn this.state.international\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the \"calling code\" part of the phone number when it's being input\r\n\t * in an international format.\r\n\t * If no valid calling code has been entered so far, returns `undefined`.\r\n\t * @return {string} [callingCode]\r\n\t */\r\n\tgetCallingCode() {\r\n\t\t // If the number is being input in national format and some \"default calling code\"\r\n\t\t // has been passed to `AsYouType` constructor, then `this.state.callingCode`\r\n\t\t // is equal to that \"default calling code\".\r\n\t\t //\r\n\t\t // If the number is being input in national format and no \"default calling code\"\r\n\t\t // has been passed to `AsYouType` constructor, then returns `undefined`,\r\n\t\t // even if a \"default country\" has been passed to `AsYouType` constructor.\r\n\t\t //\r\n\t\tif (this.isInternational()) {\r\n\t\t\treturn this.state.callingCode\r\n\t\t}\r\n\t}\r\n\r\n\t// A legacy alias.\r\n\tgetCountryCallingCode() {\r\n\t\treturn this.getCallingCode()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a two-letter country code of the phone number.\r\n\t * Returns `undefined` for \"non-geographic\" phone numbering plans.\r\n\t * Returns `undefined` if no phone number has been input yet.\r\n\t * @return {string} [country]\r\n\t */\r\n\tgetCountry() {\r\n\t\tconst { digits } = this.state\r\n\t\t// Return `undefined` if no digits have been input yet.\r\n\t\tif (digits) {\r\n\t\t\treturn this._getCountry()\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a two-letter country code of the phone number.\r\n\t * Returns `undefined` for \"non-geographic\" phone numbering plans.\r\n\t * @return {string} [country]\r\n\t */\r\n\t_getCountry() {\r\n\t\tconst { country } = this.state\r\n\t\t/* istanbul ignore if */\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t// `AsYouType.getCountry()` returns `undefined`\r\n\t\t\t// for \"non-geographic\" phone numbering plans.\r\n\t\t\tif (country === '001') {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn country\r\n\t}\r\n\r\n\tdetermineTheCountryIfNeeded() {\r\n\t\t// Suppose a user enters a phone number in international format,\r\n\t\t// and there're several countries corresponding to that country calling code,\r\n\t\t// and a country has been derived from the number, and then\r\n\t\t// a user enters one more digit and the number is no longer\r\n\t\t// valid for the derived country, so the country should be re-derived\r\n\t\t// on every new digit in those cases.\r\n\t\t//\r\n\t\t// If the phone number is being input in national format,\r\n\t\t// then it could be a case when `defaultCountry` wasn't specified\r\n\t\t// when creating `AsYouType` instance, and just `defaultCallingCode` was specified,\r\n\t\t// and that \"calling code\" could correspond to a \"non-geographic entity\",\r\n\t\t// or there could be several countries corresponding to that country calling code.\r\n\t\t// In those cases, `this.country` is `undefined` and should be derived\r\n\t\t// from the number. Again, if country calling code is ambiguous, then\r\n\t\t// `this.country` should be re-derived with each new digit.\r\n\t\t//\r\n\t\tif (!this.state.country || this.isCountryCallingCodeAmbiguous()) {\r\n\t\t\tthis.determineTheCountry()\r\n\t\t}\r\n\t}\r\n\r\n\t// Prepends `+CountryCode ` in case of an international phone number\r\n\tgetFullNumber(formattedNationalNumber) {\r\n\t\tif (this.isInternational()) {\r\n\t\t\tconst prefix = (text) => this.formatter.getInternationalPrefixBeforeCountryCallingCode(this.state, {\r\n\t\t\t\tspacing: text ? true : false\r\n\t\t\t}) + text\r\n\t\t\tconst { callingCode } = this.state\r\n\t\t\tif (!callingCode) {\r\n\t\t\t\treturn prefix(`${this.state.getDigitsWithoutInternationalPrefix()}`)\r\n\t\t\t}\r\n\t\t\tif (!formattedNationalNumber) {\r\n\t\t\t\treturn prefix(callingCode)\r\n\t\t\t}\r\n\t\t\treturn prefix(`${callingCode} ${formattedNationalNumber}`)\r\n\t\t}\r\n\t\treturn formattedNationalNumber\r\n\t}\r\n\r\n\tgetNonFormattedNationalNumberWithPrefix() {\r\n\t\tconst {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcomplexPrefixBeforeNationalSignificantNumber,\r\n\t\t\tnationalPrefix\r\n\t\t} = this.state\r\n\t\tlet number = nationalSignificantNumber\r\n\t\tconst prefix = complexPrefixBeforeNationalSignificantNumber || nationalPrefix\r\n\t\tif (prefix) {\r\n\t\t\tnumber = prefix + number\r\n\t\t}\r\n\t\treturn number\r\n\t}\r\n\r\n\tgetNonFormattedNumber() {\r\n\t\tconst { nationalSignificantNumberMatchesInput } = this.state\r\n\t\treturn this.getFullNumber(\r\n\t\t\tnationalSignificantNumberMatchesInput\r\n\t\t\t\t? this.getNonFormattedNationalNumberWithPrefix()\r\n\t\t\t\t: this.state.getNationalDigits()\r\n\t\t)\r\n\t}\r\n\r\n\tgetNonFormattedTemplate() {\r\n\t\tconst number = this.getNonFormattedNumber()\r\n\t\tif (number) {\r\n\t\t\treturn number.replace(/[\\+\\d]/g, DIGIT_PLACEHOLDER)\r\n\t\t}\r\n\t}\r\n\r\n\tisCountryCallingCodeAmbiguous() {\r\n\t\tconst { callingCode } = this.state\r\n\t\tconst countryCodes = this.metadata.getCountryCodesForCallingCode(callingCode)\r\n\t\treturn countryCodes && countryCodes.length > 1\r\n\t}\r\n\r\n\t// Determines the country of the phone number\r\n\t// entered so far based on the country phone code\r\n\t// and the national phone number.\r\n\tdetermineTheCountry() {\r\n\t\tthis.state.setCountry(getCountryByCallingCode(\r\n\t\t\tthis.isInternational() ? this.state.callingCode : this.defaultCallingCode,\r\n\t\t\t{\r\n\t\t\t\tnationalNumber: this.state.nationalSignificantNumber,\r\n\t\t\t\tdefaultCountry: this.defaultCountry,\r\n\t\t\t\tmetadata: this.metadata\r\n\t\t\t}\r\n\t\t))\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a E.164 phone number value for the user's input.\r\n\t *\r\n\t * For example, for country `\"US\"` and input `\"(222) 333-4444\"`\r\n\t * it will return `\"+12223334444\"`.\r\n\t *\r\n\t * For international phone number input, it will also auto-correct\r\n\t * some minor errors such as using a national prefix when writing\r\n\t * an international phone number. For example, if the user inputs\r\n\t * `\"+44 0 7400 000000\"` then it will return an auto-corrected\r\n\t * `\"+447400000000\"` phone number value.\r\n\t *\r\n\t * Will return `undefined` if no digits have been input,\r\n\t * or when inputting a phone number in national format and no\r\n\t * default country or default \"country calling code\" have been set.\r\n\t *\r\n\t * @return {string} [value]\r\n\t */\r\n\tgetNumberValue() {\r\n\t\tconst {\r\n\t\t\tdigits,\r\n\t\t\tcallingCode,\r\n\t\t\tcountry,\r\n\t\t\tnationalSignificantNumber\r\n\t\t} = this.state\r\n\r\n\t \t// Will return `undefined` if no digits have been input.\r\n\t\tif (!digits) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tif (this.isInternational()) {\r\n\t\t\tif (callingCode) {\r\n\t\t\t\treturn '+' + callingCode + nationalSignificantNumber\r\n\t\t\t} else {\r\n\t\t\t\treturn '+' + digits\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tif (country || callingCode) {\r\n\t\t\t\tconst callingCode_ = country ? this.metadata.countryCallingCode() : callingCode\r\n\t\t\t\treturn '+' + callingCode_ + nationalSignificantNumber\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an instance of `PhoneNumber` class.\r\n\t * Will return `undefined` if no national (significant) number\r\n\t * digits have been entered so far, or if no `defaultCountry` has been\r\n\t * set and the user enters a phone number not in international format.\r\n\t */\r\n\tgetNumber() {\r\n\t\tconst {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcarrierCode,\r\n\t\t\tcallingCode\r\n\t\t} = this.state\r\n\r\n\t\t// `this._getCountry()` is basically same as `this.state.country`\r\n\t\t// with the only change that it return `undefined` in case of a\r\n\t\t// \"non-geographic\" numbering plan instead of `\"001\"` \"internal use\" value.\r\n\t\tlet country = this._getCountry()\r\n\r\n\t\tif (!nationalSignificantNumber) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// `state.country` and `state.callingCode` aren't required to be in sync.\r\n\t\t// For example, `country` could be `\"AR\"` and `callingCode` could be `undefined`.\r\n\t\t// So `country` and `callingCode` are totally independent.\r\n\r\n\t\tif (!country && !callingCode) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// By default, if `defaultCountry` parameter was passed when\r\n\t\t// creating `AsYouType` instance, `state.country` is gonna be\r\n\t\t// that `defaultCountry`, which doesn't entirely conform with\r\n\t\t// `parsePhoneNumber()`'s behavior where it attempts to determine\r\n\t\t// the country more precisely in cases when multiple countries\r\n\t\t// could correspond to the same `countryCallingCode`.\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103#note_1417192969\r\n\t\t//\r\n\t\t// Because `AsYouType.getNumber()` method is supposed to be a 1:1\r\n\t\t// equivalent for `parsePhoneNumber(AsYouType.getNumberValue())`,\r\n\t\t// then it should also behave accordingly in cases of `country` ambiguity.\r\n\t\t// That's how users of this library would expect it to behave anyway.\r\n\t\t//\r\n\t\tif (country) {\r\n\t\t\tif (country === this.defaultCountry) {\r\n\t\t\t\t// `state.country` and `state.callingCode` aren't required to be in sync.\r\n\t\t\t\t// For example, `state.country` could be `\"AR\"` and `state.callingCode` could be `undefined`.\r\n\t\t\t\t// So `state.country` and `state.callingCode` are totally independent.\r\n\t\t\t\tconst metadata = new Metadata(this.metadata.metadata)\r\n\t\t\t\tmetadata.selectNumberingPlan(country)\r\n\t\t\t\tconst callingCode = metadata.numberingPlan.callingCode()\r\n\t\t\t\tconst ambiguousCountries = this.metadata.getCountryCodesForCallingCode(callingCode)\r\n\t\t\t\tif (ambiguousCountries.length > 1) {\r\n\t\t\t\t\tconst exactCountry = getCountryByNationalNumber(nationalSignificantNumber, {\r\n\t\t\t\t\t\tcountries: ambiguousCountries,\r\n\t\t\t\t\t\tdefaultCountry: this.defaultCountry,\r\n\t\t\t\t\t\tmetadata: this.metadata.metadata\r\n\t\t\t\t\t})\r\n\t\t\t\t\tif (exactCountry) {\r\n\t\t\t\t\t\tcountry = exactCountry\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst phoneNumber = new PhoneNumber(\r\n\t\t\tcountry || callingCode,\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tthis.metadata.metadata\r\n\t\t)\r\n\t\tif (carrierCode) {\r\n\t\t\tphoneNumber.carrierCode = carrierCode\r\n\t\t}\r\n\t\t// Phone number extensions are not supported by \"As You Type\" formatter.\r\n\t\treturn phoneNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"possible\".\r\n\t * Is just a shortcut for `PhoneNumber.isPossible()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisPossible() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isPossible()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"valid\".\r\n\t * Is just a shortcut for `PhoneNumber.isValid()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisValid() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isValid()\r\n\t}\r\n\r\n\t/**\r\n\t * @deprecated\r\n\t * This method is used in `react-phone-number-input/source/input-control.js`\r\n\t * in versions before `3.0.16`.\r\n\t */\r\n\tgetNationalNumber() {\r\n\t\treturn this.state.nationalSignificantNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the phone number characters entered by the user.\r\n\t * @return {string}\r\n\t */\r\n\tgetChars() {\r\n\t\treturn (this.state.international ? '+' : '') + this.state.digits\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the template for the formatted phone number.\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplate() {\r\n\t\treturn this.formatter.getTemplate(this.state) || this.getNonFormattedTemplate() || ''\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,QAAP,MAAqB,eAArB;AACA,OAAOC,WAAP,MAAwB,kBAAxB;AACA,OAAOC,cAAP,MAA2B,qBAA3B;AACA,OAAOC,kBAAP,IAA6BC,iBAA7B,QAAsD,yBAAtD;AACA,OAAOC,eAAP,IAA0BC,6BAA1B,QAA+D,sBAA/D;AACA,OAAOC,uBAAP,MAAoC,sCAApC;AACA,OAAOC,0BAAP,MAAuC,yCAAvC;AAEA,IAAMC,+BAA+B,GAAG,KAAxC;;IAEqBC,S;EACpB;AACD;AACA;AACA;EACC,mBAAYC,uBAAZ,EAAqCC,QAArC,EAA+C;IAAA;;IAC9C,KAAKA,QAAL,GAAgB,IAAIZ,QAAJ,CAAaY,QAAb,CAAhB;;IACA,4BAA6C,KAAKC,wBAAL,CAA8BF,uBAA9B,CAA7C;IAAA;IAAA,IAAOG,cAAP;IAAA,IAAuBC,kBAAvB,6BAF8C,CAG9C;IACA;IACA;;;IACA,KAAKD,cAAL,GAAsBA,cAAtB;IACA,KAAKC,kBAAL,GAA0BA,kBAA1B;IACA,KAAKC,KAAL;EACA;;;;WAED,kCAAyBL,uBAAzB,EAAkD;MACjD;MACA,IAAIG,cAAJ;MACA,IAAIC,kBAAJ,CAHiD,CAIjD;;MACA,IAAIJ,uBAAJ,EAA6B;QAC5B,IAAI,QAAOA,uBAAP,MAAmC,QAAvC,EAAiD;UAChDG,cAAc,GAAGH,uBAAuB,CAACG,cAAzC;UACAC,kBAAkB,GAAGJ,uBAAuB,CAACI,kBAA7C;QACA,CAHD,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EAGnB,KAAKhB,QAAL,CAAcA,QAHK,CAApB;;MAKA,IAAIyD,WAAJ,EAAiB;QAChBI,WAAW,CAACJ,WAAZ,GAA0BA,WAA1B;MACA,CAlEU,CAmEX;;;MACA,OAAOI,WAAP;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,sBAAa;MACZ,IAAMA,WAAW,GAAG,KAAKC,SAAL,EAApB;;MACA,IAAI,CAACD,WAAL,EAAkB;QACjB,OAAO,KAAP;MACA;;MACD,OAAOA,WAAW,CAACE,UAAZ,EAAP;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,mBAAU;MACT,IAAMF,WAAW,GAAG,KAAKC,SAAL,EAApB;;MACA,IAAI,CAACD,WAAL,EAAkB;QACjB,OAAO,KAAP;MACA;;MACD,OAAOA,WAAW,CAACG,OAAZ,EAAP;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,6BAAoB;MACnB,OAAO,KAAKrD,KAAL,CAAWK,yBAAlB;IACA;IAED;AACD;AACA;AACA;;;;WACC,oBAAW;MACV,OAAO,CAAC,KAAKL,KAAL,CAAWuB,aAAX,GAA2B,GAA3B,GAAiC,EAAlC,IAAwC,KAAKvB,KAAL,CAAWC,MAA1D;IACA;IAED;AACD;AACA;AACA;;;;WACC,uBAAc;MACb,OAAO,KAAKK,SAAL,CAAegD,WAAf,CAA2B,KAAKtD,KAAhC,KAA0C,KAAKuD,uBAAL,EAA1C,IAA4E,EAAnF;IACA;;;;;;SAhcmBpE,S"}
1
+ {"version":3,"file":"AsYouType.js","names":["Metadata","PhoneNumber","AsYouTypeState","AsYouTypeFormatter","DIGIT_PLACEHOLDER","AsYouTypeParser","extractFormattedDigitsAndPlus","getCountryByCallingCode","getCountryByNationalNumber","isObject","USE_NON_GEOGRAPHIC_COUNTRY_CODE","AsYouType","optionsOrDefaultCountry","metadata","getCountryAndCallingCode","defaultCountry","defaultCallingCode","reset","hasCountry","undefined","isNonGeographicCallingCode","text","parser","input","state","digits","justLeadingPlus","formattedOutput","determineTheCountryIfNeeded","nationalSignificantNumber","formatter","narrowDownMatchingFormats","formattedNationalNumber","hasSelectedNumberingPlan","format","reExtractNationalSignificantNumber","nationalDigits","getNationalDigits","getFullNumber","getNonFormattedNumber","onCountryChange","country","onCallingCodeChange","callingCode","selectNumberingPlan","numberingPlan","onNationalSignificantNumberChange","international","isInternational","getCallingCode","_getCountry","isCountryCallingCodeAmbiguous","determineTheCountry","prefix","getInternationalPrefixBeforeCountryCallingCode","spacing","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","nationalPrefix","number","nationalSignificantNumberMatchesInput","getNonFormattedNationalNumberWithPrefix","replace","countryCodes","getCountryCodesForCallingCode","length","setCountry","nationalNumber","callingCode_","countryCallingCode","carrierCode","ambiguousCountries","exactCountry","countries","phoneNumber","getNumber","isPossible","isValid","getTemplate","getNonFormattedTemplate"],"sources":["../source/AsYouType.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport PhoneNumber from './PhoneNumber.js'\r\nimport AsYouTypeState from './AsYouTypeState.js'\r\nimport AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.js'\r\nimport AsYouTypeParser, { extractFormattedDigitsAndPlus } from './AsYouTypeParser.js'\r\nimport getCountryByCallingCode from './helpers/getCountryByCallingCode.js'\r\nimport getCountryByNationalNumber from './helpers/getCountryByNationalNumber.js'\r\nimport isObject from './helpers/isObject.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default class AsYouType {\r\n\t/**\r\n\t * @param {(string|object)?} [optionsOrDefaultCountry] - The default country used for parsing non-international phone numbers. Can also be an `options` object.\r\n\t * @param {Object} metadata\r\n\t */\r\n\tconstructor(optionsOrDefaultCountry, metadata) {\r\n\t\tthis.metadata = new Metadata(metadata)\r\n\t\tconst [defaultCountry, defaultCallingCode] = this.getCountryAndCallingCode(optionsOrDefaultCountry)\r\n\t\t// `this.defaultCountry` and `this.defaultCallingCode` aren't required to be in sync.\r\n\t\t// For example, `this.defaultCountry` could be `\"AR\"` and `this.defaultCallingCode` could be `undefined`.\r\n\t\t// So `this.defaultCountry` and `this.defaultCallingCode` are totally independent.\r\n\t\tthis.defaultCountry = defaultCountry\r\n\t\tthis.defaultCallingCode = defaultCallingCode\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\tgetCountryAndCallingCode(optionsOrDefaultCountry) {\r\n\t\t// Set `defaultCountry` and `defaultCallingCode` options.\r\n\t\tlet defaultCountry\r\n\t\tlet defaultCallingCode\r\n\t\t// Turns out `null` also has type \"object\". Weird.\r\n\t\tif (optionsOrDefaultCountry) {\r\n\t\t\tif (isObject(optionsOrDefaultCountry)) {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry.defaultCountry\r\n\t\t\t\tdefaultCallingCode = optionsOrDefaultCountry.defaultCallingCode\r\n\t\t\t} else {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (defaultCountry && !this.metadata.hasCountry(defaultCountry)) {\r\n\t\t\tdefaultCountry = undefined\r\n\t\t}\r\n\t\tif (defaultCallingCode) {\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t\tif (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {\r\n\t\t\t\t\tdefaultCountry = '001'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn [defaultCountry, defaultCallingCode]\r\n\t}\r\n\r\n\t/**\r\n\t * Inputs \"next\" phone number characters.\r\n\t * @param {string} text\r\n\t * @return {string} Formatted phone number characters that have been input so far.\r\n\t */\r\n\tinput(text) {\r\n\t\tconst {\r\n\t\t\tdigits,\r\n\t\t\tjustLeadingPlus\r\n\t\t} = this.parser.input(text, this.state)\r\n\t\tif (justLeadingPlus) {\r\n\t\t\tthis.formattedOutput = '+'\r\n\t\t} else if (digits) {\r\n\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t// Match the available formats by the currently available leading digits.\r\n\t\t\tif (this.state.nationalSignificantNumber) {\r\n\t\t\t\tthis.formatter.narrowDownMatchingFormats(this.state)\r\n\t\t\t}\r\n\t\t\tlet formattedNationalNumber\r\n\t\t\tif (this.metadata.hasSelectedNumberingPlan()) {\r\n\t\t\t\tformattedNationalNumber = this.formatter.format(digits, this.state)\r\n\t\t\t}\r\n\t\t\tif (formattedNationalNumber === undefined) {\r\n\t\t\t\t// See if another national (significant) number could be re-extracted.\r\n\t\t\t\tif (this.parser.reExtractNationalSignificantNumber(this.state)) {\r\n\t\t\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t\t\t// If it could, then re-try formatting the new national (significant) number.\r\n\t\t\t\t\tconst nationalDigits = this.state.getNationalDigits()\r\n\t\t\t\t\tif (nationalDigits) {\r\n\t\t\t\t\t\tformattedNationalNumber = this.formatter.format(nationalDigits, this.state)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tthis.formattedOutput = formattedNationalNumber\r\n\t\t\t\t? this.getFullNumber(formattedNationalNumber)\r\n\t\t\t\t: this.getNonFormattedNumber()\r\n\t\t}\r\n\t\treturn this.formattedOutput\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.state = new AsYouTypeState({\r\n\t\t\tonCountryChange: (country) => {\r\n\t\t\t\t// Before version `1.6.0`, the official `AsYouType` formatter API\r\n\t\t\t\t// included the `.country` property of an `AsYouType` instance.\r\n\t\t\t\t// Since that property (along with the others) have been moved to\r\n\t\t\t\t// `this.state`, `this.country` property is emulated for compatibility\r\n\t\t\t\t// with the old versions.\r\n\t\t\t\tthis.country = country\r\n\t\t\t},\r\n\t\t\tonCallingCodeChange: (callingCode, country) => {\r\n\t\t\t\tthis.metadata.selectNumberingPlan(country, callingCode)\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t\tthis.parser.reset(this.metadata.numberingPlan)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.formatter = new AsYouTypeFormatter({\r\n\t\t\tstate: this.state,\r\n\t\t\tmetadata: this.metadata\r\n\t\t})\r\n\t\tthis.parser = new AsYouTypeParser({\r\n\t\t\tdefaultCountry: this.defaultCountry,\r\n\t\t\tdefaultCallingCode: this.defaultCallingCode,\r\n\t\t\tmetadata: this.metadata,\r\n\t\t\tstate: this.state,\r\n\t\t\tonNationalSignificantNumberChange: () => {\r\n\t\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.state.reset({\r\n\t\t\tcountry: this.defaultCountry,\r\n\t\t\tcallingCode: this.defaultCallingCode\r\n\t\t})\r\n\t\tthis.formattedOutput = ''\r\n\t\treturn this\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is being input in international format.\r\n\t * In other words, returns `true` if and only if the parsed phone number starts with a `\"+\"`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisInternational() {\r\n\t\treturn this.state.international\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the \"calling code\" part of the phone number when it's being input\r\n\t * in an international format.\r\n\t * If no valid calling code has been entered so far, returns `undefined`.\r\n\t * @return {string} [callingCode]\r\n\t */\r\n\tgetCallingCode() {\r\n\t\t // If the number is being input in national format and some \"default calling code\"\r\n\t\t // has been passed to `AsYouType` constructor, then `this.state.callingCode`\r\n\t\t // is equal to that \"default calling code\".\r\n\t\t //\r\n\t\t // If the number is being input in national format and no \"default calling code\"\r\n\t\t // has been passed to `AsYouType` constructor, then returns `undefined`,\r\n\t\t // even if a \"default country\" has been passed to `AsYouType` constructor.\r\n\t\t //\r\n\t\tif (this.isInternational()) {\r\n\t\t\treturn this.state.callingCode\r\n\t\t}\r\n\t}\r\n\r\n\t// A legacy alias.\r\n\tgetCountryCallingCode() {\r\n\t\treturn this.getCallingCode()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a two-letter country code of the phone number.\r\n\t * Returns `undefined` for \"non-geographic\" phone numbering plans.\r\n\t * Returns `undefined` if no phone number has been input yet.\r\n\t * @return {string} [country]\r\n\t */\r\n\tgetCountry() {\r\n\t\tconst { digits } = this.state\r\n\t\t// Return `undefined` if no digits have been input yet.\r\n\t\tif (digits) {\r\n\t\t\treturn this._getCountry()\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a two-letter country code of the phone number.\r\n\t * Returns `undefined` for \"non-geographic\" phone numbering plans.\r\n\t * @return {string} [country]\r\n\t */\r\n\t_getCountry() {\r\n\t\tconst { country } = this.state\r\n\t\t/* istanbul ignore if */\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t// `AsYouType.getCountry()` returns `undefined`\r\n\t\t\t// for \"non-geographic\" phone numbering plans.\r\n\t\t\tif (country === '001') {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn country\r\n\t}\r\n\r\n\tdetermineTheCountryIfNeeded() {\r\n\t\t// Suppose a user enters a phone number in international format,\r\n\t\t// and there're several countries corresponding to that country calling code,\r\n\t\t// and a country has been derived from the number, and then\r\n\t\t// a user enters one more digit and the number is no longer\r\n\t\t// valid for the derived country, so the country should be re-derived\r\n\t\t// on every new digit in those cases.\r\n\t\t//\r\n\t\t// If the phone number is being input in national format,\r\n\t\t// then it could be a case when `defaultCountry` wasn't specified\r\n\t\t// when creating `AsYouType` instance, and just `defaultCallingCode` was specified,\r\n\t\t// and that \"calling code\" could correspond to a \"non-geographic entity\",\r\n\t\t// or there could be several countries corresponding to that country calling code.\r\n\t\t// In those cases, `this.country` is `undefined` and should be derived\r\n\t\t// from the number. Again, if country calling code is ambiguous, then\r\n\t\t// `this.country` should be re-derived with each new digit.\r\n\t\t//\r\n\t\tif (!this.state.country || this.isCountryCallingCodeAmbiguous()) {\r\n\t\t\tthis.determineTheCountry()\r\n\t\t}\r\n\t}\r\n\r\n\t// Prepends `+CountryCode ` in case of an international phone number\r\n\tgetFullNumber(formattedNationalNumber) {\r\n\t\tif (this.isInternational()) {\r\n\t\t\tconst prefix = (text) => this.formatter.getInternationalPrefixBeforeCountryCallingCode(this.state, {\r\n\t\t\t\tspacing: text ? true : false\r\n\t\t\t}) + text\r\n\t\t\tconst { callingCode } = this.state\r\n\t\t\tif (!callingCode) {\r\n\t\t\t\treturn prefix(`${this.state.getDigitsWithoutInternationalPrefix()}`)\r\n\t\t\t}\r\n\t\t\tif (!formattedNationalNumber) {\r\n\t\t\t\treturn prefix(callingCode)\r\n\t\t\t}\r\n\t\t\treturn prefix(`${callingCode} ${formattedNationalNumber}`)\r\n\t\t}\r\n\t\treturn formattedNationalNumber\r\n\t}\r\n\r\n\tgetNonFormattedNationalNumberWithPrefix() {\r\n\t\tconst {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcomplexPrefixBeforeNationalSignificantNumber,\r\n\t\t\tnationalPrefix\r\n\t\t} = this.state\r\n\t\tlet number = nationalSignificantNumber\r\n\t\tconst prefix = complexPrefixBeforeNationalSignificantNumber || nationalPrefix\r\n\t\tif (prefix) {\r\n\t\t\tnumber = prefix + number\r\n\t\t}\r\n\t\treturn number\r\n\t}\r\n\r\n\tgetNonFormattedNumber() {\r\n\t\tconst { nationalSignificantNumberMatchesInput } = this.state\r\n\t\treturn this.getFullNumber(\r\n\t\t\tnationalSignificantNumberMatchesInput\r\n\t\t\t\t? this.getNonFormattedNationalNumberWithPrefix()\r\n\t\t\t\t: this.state.getNationalDigits()\r\n\t\t)\r\n\t}\r\n\r\n\tgetNonFormattedTemplate() {\r\n\t\tconst number = this.getNonFormattedNumber()\r\n\t\tif (number) {\r\n\t\t\treturn number.replace(/[\\+\\d]/g, DIGIT_PLACEHOLDER)\r\n\t\t}\r\n\t}\r\n\r\n\tisCountryCallingCodeAmbiguous() {\r\n\t\tconst { callingCode } = this.state\r\n\t\tconst countryCodes = this.metadata.getCountryCodesForCallingCode(callingCode)\r\n\t\treturn countryCodes && countryCodes.length > 1\r\n\t}\r\n\r\n\t// Determines the country of the phone number\r\n\t// entered so far based on the country phone code\r\n\t// and the national phone number.\r\n\tdetermineTheCountry() {\r\n\t\tthis.state.setCountry(getCountryByCallingCode(\r\n\t\t\tthis.isInternational() ? this.state.callingCode : this.defaultCallingCode,\r\n\t\t\t{\r\n\t\t\t\tnationalNumber: this.state.nationalSignificantNumber,\r\n\t\t\t\tdefaultCountry: this.defaultCountry,\r\n\t\t\t\tmetadata: this.metadata\r\n\t\t\t}\r\n\t\t))\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a E.164 phone number value for the user's input.\r\n\t *\r\n\t * For example, for country `\"US\"` and input `\"(222) 333-4444\"`\r\n\t * it will return `\"+12223334444\"`.\r\n\t *\r\n\t * For international phone number input, it will also auto-correct\r\n\t * some minor errors such as using a national prefix when writing\r\n\t * an international phone number. For example, if the user inputs\r\n\t * `\"+44 0 7400 000000\"` then it will return an auto-corrected\r\n\t * `\"+447400000000\"` phone number value.\r\n\t *\r\n\t * Will return `undefined` if no digits have been input,\r\n\t * or when inputting a phone number in national format and no\r\n\t * default country or default \"country calling code\" have been set.\r\n\t *\r\n\t * @return {string} [value]\r\n\t */\r\n\tgetNumberValue() {\r\n\t\tconst {\r\n\t\t\tdigits,\r\n\t\t\tcallingCode,\r\n\t\t\tcountry,\r\n\t\t\tnationalSignificantNumber\r\n\t\t} = this.state\r\n\r\n\t \t// Will return `undefined` if no digits have been input.\r\n\t\tif (!digits) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tif (this.isInternational()) {\r\n\t\t\tif (callingCode) {\r\n\t\t\t\treturn '+' + callingCode + nationalSignificantNumber\r\n\t\t\t} else {\r\n\t\t\t\treturn '+' + digits\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tif (country || callingCode) {\r\n\t\t\t\tconst callingCode_ = country ? this.metadata.countryCallingCode() : callingCode\r\n\t\t\t\treturn '+' + callingCode_ + nationalSignificantNumber\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an instance of `PhoneNumber` class.\r\n\t * Will return `undefined` if no national (significant) number\r\n\t * digits have been entered so far, or if no `defaultCountry` has been\r\n\t * set and the user enters a phone number not in international format.\r\n\t */\r\n\tgetNumber() {\r\n\t\tconst {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcarrierCode,\r\n\t\t\tcallingCode\r\n\t\t} = this.state\r\n\r\n\t\t// `this._getCountry()` is basically same as `this.state.country`\r\n\t\t// with the only change that it return `undefined` in case of a\r\n\t\t// \"non-geographic\" numbering plan instead of `\"001\"` \"internal use\" value.\r\n\t\tlet country = this._getCountry()\r\n\r\n\t\tif (!nationalSignificantNumber) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// `state.country` and `state.callingCode` aren't required to be in sync.\r\n\t\t// For example, `country` could be `\"AR\"` and `callingCode` could be `undefined`.\r\n\t\t// So `country` and `callingCode` are totally independent.\r\n\r\n\t\tif (!country && !callingCode) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// By default, if `defaultCountry` parameter was passed when\r\n\t\t// creating `AsYouType` instance, `state.country` is gonna be\r\n\t\t// that `defaultCountry`, which doesn't entirely conform with\r\n\t\t// `parsePhoneNumber()`'s behavior where it attempts to determine\r\n\t\t// the country more precisely in cases when multiple countries\r\n\t\t// could correspond to the same `countryCallingCode`.\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103#note_1417192969\r\n\t\t//\r\n\t\t// Because `AsYouType.getNumber()` method is supposed to be a 1:1\r\n\t\t// equivalent for `parsePhoneNumber(AsYouType.getNumberValue())`,\r\n\t\t// then it should also behave accordingly in cases of `country` ambiguity.\r\n\t\t// That's how users of this library would expect it to behave anyway.\r\n\t\t//\r\n\t\tif (country) {\r\n\t\t\tif (country === this.defaultCountry) {\r\n\t\t\t\t// `state.country` and `state.callingCode` aren't required to be in sync.\r\n\t\t\t\t// For example, `state.country` could be `\"AR\"` and `state.callingCode` could be `undefined`.\r\n\t\t\t\t// So `state.country` and `state.callingCode` are totally independent.\r\n\t\t\t\tconst metadata = new Metadata(this.metadata.metadata)\r\n\t\t\t\tmetadata.selectNumberingPlan(country)\r\n\t\t\t\tconst callingCode = metadata.numberingPlan.callingCode()\r\n\t\t\t\tconst ambiguousCountries = this.metadata.getCountryCodesForCallingCode(callingCode)\r\n\t\t\t\tif (ambiguousCountries.length > 1) {\r\n\t\t\t\t\tconst exactCountry = getCountryByNationalNumber(nationalSignificantNumber, {\r\n\t\t\t\t\t\tcountries: ambiguousCountries,\r\n\t\t\t\t\t\tdefaultCountry: this.defaultCountry,\r\n\t\t\t\t\t\tmetadata: this.metadata.metadata\r\n\t\t\t\t\t})\r\n\t\t\t\t\tif (exactCountry) {\r\n\t\t\t\t\t\tcountry = exactCountry\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst phoneNumber = new PhoneNumber(\r\n\t\t\tcountry || callingCode,\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tthis.metadata.metadata\r\n\t\t)\r\n\t\tif (carrierCode) {\r\n\t\t\tphoneNumber.carrierCode = carrierCode\r\n\t\t}\r\n\t\t// Phone number extensions are not supported by \"As You Type\" formatter.\r\n\t\treturn phoneNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"possible\".\r\n\t * Is just a shortcut for `PhoneNumber.isPossible()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisPossible() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isPossible()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"valid\".\r\n\t * Is just a shortcut for `PhoneNumber.isValid()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisValid() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isValid()\r\n\t}\r\n\r\n\t/**\r\n\t * @deprecated\r\n\t * This method is used in `react-phone-number-input/source/input-control.js`\r\n\t * in versions before `3.0.16`.\r\n\t */\r\n\tgetNationalNumber() {\r\n\t\treturn this.state.nationalSignificantNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the phone number characters entered by the user.\r\n\t * @return {string}\r\n\t */\r\n\tgetChars() {\r\n\t\treturn (this.state.international ? '+' : '') + this.state.digits\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the template for the formatted phone number.\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplate() {\r\n\t\treturn this.formatter.getTemplate(this.state) || this.getNonFormattedTemplate() || ''\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAOA,QAAP,MAAqB,eAArB;AACA,OAAOC,WAAP,MAAwB,kBAAxB;AACA,OAAOC,cAAP,MAA2B,qBAA3B;AACA,OAAOC,kBAAP,IAA6BC,iBAA7B,QAAsD,yBAAtD;AACA,OAAOC,eAAP,IAA0BC,6BAA1B,QAA+D,sBAA/D;AACA,OAAOC,uBAAP,MAAoC,sCAApC;AACA,OAAOC,0BAAP,MAAuC,yCAAvC;AACA,OAAOC,QAAP,MAAqB,uBAArB;AAEA,IAAMC,+BAA+B,GAAG,KAAxC;;IAEqBC,S;EACpB;AACD;AACA;AACA;EACC,mBAAYC,uBAAZ,EAAqCC,QAArC,EAA+C;IAAA;;IAC9C,KAAKA,QAAL,GAAgB,IAAIb,QAAJ,CAAaa,QAAb,CAAhB;;IACA,4BAA6C,KAAKC,wBAAL,CAA8BF,uBAA9B,CAA7C;IAAA;IAAA,IAAOG,cAAP;IAAA,IAAuBC,kBAAvB,6BAF8C,CAG9C;IACA;IACA;;;IACA,KAAKD,cAAL,GAAsBA,cAAtB;IACA,KAAKC,kBAAL,GAA0BA,kBAA1B;IACA,KAAKC,KAAL;EACA;;;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
4
  * The phone number can be either in E.164 format
5
5
  * or in a form of national number digits.
6
6
  * @param {string} value - A possibly incomplete phone number. Either in E.164 format or in a form of national number digits.
7
- * @param {string?} country - Two-letter ("ISO 3166-1 alpha-2") country code.
7
+ * @param {string|object} [optionsOrDefaultCountry] - A two-letter ("ISO 3166-1 alpha-2") country code, or an object of shape `{ defaultCountry?: string, defaultCallingCode?: string }`.
8
8
  * @return {string} Formatted (possibly incomplete) phone number.
9
9
  */
10
10
 
11
- export default function formatIncompletePhoneNumber(value, country, metadata) {
11
+ export default function formatIncompletePhoneNumber(value, optionsOrDefaultCountry, metadata) {
12
12
  if (!metadata) {
13
- metadata = country;
14
- country = undefined;
13
+ metadata = optionsOrDefaultCountry;
14
+ optionsOrDefaultCountry = undefined;
15
15
  }
16
16
 
17
- return new AsYouType(country, metadata).input(value);
17
+ return new AsYouType(optionsOrDefaultCountry, metadata).input(value);
18
18
  }
19
19
  //# sourceMappingURL=formatIncompletePhoneNumber.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatIncompletePhoneNumber.js","names":["AsYouType","formatIncompletePhoneNumber","value","country","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?} country - Two-letter (\"ISO 3166-1 alpha-2\") country code.\r\n * @return {string} Formatted (possibly incomplete) phone number.\r\n */\r\nexport default function formatIncompletePhoneNumber(value, country, metadata) {\r\n\tif (!metadata) {\r\n\t\tmetadata = country\r\n\t\tcountry = undefined\r\n\t}\r\n\treturn new AsYouType(country, metadata).input(value)\r\n}"],"mappings":"AAAA,OAAOA,SAAP,MAAsB,gBAAtB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,2BAAT,CAAqCC,KAArC,EAA4CC,OAA5C,EAAqDC,QAArD,EAA+D;EAC7E,IAAI,CAACA,QAAL,EAAe;IACdA,QAAQ,GAAGD,OAAX;IACAA,OAAO,GAAGE,SAAV;EACA;;EACD,OAAO,IAAIL,SAAJ,CAAcG,OAAd,EAAuBC,QAAvB,EAAiCE,KAAjC,CAAuCJ,KAAvC,CAAP;AACA"}
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,SAAP,MAAsB,gBAAtB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,2BAAT,CAAqCC,KAArC,EAA4CC,uBAA5C,EAAqEC,QAArE,EAA+E;EAC7F,IAAI,CAACA,QAAL,EAAe;IACdA,QAAQ,GAAGD,uBAAX;IACAA,uBAAuB,GAAGE,SAA1B;EACA;;EACD,OAAO,IAAIL,SAAJ,CAAcG,uBAAd,EAAuCC,QAAvC,EAAiDE,KAAjD,CAAuDJ,KAAvD,CAAP;AACA"}
@@ -12,5 +12,13 @@ describe('formatIncompletePhoneNumber', function () {
12
12
 
13
13
  formatIncompletePhoneNumber('+780055535', 'RU', metadata).should.equal('+7 800 555 35');
14
14
  });
15
+ it('should support an object argument', function () {
16
+ formatIncompletePhoneNumber('880055535', {
17
+ defaultCountry: 'RU'
18
+ }, metadata).should.equal('8 (800) 555-35');
19
+ formatIncompletePhoneNumber('880055535', {
20
+ defaultCallingCode: '7'
21
+ }, metadata).should.equal('8 (800) 555-35');
22
+ });
15
23
  });
16
24
  //# sourceMappingURL=formatIncompletePhoneNumber.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatIncompletePhoneNumber.test.js","names":["formatIncompletePhoneNumber","metadata","type","describe","it","result","should","equal"],"sources":["../source/formatIncompletePhoneNumber.test.js"],"sourcesContent":["import formatIncompletePhoneNumber from './formatIncompletePhoneNumber.js'\r\n\r\nimport metadata from '../metadata.min.json' assert { 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\tformatIncompletePhoneNumber('880055535', 'RU', metadata).should.equal('8 (800) 555-35')\r\n\r\n\t\t// International input, no country.\r\n\t\tformatIncompletePhoneNumber('+780055535', null, metadata).should.equal('+7 800 555 35')\r\n\r\n\t\t// International input, no country argument.\r\n\t\tformatIncompletePhoneNumber('+780055535', metadata).should.equal('+7 800 555 35')\r\n\r\n\t\t// International input, with country.\r\n\t\tformatIncompletePhoneNumber('+780055535', 'RU', metadata).should.equal('+7 800 555 35')\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,2BAAP,MAAwC,kCAAxC;AAEA,OAAOC,QAAP,MAAqB,sBAArB,UAAqDC,IAAI,EAAE,MAA3D;AAEAC,QAAQ,CAAC,6BAAD,EAAgC,YAAM;EAC7CC,EAAE,CAAC,kCAAD,EAAqC,YAAM;IAC5C,IAAIC,MAAJ,CAD4C,CAG5C;;IACAL,2BAA2B,CAAC,WAAD,EAAc,IAAd,EAAoBC,QAApB,CAA3B,CAAyDK,MAAzD,CAAgEC,KAAhE,CAAsE,gBAAtE,EAJ4C,CAM5C;;IACAP,2BAA2B,CAAC,YAAD,EAAe,IAAf,EAAqBC,QAArB,CAA3B,CAA0DK,MAA1D,CAAiEC,KAAjE,CAAuE,eAAvE,EAP4C,CAS5C;;IACAP,2BAA2B,CAAC,YAAD,EAAeC,QAAf,CAA3B,CAAoDK,MAApD,CAA2DC,KAA3D,CAAiE,eAAjE,EAV4C,CAY5C;;IACAP,2BAA2B,CAAC,YAAD,EAAe,IAAf,EAAqBC,QAArB,CAA3B,CAA0DK,MAA1D,CAAiEC,KAAjE,CAAuE,eAAvE;EACA,CAdC,CAAF;AAeA,CAhBO,CAAR"}
1
+ {"version":3,"file":"formatIncompletePhoneNumber.test.js","names":["formatIncompletePhoneNumber","metadata","type","describe","it","result","should","equal","defaultCountry","defaultCallingCode"],"sources":["../source/formatIncompletePhoneNumber.test.js"],"sourcesContent":["import formatIncompletePhoneNumber from './formatIncompletePhoneNumber.js'\r\n\r\nimport metadata from '../metadata.min.json' assert { 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\tformatIncompletePhoneNumber('880055535', 'RU', metadata).should.equal('8 (800) 555-35')\r\n\r\n\t\t// International input, no country.\r\n\t\tformatIncompletePhoneNumber('+780055535', null, metadata).should.equal('+7 800 555 35')\r\n\r\n\t\t// International input, no country argument.\r\n\t\tformatIncompletePhoneNumber('+780055535', metadata).should.equal('+7 800 555 35')\r\n\r\n\t\t// International input, with country.\r\n\t\tformatIncompletePhoneNumber('+780055535', 'RU', metadata).should.equal('+7 800 555 35')\r\n\t})\r\n\r\n\tit('should support an object argument', () => {\r\n\t\tformatIncompletePhoneNumber('880055535', { defaultCountry: 'RU' }, metadata).should.equal('8 (800) 555-35')\r\n\t\tformatIncompletePhoneNumber('880055535', { defaultCallingCode: '7' }, metadata).should.equal('8 (800) 555-35')\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,2BAAP,MAAwC,kCAAxC;AAEA,OAAOC,QAAP,MAAqB,sBAArB,UAAqDC,IAAI,EAAE,MAA3D;AAEAC,QAAQ,CAAC,6BAAD,EAAgC,YAAM;EAC7CC,EAAE,CAAC,kCAAD,EAAqC,YAAM;IAC5C,IAAIC,MAAJ,CAD4C,CAG5C;;IACAL,2BAA2B,CAAC,WAAD,EAAc,IAAd,EAAoBC,QAApB,CAA3B,CAAyDK,MAAzD,CAAgEC,KAAhE,CAAsE,gBAAtE,EAJ4C,CAM5C;;IACAP,2BAA2B,CAAC,YAAD,EAAe,IAAf,EAAqBC,QAArB,CAA3B,CAA0DK,MAA1D,CAAiEC,KAAjE,CAAuE,eAAvE,EAP4C,CAS5C;;IACAP,2BAA2B,CAAC,YAAD,EAAeC,QAAf,CAA3B,CAAoDK,MAApD,CAA2DC,KAA3D,CAAiE,eAAjE,EAV4C,CAY5C;;IACAP,2BAA2B,CAAC,YAAD,EAAe,IAAf,EAAqBC,QAArB,CAA3B,CAA0DK,MAA1D,CAAiEC,KAAjE,CAAuE,eAAvE;EACA,CAdC,CAAF;EAgBAH,EAAE,CAAC,mCAAD,EAAsC,YAAM;IAC7CJ,2BAA2B,CAAC,WAAD,EAAc;MAAEQ,cAAc,EAAE;IAAlB,CAAd,EAAwCP,QAAxC,CAA3B,CAA6EK,MAA7E,CAAoFC,KAApF,CAA0F,gBAA1F;IACAP,2BAA2B,CAAC,WAAD,EAAc;MAAES,kBAAkB,EAAE;IAAtB,CAAd,EAA2CR,QAA3C,CAA3B,CAAgFK,MAAhF,CAAuFC,KAAvF,CAA6F,gBAA7F;EACA,CAHC,CAAF;AAIA,CArBO,CAAR"}
@@ -0,0 +1,5 @@
1
+ var objectConstructor = {}.constructor;
2
+ export default function isObject(object) {
3
+ return object !== undefined && object !== null && object.constructor === objectConstructor;
4
+ }
5
+ //# sourceMappingURL=isObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isObject.js","names":["objectConstructor","constructor","isObject","object","undefined"],"sources":["../../source/helpers/isObject.js"],"sourcesContent":["const objectConstructor = {}.constructor;\r\n\r\nexport default function isObject(object) {\r\n return object !== undefined && object !== null && object.constructor === objectConstructor;\r\n}\r\n"],"mappings":"AAAA,IAAMA,iBAAiB,GAAG,GAAGC,WAA7B;AAEA,eAAe,SAASC,QAAT,CAAkBC,MAAlB,EAA0B;EACvC,OAAOA,MAAM,KAAKC,SAAX,IAAwBD,MAAM,KAAK,IAAnC,IAA2CA,MAAM,CAACF,WAAP,KAAuBD,iBAAzE;AACD"}
@@ -1,5 +1,3 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
-
3
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
2
 
5
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -14,6 +12,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
12
 
15
13
  import _formatNumber from '../format.js';
16
14
  import parse from '../parse.js';
15
+ import isObject from '../helpers/isObject.js';
17
16
  export default function formatNumber() {
18
17
  var _normalizeArguments = normalizeArguments(arguments),
19
18
  input = _normalizeArguments.input,
@@ -79,7 +78,7 @@ function normalizeArguments(args) {
79
78
  }
80
79
  } // If the phone number is passed as a parsed number object.
81
80
  // `format({ phone: '8005553535', country: 'RU' }, 'NATIONAL', [options], metadata)`.
82
- else if (is_object(arg_1)) {
81
+ else if (isObject(arg_1)) {
83
82
  input = arg_1;
84
83
  format = arg_2;
85
84
 
@@ -104,13 +103,5 @@ function normalizeArguments(args) {
104
103
  options: options,
105
104
  metadata: metadata
106
105
  };
107
- } // Babel transforms `typeof` into some "branches"
108
- // so istanbul will show this as "branch not covered".
109
-
110
- /* istanbul ignore next */
111
-
112
-
113
- var is_object = function is_object(_) {
114
- return _typeof(_) === 'object';
115
- };
106
+ }
116
107
  //# sourceMappingURL=format.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","names":["_formatNumber","parse","formatNumber","normalizeArguments","arguments","input","format","options","metadata","args","Array","prototype","slice","call","arg_1","arg_2","arg_3","arg_4","arg_5","defaultCountry","extended","Error","is_object","TypeError","_"],"sources":["../../source/legacy/format.js"],"sourcesContent":["import _formatNumber from '../format.js'\r\nimport parse from '../parse.js'\r\n\r\nexport default function formatNumber() {\r\n\tconst {\r\n\t\tinput,\r\n\t\tformat,\r\n\t\toptions,\r\n\t\tmetadata\r\n\t} = normalizeArguments(arguments)\r\n\r\n\treturn _formatNumber(input, format, options, metadata)\r\n}\r\n\r\n// Sort out arguments\r\nfunction normalizeArguments(args)\r\n{\r\n\tconst [arg_1, arg_2, arg_3, arg_4, arg_5] = Array.prototype.slice.call(args)\r\n\r\n\tlet input\r\n\tlet format\r\n\tlet options\r\n\tlet metadata\r\n\r\n\t// Sort out arguments.\r\n\r\n\t// If the phone number is passed as a string.\r\n\t// `format('8005553535', ...)`.\r\n\tif (typeof arg_1 === 'string')\r\n\t{\r\n\t\t// If country code is supplied.\r\n\t\t// `format('8005553535', 'RU', 'NATIONAL', [options], metadata)`.\r\n\t\tif (typeof arg_3 === 'string')\r\n\t\t{\r\n\t\t\tformat = arg_3\r\n\r\n\t\t\tif (arg_5)\r\n\t\t\t{\r\n\t\t\t\toptions = arg_4\r\n\t\t\t\tmetadata = arg_5\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tmetadata = arg_4\r\n\t\t\t}\r\n\r\n\t\t\tinput = parse(arg_1, { defaultCountry: arg_2, extended: true }, metadata)\r\n\t\t}\r\n\t\t// Just an international phone number is supplied\r\n\t\t// `format('+78005553535', 'NATIONAL', [options], metadata)`.\r\n\t\telse\r\n\t\t{\r\n\t\t\tif (typeof arg_2 !== 'string')\r\n\t\t\t{\r\n\t\t\t\tthrow new Error('`format` argument not passed to `formatNumber(number, format)`')\r\n\t\t\t}\r\n\r\n\t\t\tformat = arg_2\r\n\r\n\t\t\tif (arg_4)\r\n\t\t\t{\r\n\t\t\t\toptions = arg_3\r\n\t\t\t\tmetadata = arg_4\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tmetadata = arg_3\r\n\t\t\t}\r\n\r\n\t\t\tinput = parse(arg_1, { extended: true }, metadata)\r\n\t\t}\r\n\t}\r\n\t// If the phone number is passed as a parsed number object.\r\n\t// `format({ phone: '8005553535', country: 'RU' }, 'NATIONAL', [options], metadata)`.\r\n\telse if (is_object(arg_1))\r\n\t{\r\n\t\tinput = arg_1\r\n\t\tformat = arg_2\r\n\r\n\t\tif (arg_4)\r\n\t\t{\r\n\t\t\toptions = arg_3\r\n\t\t\tmetadata = arg_4\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tmetadata = arg_3\r\n\t\t}\r\n\t}\r\n\telse throw new TypeError('A phone number must either be a string or an object of shape { phone, [country] }.')\r\n\r\n\t// Legacy lowercase formats.\r\n\tif (format === 'International') {\r\n\t\tformat = 'INTERNATIONAL'\r\n\t} else if (format === 'National') {\r\n\t\tformat = 'NATIONAL'\r\n\t}\r\n\r\n\treturn {\r\n\t\tinput,\r\n\t\tformat,\r\n\t\toptions,\r\n\t\tmetadata\r\n\t}\r\n}\r\n\r\n// Babel transforms `typeof` into some \"branches\"\r\n// so istanbul will show this as \"branch not covered\".\r\n/* istanbul ignore next */\r\nconst is_object = _ => typeof _ === 'object'"],"mappings":";;;;;;;;;;;;;;AAAA,OAAOA,aAAP,MAA0B,cAA1B;AACA,OAAOC,KAAP,MAAkB,aAAlB;AAEA,eAAe,SAASC,YAAT,GAAwB;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QACCT,QAAQ,GAAGQ,KAAX;MACA;;MAEDX,KAAK,GAAGJ,KAAK,CAACa,KAAD,EAAQ;QAAEM,QAAQ,EAAE;MAAZ,CAAR,EAA4BZ,QAA5B,CAAb;IACA;EACD,CA3CD,CA4CA;EACA;EA7CA,KA8CK,IAAIc,SAAS,CAACR,KAAD,CAAb,EACL;IACCT,KAAK,GAAIS,KAAT;IACAR,MAAM,GAAGS,KAAT;;IAEA,IAAIE,KAAJ,EACA;MACCV,OAAO,GAAIS,KAAX;MACAR,QAAQ,GAAGS,KAAX;IACA,CAJD,MAMA;MACCT,QAAQ,GAAGQ,KAAX;IACA;EACD,CAdI,MAeA,MAAM,IAAIO,SAAJ,CAAc,oFAAd,CAAN,CAzEN,CA2EC;;;EACA,IAAIjB,MAAM,KAAK,eAAf,EAAgC;IAC/BA,MAAM,GAAG,eAAT;EACA,CAFD,MAEO,IAAIA,MAAM,KAAK,UAAf,EAA2B;IACjCA,MAAM,GAAG,UAAT;EACA;;EAED,OAAO;IACND,KAAK,EAALA,KADM;IAENC,MAAM,EAANA,MAFM;IAGNC,OAAO,EAAPA,OAHM;IAINC,QAAQ,EAARA;EAJM,CAAP;AAMA,C,CAED;AACA;;AACA;;;AACA,IAAMc,SAAS,GAAG,SAAZA,SAAY,CAAAE,CAAC;EAAA,OAAI,QAAOA,CAAP,MAAa,QAAjB;AAAA,CAAnB"}
1
+ {"version":3,"file":"format.js","names":["_formatNumber","parse","isObject","formatNumber","normalizeArguments","arguments","input","format","options","metadata","args","Array","prototype","slice","call","arg_1","arg_2","arg_3","arg_4","arg_5","defaultCountry","extended","Error","TypeError"],"sources":["../../source/legacy/format.js"],"sourcesContent":["import _formatNumber from '../format.js'\r\nimport parse from '../parse.js'\r\nimport isObject from '../helpers/isObject.js'\r\n\r\nexport default function formatNumber() {\r\n\tconst {\r\n\t\tinput,\r\n\t\tformat,\r\n\t\toptions,\r\n\t\tmetadata\r\n\t} = normalizeArguments(arguments)\r\n\r\n\treturn _formatNumber(input, format, options, metadata)\r\n}\r\n\r\n// Sort out arguments\r\nfunction normalizeArguments(args)\r\n{\r\n\tconst [arg_1, arg_2, arg_3, arg_4, arg_5] = Array.prototype.slice.call(args)\r\n\r\n\tlet input\r\n\tlet format\r\n\tlet options\r\n\tlet metadata\r\n\r\n\t// Sort out arguments.\r\n\r\n\t// If the phone number is passed as a string.\r\n\t// `format('8005553535', ...)`.\r\n\tif (typeof arg_1 === 'string')\r\n\t{\r\n\t\t// If country code is supplied.\r\n\t\t// `format('8005553535', 'RU', 'NATIONAL', [options], metadata)`.\r\n\t\tif (typeof arg_3 === 'string')\r\n\t\t{\r\n\t\t\tformat = arg_3\r\n\r\n\t\t\tif (arg_5)\r\n\t\t\t{\r\n\t\t\t\toptions = arg_4\r\n\t\t\t\tmetadata = arg_5\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tmetadata = arg_4\r\n\t\t\t}\r\n\r\n\t\t\tinput = parse(arg_1, { defaultCountry: arg_2, extended: true }, metadata)\r\n\t\t}\r\n\t\t// Just an international phone number is supplied\r\n\t\t// `format('+78005553535', 'NATIONAL', [options], metadata)`.\r\n\t\telse\r\n\t\t{\r\n\t\t\tif (typeof arg_2 !== 'string')\r\n\t\t\t{\r\n\t\t\t\tthrow new Error('`format` argument not passed to `formatNumber(number, format)`')\r\n\t\t\t}\r\n\r\n\t\t\tformat = arg_2\r\n\r\n\t\t\tif (arg_4)\r\n\t\t\t{\r\n\t\t\t\toptions = arg_3\r\n\t\t\t\tmetadata = arg_4\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tmetadata = arg_3\r\n\t\t\t}\r\n\r\n\t\t\tinput = parse(arg_1, { extended: true }, metadata)\r\n\t\t}\r\n\t}\r\n\t// If the phone number is passed as a parsed number object.\r\n\t// `format({ phone: '8005553535', country: 'RU' }, 'NATIONAL', [options], metadata)`.\r\n\telse if (isObject(arg_1))\r\n\t{\r\n\t\tinput = arg_1\r\n\t\tformat = arg_2\r\n\r\n\t\tif (arg_4)\r\n\t\t{\r\n\t\t\toptions = arg_3\r\n\t\t\tmetadata = arg_4\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tmetadata = arg_3\r\n\t\t}\r\n\t}\r\n\telse throw new TypeError('A phone number must either be a string or an object of shape { phone, [country] }.')\r\n\r\n\t// Legacy lowercase formats.\r\n\tif (format === 'International') {\r\n\t\tformat = 'INTERNATIONAL'\r\n\t} else if (format === 'National') {\r\n\t\tformat = 'NATIONAL'\r\n\t}\r\n\r\n\treturn {\r\n\t\tinput,\r\n\t\tformat,\r\n\t\toptions,\r\n\t\tmetadata\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,aAAP,MAA0B,cAA1B;AACA,OAAOC,KAAP,MAAkB,aAAlB;AACA,OAAOC,QAAP,MAAqB,wBAArB;AAEA,eAAe,SAASC,YAAT,GAAwB;EACtC,0BAKIC,kBAAkB,CAACC,SAAD,CALtB;EAAA,IACCC,KADD,uBACCA,KADD;EAAA,IAECC,MAFD,uBAECA,MAFD;EAAA,IAGCC,OAHD,uBAGCA,OAHD;EAAA,IAICC,QAJD,uBAICA,QAJD;;EAOA,OAAOT,aAAa,CAACM,KAAD,EAAQC,MAAR,EAAgBC,OAAhB,EAAyBC,QAAzB,CAApB;AACA,C,CAED;;AACA,SAASL,kBAAT,CAA4BM,IAA5B,EACA;EACC,4BAA4CC,KAAK,CAACC,SAAN,CAAgBC,KAAhB,CAAsBC,IAAtB,CAA2BJ,IAA3B,CAA5C;EAAA;EAAA,IAAOK,KAAP;EAAA,IAAcC,KAAd;EAAA,IAAqBC,KAArB;EAAA,IAA4BC,KAA5B;EAAA,IAAmCC,KAAnC;;EAEA,IAAIb,KAAJ;EACA,IAAIC,MAAJ;EACA,IAAIC,OAAJ;EACA,IAAIC,QAAJ,CAND,CAQC;EAEA;EACA;;EACA,IAAI,OAAOM,KAAP,KAAiB,QAArB,EACA;IACC;IACA;IACA,IA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EAANA,MAFM;IAGNC,OAAO,EAAPA,OAHM;IAINC,QAAQ,EAARA;EAJM,CAAP;AAMA"}
@@ -1,5 +1,3 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
-
3
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
2
 
5
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -14,6 +12,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
12
 
15
13
  import isViablePhoneNumber from '../helpers/isViablePhoneNumber.js';
16
14
  import _getNumberType from '../helpers/getNumberType.js';
15
+ import isObject from '../helpers/isObject.js';
17
16
  import parse from '../parse.js'; // Finds out national phone number type (fixed line, mobile, etc)
18
17
 
19
18
  export default function getNumberType() {
@@ -47,7 +46,7 @@ export function normalizeArguments(args) {
47
46
  // If "default country" argument is being passed
48
47
  // then convert it to an `options` object.
49
48
  // `getNumberType('88005553535', 'RU', metadata)`.
50
- if (_typeof(arg_2) !== 'object') {
49
+ if (!isObject(arg_2)) {
51
50
  if (arg_4) {
52
51
  options = arg_3;
53
52
  metadata = arg_4;
@@ -91,7 +90,7 @@ export function normalizeArguments(args) {
91
90
  }
92
91
  } // If the phone number is passed as a parsed phone number.
93
92
  // `getNumberType({ phone: '88005553535', country: 'RU' }, ...)`.
94
- else if (is_object(arg_1)) {
93
+ else if (isObject(arg_1)) {
95
94
  input = arg_1;
96
95
 
97
96
  if (arg_3) {
@@ -107,12 +106,5 @@ export function normalizeArguments(args) {
107
106
  options: options,
108
107
  metadata: metadata
109
108
  };
110
- } // Babel transforms `typeof` into some "branches"
111
- // so istanbul will show this as "branch not covered".
112
-
113
- /* istanbul ignore next */
114
-
115
- var is_object = function is_object(_) {
116
- return _typeof(_) === 'object';
117
- };
109
+ }
118
110
  //# sourceMappingURL=getNumberType.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getNumberType.js","names":["isViablePhoneNumber","_getNumberType","parse","getNumberType","normalizeArguments","arguments","input","options","metadata","phone","args","Array","prototype","slice","call","arg_1","arg_2","arg_3","arg_4","defaultCountry","undefined","is_object","TypeError","_"],"sources":["../../source/legacy/getNumberType.js"],"sourcesContent":["import isViablePhoneNumber from '../helpers/isViablePhoneNumber.js'\r\nimport _getNumberType from '../helpers/getNumberType.js'\r\nimport parse from '../parse.js'\r\n\r\n// Finds out national phone number type (fixed line, mobile, etc)\r\nexport default function getNumberType() {\r\n\tconst { input, options, metadata } = normalizeArguments(arguments)\r\n\t// `parseNumber()` would return `{}` when no phone number could be parsed from the input.\r\n\tif (!input.phone) {\r\n\t\treturn\r\n\t}\r\n\treturn _getNumberType(input, options, metadata)\r\n}\r\n\r\n// Sort out arguments\r\nexport function normalizeArguments(args)\r\n{\r\n\tconst [arg_1, arg_2, arg_3, arg_4] = Array.prototype.slice.call(args)\r\n\r\n\tlet input\r\n\tlet options = {}\r\n\tlet metadata\r\n\r\n\t// If the phone number is passed as a string.\r\n\t// `getNumberType('88005553535', ...)`.\r\n\tif (typeof arg_1 === 'string')\r\n\t{\r\n\t\t// If \"default country\" argument is being passed\r\n\t\t// then convert it to an `options` object.\r\n\t\t// `getNumberType('88005553535', 'RU', metadata)`.\r\n\t\tif (typeof arg_2 !== 'object')\r\n\t\t{\r\n\t\t\tif (arg_4)\r\n\t\t\t{\r\n\t\t\t\toptions = arg_3\r\n\t\t\t\tmetadata = arg_4\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tmetadata = arg_3\r\n\t\t\t}\r\n\r\n\t\t\t// `parse` extracts phone numbers from raw text,\r\n\t\t\t// therefore it will cut off all \"garbage\" characters,\r\n\t\t\t// while this `validate` function needs to verify\r\n\t\t\t// that the phone number contains no \"garbage\"\r\n\t\t\t// therefore the explicit `isViablePhoneNumber` check.\r\n\t\t\tif (isViablePhoneNumber(arg_1))\r\n\t\t\t{\r\n\t\t\t\tinput = parse(arg_1, { defaultCountry: arg_2 }, metadata)\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tinput = {}\r\n\t\t\t}\r\n\t\t}\r\n\t\t// No \"resrict country\" argument is being passed.\r\n\t\t// International phone number is passed.\r\n\t\t// `getNumberType('+78005553535', metadata)`.\r\n\t\telse\r\n\t\t{\r\n\t\t\tif (arg_3)\r\n\t\t\t{\r\n\t\t\t\toptions = arg_2\r\n\t\t\t\tmetadata = arg_3\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tmetadata = arg_2\r\n\t\t\t}\r\n\r\n\t\t\t// `parse` extracts phone numbers from raw text,\r\n\t\t\t// therefore it will cut off all \"garbage\" characters,\r\n\t\t\t// while this `validate` function needs to verify\r\n\t\t\t// that the phone number contains no \"garbage\"\r\n\t\t\t// therefore the explicit `isViablePhoneNumber` check.\r\n\t\t\tif (isViablePhoneNumber(arg_1))\r\n\t\t\t{\r\n\t\t\t\tinput = parse(arg_1, undefined, metadata)\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tinput = {}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t// If the phone number is passed as a parsed phone number.\r\n\t// `getNumberType({ phone: '88005553535', country: 'RU' }, ...)`.\r\n\telse if (is_object(arg_1))\r\n\t{\r\n\t\tinput = arg_1\r\n\r\n\t\tif (arg_3)\r\n\t\t{\r\n\t\t\toptions = arg_2\r\n\t\t\tmetadata = arg_3\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tmetadata = arg_2\r\n\t\t}\r\n\t}\r\n\telse throw new TypeError('A phone number must either be a string or an object of shape { phone, [country] }.')\r\n\r\n\treturn {\r\n\t\tinput,\r\n\t\toptions,\r\n\t\tmetadata\r\n\t}\r\n}\r\n\r\n// Babel transforms `typeof` into some \"branches\"\r\n// so istanbul will show this as \"branch not covered\".\r\n/* istanbul ignore next */\r\nconst is_object = _ => typeof _ === 'object'"],"mappings":";;;;;;;;;;;;;;AAAA,OAAOA,mBAAP,MAAgC,mCAAhC;AACA,OAAOC,cAAP,MAA2B,6BAA3B;AACA,OAAOC,KAAP,MAAkB,aAAlB,C,CAEA;;AACA,eAAe,SAASC,aAAT,GAAyB;EACvC,0BAAqCC,kBAAkB,CAACC,SAAD,CAAvD;EAAA,IAAQC,KAAR,uBAAQA,KAAR;EAAA,IAAeC,OAAf,uBAAeA,OAAf;EAAA,IAAwBC,QAAxB,uBAAwBA,QAAxB,CADuC,CAEvC;;;EACA,IAAI,CAACF,KAAK,CAACG,KAAX,EAAkB;IACjB;EACA;;EACD,OAAOR,cAAc,CAACK,KAAD,EAAQC,OAAR,EAAiBC,QAAjB,CAArB;AACA,C,CAED;;AACA,OAAO,SAASJ,kBAAT,CAA4BM,IAA5B,EACP;EACC,4BAAqCC,KAAK,CAACC,SAAN,CAAgBC,KAAhB,CAAsBC,IAAtB,CAA2BJ,IAA3B,CAArC;EAAA;EAAA,IAAOK,KAAP;EAAA,IAAcC,KAAd;EAAA,IAAqBC,KAArB;EAAA,IAA4BC,KAA5B;;EAEA,IAAIZ,KAAJ;EACA,IAAIC,OAAO,GAAG,EAAd;EACA,IAAIC,QAAJ,CALD,CAOC;EACA;;EACA,IAAI,OAAOO,KAAP,KAAiB,QAArB,EACA;IACC;IACA;IACA;IACA,IAAI,QAAOC,KAAP,MAAiB,QAArB,EACA;MACC,IAAIE,KAAJ,EACA;QACCX,OAAO,GAAGU,KAAV;QACAT,QAAQ,GAAGU,KAAX;MACA,CAJD,MAMA;QACCV,QAAQ,GAAGS,KAAX;MACA,CATF,CAWC;MACA;MACA;MACA;MACA;;;MACA,IAAIjB,mBAAmB,CAACe,KAAD,CAAvB,EACA;QACCT,KAAK,GAAGJ,KAAK,CAACa,KAAD,EAAQ;UAAEI,cAAc,EAAEH;QAAlB,CAAR,EAAmCR,QAAnC,CAAb;MACA,CAHD,MAKA;QACCF,KAAK,GAAG,EAAR;MACA;IACD,CAzBD,CA0BA;IACA;IACA;IA5BA,KA8BA;MACC,IAAIW,KAAJ,EACA;QACCV,OAAO,GAAGS,KAAV;QACAR,QAAQ,GAAGS,KAAX;MACA,CAJD,MAMA;QACCT,QAAQ,GAAGQ,KAAX;MACA,CATF,CAWC;MACA;MACA;MACA;MACA;;;MACA,IAAIhB,mBAAmB,CAACe,KAAD,CAAvB,EACA;QACCT,KAAK,GAAGJ,KAAK,CAACa,KAAD,EAAQK,SAAR,EAAmBZ,QAAnB,CAAb;MACA,CAHD,MAKA;QACCF,KAAK,GAAG,EAAR;MACA;IACD;EACD,CA5DD,CA6DA;EACA;EA9DA,KA+DK,IAAIe,SAAS,CAACN,KAAD,CAAb,EACL;IACCT,KAAK,GAAGS,KAAR;;IAEA,IAAIE,KAAJ,EACA;MACCV,OAAO,GAAGS,KAAV;MACAR,QAAQ,GAAGS,KAAX;IACA,CAJD,MAMA;MACCT,QAAQ,GAAGQ,KAAX;IACA;EACD,CAbI,MAcA,MAAM,IAAIM,SAAJ,CAAc,oFAAd,CAAN;;EAEL,OAAO;IACNhB,KAAK,EAALA,KADM;IAENC,OAAO,EAAPA,OAFM;IAGNC,QAAQ,EAARA;EAHM,CAAP;AAKA,C,CAED;AACA;;AACA;;AACA,IAAMa,SAAS,GAAG,SAAZA,SAAY,CAAAE,CAAC;EAAA,OAAI,QAAOA,CAAP,MAAa,QAAjB;AAAA,CAAnB"}
1
+ {"version":3,"file":"getNumberType.js","names":["isViablePhoneNumber","_getNumberType","isObject","parse","getNumberType","normalizeArguments","arguments","input","options","metadata","phone","args","Array","prototype","slice","call","arg_1","arg_2","arg_3","arg_4","defaultCountry","undefined","TypeError"],"sources":["../../source/legacy/getNumberType.js"],"sourcesContent":["import isViablePhoneNumber from '../helpers/isViablePhoneNumber.js'\r\nimport _getNumberType from '../helpers/getNumberType.js'\r\nimport isObject from '../helpers/isObject.js'\r\nimport parse from '../parse.js'\r\n\r\n// Finds out national phone number type (fixed line, mobile, etc)\r\nexport default function getNumberType() {\r\n\tconst { input, options, metadata } = normalizeArguments(arguments)\r\n\t// `parseNumber()` would return `{}` when no phone number could be parsed from the input.\r\n\tif (!input.phone) {\r\n\t\treturn\r\n\t}\r\n\treturn _getNumberType(input, options, metadata)\r\n}\r\n\r\n// Sort out arguments\r\nexport function normalizeArguments(args)\r\n{\r\n\tconst [arg_1, arg_2, arg_3, arg_4] = Array.prototype.slice.call(args)\r\n\r\n\tlet input\r\n\tlet options = {}\r\n\tlet metadata\r\n\r\n\t// If the phone number is passed as a string.\r\n\t// `getNumberType('88005553535', ...)`.\r\n\tif (typeof arg_1 === 'string')\r\n\t{\r\n\t\t// If \"default country\" argument is being passed\r\n\t\t// then convert it to an `options` object.\r\n\t\t// `getNumberType('88005553535', 'RU', metadata)`.\r\n\t\tif (!isObject(arg_2))\r\n\t\t{\r\n\t\t\tif (arg_4)\r\n\t\t\t{\r\n\t\t\t\toptions = arg_3\r\n\t\t\t\tmetadata = arg_4\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tmetadata = arg_3\r\n\t\t\t}\r\n\r\n\t\t\t// `parse` extracts phone numbers from raw text,\r\n\t\t\t// therefore it will cut off all \"garbage\" characters,\r\n\t\t\t// while this `validate` function needs to verify\r\n\t\t\t// that the phone number contains no \"garbage\"\r\n\t\t\t// therefore the explicit `isViablePhoneNumber` check.\r\n\t\t\tif (isViablePhoneNumber(arg_1))\r\n\t\t\t{\r\n\t\t\t\tinput = parse(arg_1, { defaultCountry: arg_2 }, metadata)\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tinput = {}\r\n\t\t\t}\r\n\t\t}\r\n\t\t// No \"resrict country\" argument is being passed.\r\n\t\t// International phone number is passed.\r\n\t\t// `getNumberType('+78005553535', metadata)`.\r\n\t\telse\r\n\t\t{\r\n\t\t\tif (arg_3)\r\n\t\t\t{\r\n\t\t\t\toptions = arg_2\r\n\t\t\t\tmetadata = arg_3\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tmetadata = arg_2\r\n\t\t\t}\r\n\r\n\t\t\t// `parse` extracts phone numbers from raw text,\r\n\t\t\t// therefore it will cut off all \"garbage\" characters,\r\n\t\t\t// while this `validate` function needs to verify\r\n\t\t\t// that the phone number contains no \"garbage\"\r\n\t\t\t// therefore the explicit `isViablePhoneNumber` check.\r\n\t\t\tif (isViablePhoneNumber(arg_1))\r\n\t\t\t{\r\n\t\t\t\tinput = parse(arg_1, undefined, metadata)\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tinput = {}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t// If the phone number is passed as a parsed phone number.\r\n\t// `getNumberType({ phone: '88005553535', country: 'RU' }, ...)`.\r\n\telse if (isObject(arg_1))\r\n\t{\r\n\t\tinput = arg_1\r\n\r\n\t\tif (arg_3)\r\n\t\t{\r\n\t\t\toptions = arg_2\r\n\t\t\tmetadata = arg_3\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tmetadata = arg_2\r\n\t\t}\r\n\t}\r\n\telse throw new TypeError('A phone number must either be a string or an object of shape { phone, [country] }.')\r\n\r\n\treturn {\r\n\t\tinput,\r\n\t\toptions,\r\n\t\tmetadata\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,mBAAP,MAAgC,mCAAhC;AACA,OAAOC,cAAP,MAA2B,6BAA3B;AACA,OAAOC,QAAP,MAAqB,wBAArB;AACA,OAAOC,KAAP,MAAkB,aAAlB,C,CAEA;;AACA,eAAe,SAASC,aAAT,GAAyB;EACvC,0BAAqCC,kBAAkB,CAACC,SAAD,CAAvD;EA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mB,CAACgB,KAAD,CAAvB,EACA;QACCT,KAAK,GAAGJ,KAAK,CAACa,KAAD,EAAQK,SAAR,EAAmBZ,QAAnB,CAAb;MACA,CAHD,MAKA;QACCF,KAAK,GAAG,EAAR;MACA;IACD;EACD,CA5DD,CA6DA;EACA;EA9DA,KA+DK,IAAIL,QAAQ,CAACc,KAAD,CAAZ,EACL;IACCT,KAAK,GAAGS,KAAR;;IAEA,IAAIE,KAAJ,EACA;MACCV,OAAO,GAAGS,KAAV;MACAR,QAAQ,GAAGS,KAAX;IACA,CAJD,MAMA;MACCT,QAAQ,GAAGQ,KAAX;IACA;EACD,CAbI,MAcA,MAAM,IAAIK,SAAJ,CAAc,oFAAd,CAAN;;EAEL,OAAO;IACNf,KAAK,EAALA,KADM;IAENC,OAAO,EAAPA,OAFM;IAGNC,QAAQ,EAARA;EAHM,CAAP;AAKA"}
package/es6/metadata.js CHANGED
@@ -6,7 +6,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
6
6
 
7
7
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
8
 
9
- import compare from './tools/semver-compare.js'; // Added "possibleLengths" and renamed
9
+ import compare from './tools/semver-compare.js';
10
+ import isObject from './helpers/isObject.js'; // Added "possibleLengths" and renamed
10
11
  // "country_phone_code_to_countries" to "country_calling_codes".
11
12
 
12
13
  var V2 = '1.0.18'; // Added "idd_prefix" and "default_idd_prefix".
@@ -571,23 +572,15 @@ export function validateMetadata(metadata) {
571
572
  // `country_calling_codes` in `1.0.18`.
572
573
 
573
574
 
574
- if (!is_object(metadata) || !is_object(metadata.countries)) {
575
- throw new Error("[libphonenumber-js] `metadata` argument was passed but it's not a valid metadata. Must be an object having `.countries` child object property. Got ".concat(is_object(metadata) ? 'an object of shape: { ' + Object.keys(metadata).join(', ') + ' }' : 'a ' + type_of(metadata) + ': ' + metadata, "."));
575
+ if (!isObject(metadata) || !isObject(metadata.countries)) {
576
+ throw new Error("[libphonenumber-js] `metadata` argument was passed but it's not a valid metadata. Must be an object having `.countries` child object property. Got ".concat(isObject(metadata) ? 'an object of shape: { ' + Object.keys(metadata).join(', ') + ' }' : 'a ' + typeOf(metadata) + ': ' + metadata, "."));
576
577
  }
577
578
  } // Babel transforms `typeof` into some "branches"
578
579
  // so istanbul will show this as "branch not covered".
579
580
 
580
581
  /* istanbul ignore next */
581
582
 
582
- var is_object = function is_object(_) {
583
- return _typeof(_) === 'object';
584
- }; // Babel transforms `typeof` into some "branches"
585
- // so istanbul will show this as "branch not covered".
586
-
587
- /* istanbul ignore next */
588
-
589
-
590
- var type_of = function type_of(_) {
583
+ var typeOf = function typeOf(_) {
591
584
  return _typeof(_);
592
585
  };
593
586
  /**