libphonenumber-js 1.13.14 → 1.13.16

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 (40) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/build/AsYouType.test.js.map +1 -1
  3. package/build/AsYouTypeFormatter.js.map +1 -1
  4. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +1 -0
  5. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  6. package/bundle/libphonenumber-js.min.js +1 -1
  7. package/bundle/libphonenumber-js.min.js.map +1 -1
  8. package/bundle/libphonenumber-max.js +1 -1
  9. package/bundle/libphonenumber-max.js.map +1 -1
  10. package/bundle/libphonenumber-min.js +1 -1
  11. package/bundle/libphonenumber-min.js.map +1 -1
  12. package/bundle/libphonenumber-mobile.js +1 -1
  13. package/bundle/libphonenumber-mobile.js.map +1 -1
  14. package/es6/AsYouType.test.js.map +1 -1
  15. package/es6/AsYouTypeFormatter.js +1 -1
  16. package/es6/AsYouTypeFormatter.js.map +1 -1
  17. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +1 -0
  18. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  19. package/es6-modern/AsYouType.test.js.map +1 -1
  20. package/es6-modern/AsYouTypeFormatter.js +1 -1
  21. package/es6-modern/AsYouTypeFormatter.js.map +1 -1
  22. package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +1 -0
  23. package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  24. package/max/metadata/metadata.max.json +1 -1
  25. package/max/metadata/metadata.max.json.js +1 -1
  26. package/metadata.full.json +1 -1
  27. package/metadata.full.json.js +1 -1
  28. package/metadata.max.json +1 -1
  29. package/metadata.max.json.js +1 -1
  30. package/metadata.min.json +1 -1
  31. package/metadata.min.json.js +1 -1
  32. package/metadata.mobile.json +1 -1
  33. package/metadata.mobile.json.js +1 -1
  34. package/min/metadata/metadata.min.json +1 -1
  35. package/min/metadata/metadata.min.json.js +1 -1
  36. package/mobile/metadata/metadata.mobile.json +1 -1
  37. package/mobile/metadata/metadata.mobile.json.js +1 -1
  38. package/package.json +2 -2
  39. package/source/AsYouTypeFormatter.js +0 -3
  40. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +1 -0
@@ -7,7 +7,7 @@ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o =
7
7
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
8
8
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
9
9
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10
- import { DIGIT_PLACEHOLDER, countOccurences, repeat, cutAndStripNonPairedParens, closeNonPairedParens, stripNonPairedParens, populateTemplateWithDigits } from './AsYouTypeFormatter.util.js';
10
+ import { DIGIT_PLACEHOLDER, repeat, cutAndStripNonPairedParens, populateTemplateWithDigits } from './AsYouTypeFormatter.util.js';
11
11
  import formatCompleteNumber, { canFormatCompleteNumber } from './AsYouTypeFormatter.complete.js';
12
12
  import PatternMatcher from './AsYouTypeFormatter.PatternMatcher.js';
13
13
  import parseDigits from './helpers/parseDigits.js';
@@ -1 +1 @@
1
- {"version":3,"file":"AsYouTypeFormatter.js","names":["DIGIT_PLACEHOLDER","countOccurences","repeat","cutAndStripNonPairedParens","closeNonPairedParens","stripNonPairedParens","populateTemplateWithDigits","formatCompleteNumber","canFormatCompleteNumber","PatternMatcher","parseDigits","FIRST_GROUP_PATTERN","VALID_PUNCTUATION","applyInternationalSeparatorStyle","DUMMY_DIGIT","LONGEST_NATIONAL_PHONE_NUMBER_LENGTH","LONGEST_DUMMY_PHONE_NUMBER","NATIONAL_PREFIX_SEPARATORS_PATTERN","SUPPORT_LEGACY_FORMATTING_PATTERNS","CREATE_CHARACTER_CLASS_PATTERN","CREATE_STANDALONE_DIGIT_PATTERN","NON_ALTERING_FORMAT_REG_EXP","RegExp","MIN_LEADING_DIGITS_LENGTH","AsYouTypeFormatter","_ref","state","metadata","_classCallCheck","resetFormat","_createClass","key","value","chosenFormat","undefined","template","nationalNumberTemplate","populatedNationalNumberTemplate","populatedNationalNumberTemplatePosition","reset","numberingPlan","isNANP","callingCode","matchingFormats","formats","nationalSignificantNumber","narrowDownMatchingFormats","format","nextDigits","_this","_iterator","_createForOfIteratorHelperLoose","_step","done","formattedCompleteNumber","shouldTryNationalPrefixFormattingRule","international","nationalPrefix","getSeparatorAfterNationalPrefix","setNationalNumberTemplate","replace","lastIndexOf","formatNationalNumberWithNextDigits","previouslyChosenFormat","newlyChosenFormat","chooseFormat","formatNextNationalNumberDigits","getNationalDigits","_ref2","_this2","leadingDigits","leadingDigitsPatternIndex","length","filter","formatSuits","formatMatches","indexOf","usesNationalPrefix","nationalPrefixIsOptionalWhenFormattingInNationalFormat","nationalPrefixIsMandatoryWhenFormattingInNationalFormat","leadingDigitsPatternsCount","leadingDigitsPatterns","Math","min","leadingDigitsPattern","match","allowOverflow","error","console","concat","test","getFormatFormat","internationalFormat","_this3","_loop","_step2","createTemplateForFormat","_","_ret","_iterator2","slice","pattern","getTemplateForFormat","nationalPrefixFormattingRule","getInternationalPrefixBeforeCountryCallingCode","_ref3","options","IDDPrefix","missingPlus","spacing","getTemplate","index","i","internationalPrefix","getDigitsWithoutInternationalPrefix","_ref4","prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix","digits","strictPattern","nationalNumberDummyDigits","numberFormat","nationalPrefixIncludedInTemplate","numberFormatWithNationalPrefix","result","_ref5","default"],"sources":["../source/AsYouTypeFormatter.js"],"sourcesContent":["import {\n\tDIGIT_PLACEHOLDER,\n\tcountOccurences,\n\trepeat,\n\tcutAndStripNonPairedParens,\n\tcloseNonPairedParens,\n\tstripNonPairedParens,\n\tpopulateTemplateWithDigits\n} from './AsYouTypeFormatter.util.js'\n\nimport formatCompleteNumber, {\n\tcanFormatCompleteNumber\n} from './AsYouTypeFormatter.complete.js'\n\nimport PatternMatcher from './AsYouTypeFormatter.PatternMatcher.js'\n\nimport parseDigits from './helpers/parseDigits.js'\nexport { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util.js'\nimport { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat.js'\nimport { VALID_PUNCTUATION } from './constants.js'\nimport applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle.js'\n\n// Used in phone number format template creation.\n// Could be any digit, I guess.\nconst DUMMY_DIGIT = '9'\n// I don't know why is it exactly `15`\nconst LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15\n// Create a phone number consisting only of the digit 9 that matches the\n// `number_pattern` by applying the pattern to the \"longest phone number\" string.\nconst LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH)\n\n// A set of characters that, if found in a national prefix formatting rules, are an indicator to\n// us that we should separate the national prefix from the number when formatting.\nconst NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/\n\n// Deprecated: Google has removed some formatting pattern related code from their repo.\n// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c\n// \"We no longer have numbers in formatting matching patterns, only \\d.\"\n// Because this library supports generating custom metadata\n// some users may still be using old metadata so the relevant\n// code seems to stay until some next major version update.\nconst SUPPORT_LEGACY_FORMATTING_PATTERNS = true\n\n// A pattern that is used to match character classes in regular expressions.\n// An example of a character class is \"[1-4]\".\nconst CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\[([^\\[\\]])*\\]/g)\n\n// Any digit in a regular expression that actually denotes a digit. For\n// example, in the regular expression \"80[0-2]\\d{6,10}\", the first 2 digits\n// (8 and 0) are standalone digits, but the rest are not.\n// Two look-aheads are needed because the number following \\\\d could be a\n// two-digit number, since the phone number can be as long as 15 digits.\nconst CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\d(?=[^,}][^,}])/g)\n\n// A regular expression that is used to determine if a `format` is\n// suitable to be used in the \"as you type formatter\".\n// A `format` is suitable when the resulting formatted number has\n// the same digits as the user has entered.\n//\n// In the simplest case, that would mean that the format\n// doesn't add any additional digits when formatting a number.\n// Google says that it also shouldn't add \"star\" (`*`) characters,\n// like it does in some Israeli formats.\n// Such basic format would only contain \"valid punctuation\"\n// and \"captured group\" identifiers ($1, $2, etc).\n//\n// An example of a format that adds additional digits:\n//\n// Country: `AR` (Argentina).\n// Format:\n// {\n// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\n// \"leading_digits_patterns\": [\"91\"],\n// \"national_prefix_formatting_rule\": \"0$1\",\n// \"format\": \"$2 15-$3-$4\",\n// \"international_format\": \"$1 $2 $3-$4\"\n// }\n//\n// In the format above, the `format` adds `15` to the digits when formatting a number.\n// A sidenote: this format actually is suitable because `national_prefix_for_parsing`\n// has previously removed `15` from a national number, so re-adding `15` in `format`\n// doesn't actually result in any extra digits added to user's input.\n// But verifying that would be a complex procedure, so the code chooses a simpler path:\n// it simply filters out all `format`s that contain anything but \"captured group\" ids.\n//\n// This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's\n// `libphonenumber` code.\n//\nconst NON_ALTERING_FORMAT_REG_EXP = new RegExp(\n\t'[' + VALID_PUNCTUATION + ']*' +\n\t// Google developers say:\n\t// \"We require that the first matching group is present in the\n\t// output pattern to ensure no data is lost while formatting.\"\n\t'\\\\$1' +\n\t'[' + VALID_PUNCTUATION + ']*' +\n\t'(\\\\$\\\\d[' + VALID_PUNCTUATION + ']*)*' +\n\t'$'\n)\n\n// This is the minimum length of the leading digits of a phone number\n// to guarantee the first \"leading digits pattern\" for a phone number format\n// to be preemptive.\nconst MIN_LEADING_DIGITS_LENGTH = 3\n\nexport default class AsYouTypeFormatter {\n\tconstructor({\n\t\tstate,\n\t\tmetadata\n\t}) {\n\t\tthis.metadata = metadata\n\t\tthis.resetFormat()\n\t}\n\n\tresetFormat() {\n\t\tthis.chosenFormat = undefined\n\t\tthis.template = undefined\n\t\tthis.nationalNumberTemplate = undefined\n\t\tthis.populatedNationalNumberTemplate = undefined\n\t\tthis.populatedNationalNumberTemplatePosition = -1\n\t}\n\n\treset(numberingPlan, state) {\n\t\tthis.resetFormat()\n\t\tif (numberingPlan) {\n\t\t\tthis.isNANP = numberingPlan.callingCode() === '1'\n\t\t\tthis.matchingFormats = numberingPlan.formats()\n\t\t\tif (state.nationalSignificantNumber) {\n\t\t\t\tthis.narrowDownMatchingFormats(state)\n\t\t\t}\n\t\t} else {\n\t\t\tthis.isNANP = undefined\n\t\t\tthis.matchingFormats = []\n\t\t}\n\t}\n\n\t/**\n\t * Formats an updated phone number.\n\t * @param {string} nextDigits — Additional phone number digits.\n\t * @param {object} state — `AsYouType` state.\n\t * @return {[string]} Returns undefined if the updated phone number can't be formatted using any of the available formats.\n\t */\n\tformat(nextDigits, state) {\n\t\t// See if the phone number digits can be formatted as a complete phone number.\n\t\t// If not, use the results from `formatNationalNumberWithNextDigits()`,\n\t\t// which formats based on the chosen formatting pattern.\n\t\t//\n\t\t// Attempting to format complete phone number first is how it's done\n\t\t// in Google's `libphonenumber`, so this library just follows it.\n\t\t// Google's `libphonenumber` code doesn't explain in detail why does it\n\t\t// attempt to format digits as a complete phone number\n\t\t// instead of just going with a previoulsy (or newly) chosen `format`:\n\t\t//\n\t\t// \"Checks to see if there is an exact pattern match for these digits.\n\t\t// If so, we should use this instead of any other formatting template\n\t\t// whose leadingDigitsPattern also matches the input.\"\n\t\t//\n\t\tif (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {\n\t\t\tfor (const format of this.matchingFormats) {\n\t\t\t\tconst formattedCompleteNumber = formatCompleteNumber(\n\t\t\t\t\tstate,\n\t\t\t\t\tformat,\n\t\t\t\t\t{\n\t\t\t\t\t\tmetadata: this.metadata,\n\t\t\t\t\t\tshouldTryNationalPrefixFormattingRule: (format) => this.shouldTryNationalPrefixFormattingRule(format, {\n\t\t\t\t\t\t\tinternational: state.international,\n\t\t\t\t\t\t\tnationalPrefix: state.nationalPrefix\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tgetSeparatorAfterNationalPrefix: (format) => this.getSeparatorAfterNationalPrefix(format)\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t\tif (formattedCompleteNumber) {\n\t\t\t\t\tthis.resetFormat()\n\t\t\t\t\tthis.chosenFormat = format\n\t\t\t\t\tthis.setNationalNumberTemplate(formattedCompleteNumber.replace(/\\d/g, DIGIT_PLACEHOLDER), state)\n\t\t\t\t\tthis.populatedNationalNumberTemplate = formattedCompleteNumber\n\t\t\t\t\t// With a new formatting template, the matched position\n\t\t\t\t\t// using the old template needs to be reset.\n\t\t\t\t\tthis.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(DIGIT_PLACEHOLDER)\n\t\t\t\t\treturn formattedCompleteNumber\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\t// Format the digits as a partial (incomplete) phone number\n\t\t// using the previously chosen formatting pattern (or a newly chosen one).\n\t\treturn this.formatNationalNumberWithNextDigits(nextDigits, state)\n\t}\n\n\t// Formats the next phone number digits.\n\tformatNationalNumberWithNextDigits(nextDigits, state) {\n\t\tconst previouslyChosenFormat = this.chosenFormat\n\n\t\t// Choose a format from the list of matching ones.\n\t\tconst newlyChosenFormat = this.chooseFormat(state)\n\n\t\tif (newlyChosenFormat) {\n\t\t\tif (newlyChosenFormat === previouslyChosenFormat) {\n\t\t\t\t// If it can format the next (current) digits\n\t\t\t\t// using the previously chosen phone number format\n\t\t\t\t// then return the updated formatted number.\n\t\t\t\treturn this.formatNextNationalNumberDigits(nextDigits)\n\t\t\t} else {\n\t\t\t\t// If a more appropriate phone number format\n\t\t\t\t// has been chosen for these \"leading digits\",\n\t\t\t\t// then re-format the national phone number part\n\t\t\t\t// using the newly selected format.\n\t\t\t\treturn this.formatNextNationalNumberDigits(state.getNationalDigits())\n\t\t\t}\n\t\t}\n\t}\n\n\tnarrowDownMatchingFormats({\n\t\tnationalSignificantNumber,\n\t\tnationalPrefix,\n\t\tinternational\n\t}) {\n\t\tconst leadingDigits = nationalSignificantNumber\n\n\t\t// \"leading digits\" pattern list starts with a\n\t\t// \"leading digits\" pattern fitting a maximum of 3 leading digits.\n\t\t// So, after a user inputs 3 digits of a national (significant) phone number\n\t\t// this national (significant) number can already be formatted.\n\t\t// The next \"leading digits\" pattern is for 4 leading digits max,\n\t\t// and the \"leading digits\" pattern after it is for 5 leading digits max, etc.\n\n\t\t// This implementation is different from Google's\n\t\t// in that it searches for a fitting format\n\t\t// even if the user has entered less than\n\t\t// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.\n\t\t// Because some leading digit patterns already match for a single first digit.\n\t\tlet leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH\n\t\tif (leadingDigitsPatternIndex < 0) {\n\t\t\tleadingDigitsPatternIndex = 0\n\t\t}\n\n\t\tthis.matchingFormats = this.matchingFormats.filter(\n\t\t\tformat => this.formatSuits(format, international, nationalPrefix)\n\t\t\t\t&& this.formatMatches(format, leadingDigits, leadingDigitsPatternIndex)\n\t\t)\n\n\t\t// If there was a phone number format chosen\n\t\t// and it no longer holds given the new leading digits then reset it.\n\t\t// The test for this `if` condition is marked as:\n\t\t// \"Reset a chosen format when it no longer holds given the new leading digits\".\n\t\t// To construct a valid test case for this one can find a country\n\t\t// in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`\n\t\t// and yielding another format for 4 `<leadingDigits>` (Australia in this case).\n\t\tif (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {\n\t\t\tthis.resetFormat()\n\t\t}\n\t}\n\n\tformatSuits(format, international, nationalPrefix) {\n\t\t// When a prefix before a national (significant) number is\n\t\t// simply a national prefix, then it's parsed as `this.nationalPrefix`.\n\t\t// In more complex cases, a prefix before national (significant) number\n\t\t// could include a national prefix as well as some \"capturing groups\",\n\t\t// and in that case there's no info whether a national prefix has been parsed.\n\t\t// If national prefix is not used when formatting a phone number\n\t\t// using this format, but a national prefix has been entered by the user,\n\t\t// and was extracted, then discard such phone number format.\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184\n\t\tif (nationalPrefix &&\n\t\t\t!format.usesNationalPrefix() &&\n\t\t\t// !format.domesticCarrierCodeFormattingRule() &&\n\t\t\t!format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {\n\t\t\treturn false\n\t\t}\n\t\t// If national prefix is mandatory for this phone number format\n\t\t// and there're no guarantees that a national prefix is present in user input\n\t\t// then discard this phone number format as not suitable.\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193\n\t\tif (!international &&\n\t\t\t!nationalPrefix &&\n\t\t\tformat.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t}\n\n\tformatMatches(format, leadingDigits, leadingDigitsPatternIndex) {\n\t\tconst leadingDigitsPatternsCount = format.leadingDigitsPatterns().length\n\n\t\t// If this format is not restricted to a certain\n\t\t// leading digits pattern then it fits.\n\t\t// The test case could be found by searching for \"leadingDigitsPatternsCount === 0\".\n\t\tif (leadingDigitsPatternsCount === 0) {\n\t\t\treturn true\n\t\t}\n\n\t\t// Start narrowing down the list of possible formats based on the leading digits.\n\t\t// (only previously matched formats take part in the narrowing down process)\n\n\t\t// `leading_digits_patterns` start with 3 digits min\n\t\t// and then go up from there one digit at a time.\n\t\tleadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1)\n\t\tconst leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]\n\n\t\t// Google imposes a requirement on the leading digits\n\t\t// to be minimum 3 digits long in order to be eligible\n\t\t// for checking those with a leading digits pattern.\n\t\t//\n\t\t// Since `leading_digits_patterns` start with 3 digits min,\n\t\t// Google's original `libphonenumber` library only starts\n\t\t// excluding any non-matching formats only when the\n\t\t// national number entered so far is at least 3 digits long,\n\t\t// otherwise format matching would give false negatives.\n\t\t//\n\t\t// For example, when the digits entered so far are `2`\n\t\t// and the leading digits pattern is `21` –\n\t\t// it's quite obvious in this case that the format could be the one\n\t\t// but due to the absence of further digits it would give false negative.\n\t\t//\n\t\t// Also, `leading_digits_patterns` doesn't always correspond to a single\n\t\t// digits count. For example, `60|8` pattern would already match `8`\n\t\t// but the `60` part would require having at least two leading digits,\n\t\t// so the whole pattern would require inputting two digits first in order to\n\t\t// decide on whether it matches the input, even when the input is \"80\".\n\t\t//\n\t\t// This library — `libphonenumber-js` — allows filtering by `leading_digits_patterns`\n\t\t// even when there's only 1 or 2 digits of the national (significant) number.\n\t\t// To do that, it uses a non-strict pattern matcher written specifically for that.\n\t\t//\n\t\tif (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {\n\t\t\t// Before leading digits < 3 matching was implemented:\n\t\t\t// return true\n\t\t\t//\n\t\t\t// After leading digits < 3 matching was implemented:\n\t\t\ttry {\n\t\t\t\treturn new PatternMatcher(leadingDigitsPattern).match(leadingDigits, { allowOverflow: true }) !== undefined\n\t\t\t} catch (error) /* istanbul ignore next */ {\n\t\t\t\t// There's a slight possibility that there could be some undiscovered bug\n\t\t\t\t// in the pattern matcher code. Since the \"leading digits < 3 matching\"\n\t\t\t\t// feature is not \"essential\" for operation, it can fall back to the old way\n\t\t\t\t// in case of any issues rather than halting the application's execution.\n\t\t\t\tconsole.error(error)\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\n\t\t// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are\n\t\t// available then use the usual regular expression matching.\n\t\t//\n\t\t// The whole pattern is wrapped in round brackets (`()`) because\n\t\t// the pattern can use \"or\" operator (`|`) at the top level of the pattern.\n\t\t//\n\t\treturn new RegExp(`^(${leadingDigitsPattern})`).test(leadingDigits)\n\t}\n\n\tgetFormatFormat(format, international) {\n\t\treturn international ? format.internationalFormat() : format.format()\n\t}\n\n\tchooseFormat(state) {\n\t\t// When there are multiple available formats, the formatter uses the first\n\t\t// format where a formatting template could be created.\n\t\t//\n\t\t// For some weird reason, `istanbul` says \"else path not taken\"\n\t\t// for the `for of` line below. Supposedly that means that\n\t\t// the loop doesn't ever go over the last element in the list.\n\t\t// That's true because there always is `this.chosenFormat`\n\t\t// when `this.matchingFormats` is non-empty.\n\t\t// And, for some weird reason, it doesn't think that the case\n\t\t// with empty `this.matchingFormats` qualifies for a valid \"else\" path.\n\t\t// So simply muting this `istanbul` warning.\n\t\t// It doesn't skip the contents of the `for of` loop,\n\t\t// it just skips the `for of` line.\n\t\t//\n\t\t/* istanbul ignore next */\n\t\tfor (const format of this.matchingFormats.slice()) {\n\t\t\t// If this format is currently being used\n\t\t\t// and is still suitable, then stick to it.\n\t\t\tif (this.chosenFormat === format) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\t// Sometimes, a formatting rule inserts additional digits in a phone number,\n\t\t\t// and \"as you type\" formatter can't do that: it should only use the digits\n\t\t\t// that the user has input.\n\t\t\t//\n\t\t\t// For example, in Argentina, there's a format for mobile phone numbers:\n\t\t\t//\n\t\t\t// {\n\t\t\t// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\n\t\t\t// \"leading_digits_patterns\": [\"91\"],\n\t\t\t// \"national_prefix_formatting_rule\": \"0$1\",\n\t\t\t// \"format\": \"$2 15-$3-$4\",\n\t\t\t// \"international_format\": \"$1 $2 $3-$4\"\n\t\t\t// }\n\t\t\t//\n\t\t\t// In that format, `international_format` is used instead of `format`\n\t\t\t// because `format` inserts `15` in the formatted number,\n\t\t\t// and `AsYouType` formatter should only use the digits\n\t\t\t// the user has actually input, without adding any extra digits.\n\t\t\t// In this case, it wouldn't make a difference, because the `15`\n\t\t\t// is first stripped when applying `national_prefix_for_parsing`\n\t\t\t// and then re-added when using `format`, so in reality it doesn't\n\t\t\t// add any new digits to the number, but to detect that, the code\n\t\t\t// would have to be more complex: it would have to try formatting\n\t\t\t// the digits using the format and then see if any digits have\n\t\t\t// actually been added or removed, and then, every time a new digit\n\t\t\t// is input, it should re-check whether the chosen format doesn't\n\t\t\t// alter the digits.\n\t\t\t//\n\t\t\t// Google's code doesn't go that far, and so does this library:\n\t\t\t// it simply requires that a `format` doesn't add any additonal\n\t\t\t// digits to user's input.\n\t\t\t//\n\t\t\t// Also, people in general should move from inputting phone numbers\n\t\t\t// in national format (possibly with national prefixes)\n\t\t\t// and use international phone number format instead:\n\t\t\t// it's a logical thing in the modern age of mobile phones,\n\t\t\t// globalization and the internet.\n\t\t\t//\n\t\t\t/* istanbul ignore if */\n\t\t\tif (!NON_ALTERING_FORMAT_REG_EXP.test(this.getFormatFormat(format, state.international))) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!this.createTemplateForFormat(format, state)) {\n\t\t\t\t// Remove the format if it can't generate a template.\n\t\t\t\tthis.matchingFormats = this.matchingFormats.filter(_ => _ !== format)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tthis.chosenFormat = format\n\t\t\tbreak\n\t\t}\n\t\tif (!this.chosenFormat) {\n\t\t\t// No format matches the national (significant) phone number.\n\t\t\tthis.resetFormat()\n\t\t}\n\t\treturn this.chosenFormat\n\t}\n\n\tcreateTemplateForFormat(format, state) {\n\t\t// The formatter doesn't format numbers when numberPattern contains '|', e.g.\n\t\t// (20|3)\\d{4}. In those cases we quickly return.\n\t\t// (Though there's no such format in current metadata)\n\t\t/* istanbul ignore if */\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {\n\t\t\treturn\n\t\t}\n\t\t// Get formatting template for this phone number format\n\t\tconst template = this.getTemplateForFormat(format, state)\n\t\t// If the national number entered is too long\n\t\t// for any phone number format, then abort.\n\t\tif (template) {\n\t\t\tthis.setNationalNumberTemplate(template, state)\n\t\t\treturn true\n\t\t}\n\t}\n\n\tgetSeparatorAfterNationalPrefix(format) {\n\t\t// `US` metadata doesn't have a `national_prefix_formatting_rule`,\n\t\t// so the `if` condition below doesn't apply to `US`,\n\t\t// but in reality there shoudl be a separator\n\t\t// between a national prefix and a national (significant) number.\n\t\t// So `US` national prefix separator is a \"special\" \"hardcoded\" case.\n\t\tif (this.isNANP) {\n\t\t\treturn ' '\n\t\t}\n\t\t// If a `format` has a `national_prefix_formatting_rule`\n\t\t// and that rule has a separator after a national prefix,\n\t\t// then it means that there should be a separator\n\t\t// between a national prefix and a national (significant) number.\n\t\tif (format &&\n\t\t\tformat.nationalPrefixFormattingRule() &&\n\t\t\tNATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {\n\t\t\treturn ' '\n\t\t}\n\t\t// At this point, there seems to be no clear evidence that\n\t\t// there should be a separator between a national prefix\n\t\t// and a national (significant) number. So don't insert one.\n\t\treturn ''\n\t}\n\n\tgetInternationalPrefixBeforeCountryCallingCode({ IDDPrefix, missingPlus }, options) {\n\t\tif (IDDPrefix) {\n\t\t\treturn options && options.spacing === false ? IDDPrefix : IDDPrefix + ' '\n\t\t}\n\t\tif (missingPlus) {\n\t\t\treturn ''\n\t\t}\n\t\treturn '+'\n\t}\n\n\tgetTemplate(state) {\n\t\tif (!this.template) {\n\t\t\treturn\n\t\t}\n\t\t// `this.template` holds the template for a \"complete\" phone number.\n\t\t// The currently entered phone number is most likely not \"complete\",\n\t\t// so trim all non-populated digits.\n\t\tlet index = -1\n\t\tlet i = 0\n\t\tconst internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, { spacing: false }) : ''\n\t\twhile (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {\n\t\t\tindex = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)\n\t\t\ti++\n\t\t}\n\t\treturn cutAndStripNonPairedParens(this.template, index + 1)\n\t}\n\n\tsetNationalNumberTemplate(template, state) {\n\t\tthis.nationalNumberTemplate = template\n\t\tthis.populatedNationalNumberTemplate = template\n\t\t// With a new formatting template, the matched position\n\t\t// using the old template needs to be reset.\n\t\tthis.populatedNationalNumberTemplatePosition = -1\n\t\t// For convenience, the public `.template` property\n\t\t// contains the whole international number\n\t\t// if the phone number being input is international:\n\t\t// 'x' for the '+' sign, 'x'es for the country phone code,\n\t\t// a spacebar and then the template for the formatted national number.\n\t\tif (state.international) {\n\t\t\tthis.template =\n\t\t\t\tthis.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER) +\n\t\t\t\trepeat(DIGIT_PLACEHOLDER, state.callingCode.length) +\n\t\t\t\t' ' +\n\t\t\t\ttemplate\n\t\t} else {\n\t\t\tthis.template = template\n\t\t}\n\t}\n\n\t/**\n\t * Generates formatting template for a national phone number,\n\t * optionally containing a national prefix, for a format.\n\t * @param {Format} format\n\t * @param {string} nationalPrefix\n\t * @return {string}\n\t */\n\tgetTemplateForFormat(format, {\n\t\tnationalSignificantNumber,\n\t\tinternational,\n\t\tnationalPrefix,\n\t\tprefixBeforeNationalSignificantNumberThatIsNotNationalPrefix\n\t}) {\n\t\tlet pattern = format.pattern()\n\n\t\t/* istanbul ignore else */\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS) {\n\t\t\tpattern = pattern\n\t\t\t\t// Replace anything in the form of [..] with \\d\n\t\t\t\t.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\\\d')\n\t\t\t\t// Replace any standalone digit (not the one in `{}`) with \\d\n\t\t\t\t.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\\\d')\n\t\t}\n\n\t\t// Generate a dummy national number (consisting of `9`s)\n\t\t// that fits this format's `pattern`.\n\t\t//\n\t\t// This match will always succeed,\n\t\t// because the \"longest dummy phone number\"\n\t\t// has enough length to accomodate any possible\n\t\t// national phone number format pattern.\n\t\t//\n\t\tlet digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]\n\n\t\t// If the national number entered is too long\n\t\t// for any phone number format, then abort.\n\t\tif (nationalSignificantNumber.length > digits.length) {\n\t\t\treturn\n\t\t}\n\n\t\t// Get a formatting template which can be used to efficiently format\n\t\t// a partial number where digits are added one by one.\n\n\t\t// Below `strictPattern` is used for the\n\t\t// regular expression (with `^` and `$`).\n\t\t// This wasn't originally in Google's `libphonenumber`\n\t\t// and I guess they don't really need it\n\t\t// because they're not using \"templates\" to format phone numbers\n\t\t// but I added `strictPattern` after encountering\n\t\t// South Korean phone number formatting bug.\n\t\t//\n\t\t// Non-strict regular expression bug demonstration:\n\t\t//\n\t\t// this.nationalSignificantNumber : `111111111` (9 digits)\n\t\t//\n\t\t// pattern : (\\d{2})(\\d{3,4})(\\d{4})\n\t\t// format : `$1 $2 $3`\n\t\t// digits : `9999999999` (10 digits)\n\t\t//\n\t\t// '9999999999'.replace(new RegExp(/(\\d{2})(\\d{3,4})(\\d{4})/g), '$1 $2 $3') = \"99 9999 9999\"\n\t\t//\n\t\t// template : xx xxxx xxxx\n\t\t//\n\t\t// But the correct template in this case is `xx xxx xxxx`.\n\t\t// The template was generated incorrectly because of the\n\t\t// `{3,4}` variability in the `pattern`.\n\t\t//\n\t\t// The fix is, if `this.nationalSignificantNumber` has already sufficient length\n\t\t// to satisfy the `pattern` completely then `this.nationalSignificantNumber`\n\t\t// is used instead of `digits`.\n\n\t\tconst strictPattern = new RegExp('^' + pattern + '$')\n\t\tconst nationalNumberDummyDigits = nationalSignificantNumber.replace(/\\d/g, DUMMY_DIGIT)\n\n\t\t// If `this.nationalSignificantNumber` has already sufficient length\n\t\t// to satisfy the `pattern` completely then use it\n\t\t// instead of `digits`.\n\t\tif (strictPattern.test(nationalNumberDummyDigits)) {\n\t\t\tdigits = nationalNumberDummyDigits\n\t\t}\n\n\t\tlet numberFormat = this.getFormatFormat(format, international)\n\t\tlet nationalPrefixIncludedInTemplate\n\n\t\t// If a user did input a national prefix (and that's guaranteed),\n\t\t// and if a `format` does have a national prefix formatting rule,\n\t\t// then see if that national prefix formatting rule\n\t\t// prepends exactly the same national prefix the user has input.\n\t\t// If that's the case, then use the `format` with the national prefix formatting rule.\n\t\t// Otherwise, use the `format` without the national prefix formatting rule,\n\t\t// and prepend a national prefix manually to it.\n\t\tif (this.shouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix })) {\n\t\t\tconst numberFormatWithNationalPrefix = numberFormat.replace(\n\t\t\t\tFIRST_GROUP_PATTERN,\n\t\t\t\tformat.nationalPrefixFormattingRule()\n\t\t\t)\n\t\t\t// If `national_prefix_formatting_rule` of a `format` simply prepends\n\t\t\t// national prefix at the start of a national (significant) number,\n\t\t\t// then such formatting can be used with `AsYouType` formatter.\n\t\t\t// There seems to be no `else` case: everywhere in metadata,\n\t\t\t// national prefix formatting rule is national prefix + $1,\n\t\t\t// or `($1)`, in which case such format isn't even considered\n\t\t\t// when the user has input a national prefix.\n\t\t\t/* istanbul ignore else */\n\t\t\tif (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {\n\t\t\t\tnumberFormat = numberFormatWithNationalPrefix\n\t\t\t\tnationalPrefixIncludedInTemplate = true\n\t\t\t\t// Replace all digits of the national prefix in the formatting template\n\t\t\t\t// with `DIGIT_PLACEHOLDER`s.\n\t\t\t\tif (nationalPrefix) {\n\t\t\t\t\tlet i = nationalPrefix.length\n\t\t\t\t\twhile (i > 0) {\n\t\t\t\t\t\tnumberFormat = numberFormat.replace(/\\d/, DIGIT_PLACEHOLDER)\n\t\t\t\t\t\ti--\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Generate formatting template for this phone number format.\n\t\tlet template = digits\n\t\t\t// Format the dummy phone number according to the format.\n\t\t\t.replace(new RegExp(pattern), numberFormat)\n\t\t\t// Replace each dummy digit with a DIGIT_PLACEHOLDER.\n\t\t\t.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)\n\n\t\t// If a prefix of a national (significant) number is not as simple\n\t\t// as just a basic national prefix, then just prepend such prefix\n\t\t// before the national (significant) number, optionally spacing\n\t\t// the two with a whitespace.\n\t\tif (!nationalPrefixIncludedInTemplate) {\n\t\t\tif (prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix) {\n\t\t\t\t// Prepend the prefix to the template manually.\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix.length) +\n\t\t\t\t\t' ' +\n\t\t\t\t\ttemplate\n\t\t\t} else if (nationalPrefix) {\n\t\t\t\t// Prepend national prefix to the template manually.\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +\n\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\n\t\t\t\t\ttemplate\n\t\t\t}\n\t\t}\n\n\t\tif (international) {\n\t\t\ttemplate = applyInternationalSeparatorStyle(template)\n\t\t}\n\n\t\treturn template\n\t}\n\n\tformatNextNationalNumberDigits(digits) {\n\t\tconst result = populateTemplateWithDigits(\n\t\t\tthis.populatedNationalNumberTemplate,\n\t\t\tthis.populatedNationalNumberTemplatePosition,\n\t\t\tdigits\n\t\t)\n\n\t\tif (!result) {\n\t\t\t// Reset the format.\n\t\t\tthis.resetFormat()\n\t\t\treturn\n\t\t}\n\n\t\tthis.populatedNationalNumberTemplate = result[0]\n\t\tthis.populatedNationalNumberTemplatePosition = result[1]\n\n\t\t// Return the formatted phone number so far.\n\t\treturn cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\n\n\t\t// The old way which was good for `input-format` but is not so good\n\t\t// for `react-phone-number-input`'s default input (`InputBasic`).\n\t\t// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\n\t\t// \t.replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')\n\t}\n\n\tshouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix }) {\n\t\tif (format.nationalPrefixFormattingRule()) {\n\t\t\t// In some countries, `national_prefix_formatting_rule` is `($1)`,\n\t\t\t// so it applies even if the user hasn't input a national prefix.\n\t\t\t// `format.usesNationalPrefix()` detects such cases.\n\t\t\tconst usesNationalPrefix = format.usesNationalPrefix()\n\t\t\tif ((usesNationalPrefix && nationalPrefix) ||\n\t\t\t\t(!usesNationalPrefix && !international)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t}\n}"],"mappings":";;;;;;;;;AAAA,SACCA,iBAAiB,EACjBC,eAAe,EACfC,MAAM,EACNC,0BAA0B,EAC1BC,oBAAoB,EACpBC,oBAAoB,EACpBC,0BAA0B,QACpB,8BAA8B;AAErC,OAAOC,oBAAoB,IAC1BC,uBAAuB,QACjB,kCAAkC;AAEzC,OAAOC,cAAc,MAAM,wCAAwC;AAEnE,OAAOC,WAAW,MAAM,0BAA0B;AAClD,SAASV,iBAAiB,QAAQ,8BAA8B;AAChE,SAASW,mBAAmB,QAAQ,8CAA8C;AAClF,SAASC,iBAAiB,QAAQ,gBAAgB;AAClD,OAAOC,gCAAgC,MAAM,+CAA+C;;AAE5F;AACA;AACA,IAAMC,WAAW,GAAG,GAAG;AACvB;AACA,IAAMC,oCAAoC,GAAG,EAAE;AAC/C;AACA;AACA,IAAMC,0BAA0B,GAAGd,MAAM,CAACY,WAAW,EAAEC,oCAAoC,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,MAAM,CAACwD,4BAA4B,CAAC,CAAC,EAAE;QAC1C;QACA;QACA;QACA,IAAM1B,kBAAkB,GAAG9B,MAAM,CAAC8B,kBAAkB,CAAC,CAAC;QACtD,IAAKA,kBAAkB,IAAIpB,cAAc,IACvC,CAACoB,kBAAkB,IAAI,CAACrB,aAAc,EAAE;UACzC,OAAO,IAAI;QACZ;MACD;IACD;EAAC;AAAA;AAAA,SAhmBmBhC,kBAAkB,IAAAqG,OAAA","ignoreList":[]}
1
+ {"version":3,"file":"AsYouTypeFormatter.js","names":["DIGIT_PLACEHOLDER","repeat","cutAndStripNonPairedParens","populateTemplateWithDigits","formatCompleteNumber","canFormatCompleteNumber","PatternMatcher","parseDigits","FIRST_GROUP_PATTERN","VALID_PUNCTUATION","applyInternationalSeparatorStyle","DUMMY_DIGIT","LONGEST_NATIONAL_PHONE_NUMBER_LENGTH","LONGEST_DUMMY_PHONE_NUMBER","NATIONAL_PREFIX_SEPARATORS_PATTERN","SUPPORT_LEGACY_FORMATTING_PATTERNS","CREATE_CHARACTER_CLASS_PATTERN","CREATE_STANDALONE_DIGIT_PATTERN","NON_ALTERING_FORMAT_REG_EXP","RegExp","MIN_LEADING_DIGITS_LENGTH","AsYouTypeFormatter","_ref","state","metadata","_classCallCheck","resetFormat","_createClass","key","value","chosenFormat","undefined","template","nationalNumberTemplate","populatedNationalNumberTemplate","populatedNationalNumberTemplatePosition","reset","numberingPlan","isNANP","callingCode","matchingFormats","formats","nationalSignificantNumber","narrowDownMatchingFormats","format","nextDigits","_this","_iterator","_createForOfIteratorHelperLoose","_step","done","formattedCompleteNumber","shouldTryNationalPrefixFormattingRule","international","nationalPrefix","getSeparatorAfterNationalPrefix","setNationalNumberTemplate","replace","lastIndexOf","formatNationalNumberWithNextDigits","previouslyChosenFormat","newlyChosenFormat","chooseFormat","formatNextNationalNumberDigits","getNationalDigits","_ref2","_this2","leadingDigits","leadingDigitsPatternIndex","length","filter","formatSuits","formatMatches","indexOf","usesNationalPrefix","nationalPrefixIsOptionalWhenFormattingInNationalFormat","nationalPrefixIsMandatoryWhenFormattingInNationalFormat","leadingDigitsPatternsCount","leadingDigitsPatterns","Math","min","leadingDigitsPattern","match","allowOverflow","error","console","concat","test","getFormatFormat","internationalFormat","_this3","_loop","_step2","createTemplateForFormat","_","_ret","_iterator2","slice","pattern","getTemplateForFormat","nationalPrefixFormattingRule","getInternationalPrefixBeforeCountryCallingCode","_ref3","options","IDDPrefix","missingPlus","spacing","getTemplate","index","i","internationalPrefix","getDigitsWithoutInternationalPrefix","_ref4","prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix","digits","strictPattern","nationalNumberDummyDigits","numberFormat","nationalPrefixIncludedInTemplate","numberFormatWithNationalPrefix","result","_ref5","default"],"sources":["../source/AsYouTypeFormatter.js"],"sourcesContent":["import {\n\tDIGIT_PLACEHOLDER,\n\trepeat,\n\tcutAndStripNonPairedParens,\n\tpopulateTemplateWithDigits\n} from './AsYouTypeFormatter.util.js'\n\nimport formatCompleteNumber, {\n\tcanFormatCompleteNumber\n} from './AsYouTypeFormatter.complete.js'\n\nimport PatternMatcher from './AsYouTypeFormatter.PatternMatcher.js'\n\nimport parseDigits from './helpers/parseDigits.js'\nexport { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util.js'\nimport { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat.js'\nimport { VALID_PUNCTUATION } from './constants.js'\nimport applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle.js'\n\n// Used in phone number format template creation.\n// Could be any digit, I guess.\nconst DUMMY_DIGIT = '9'\n// I don't know why is it exactly `15`\nconst LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15\n// Create a phone number consisting only of the digit 9 that matches the\n// `number_pattern` by applying the pattern to the \"longest phone number\" string.\nconst LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH)\n\n// A set of characters that, if found in a national prefix formatting rules, are an indicator to\n// us that we should separate the national prefix from the number when formatting.\nconst NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/\n\n// Deprecated: Google has removed some formatting pattern related code from their repo.\n// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c\n// \"We no longer have numbers in formatting matching patterns, only \\d.\"\n// Because this library supports generating custom metadata\n// some users may still be using old metadata so the relevant\n// code seems to stay until some next major version update.\nconst SUPPORT_LEGACY_FORMATTING_PATTERNS = true\n\n// A pattern that is used to match character classes in regular expressions.\n// An example of a character class is \"[1-4]\".\nconst CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\[([^\\[\\]])*\\]/g)\n\n// Any digit in a regular expression that actually denotes a digit. For\n// example, in the regular expression \"80[0-2]\\d{6,10}\", the first 2 digits\n// (8 and 0) are standalone digits, but the rest are not.\n// Two look-aheads are needed because the number following \\\\d could be a\n// two-digit number, since the phone number can be as long as 15 digits.\nconst CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\d(?=[^,}][^,}])/g)\n\n// A regular expression that is used to determine if a `format` is\n// suitable to be used in the \"as you type formatter\".\n// A `format` is suitable when the resulting formatted number has\n// the same digits as the user has entered.\n//\n// In the simplest case, that would mean that the format\n// doesn't add any additional digits when formatting a number.\n// Google says that it also shouldn't add \"star\" (`*`) characters,\n// like it does in some Israeli formats.\n// Such basic format would only contain \"valid punctuation\"\n// and \"captured group\" identifiers ($1, $2, etc).\n//\n// An example of a format that adds additional digits:\n//\n// Country: `AR` (Argentina).\n// Format:\n// {\n// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\n// \"leading_digits_patterns\": [\"91\"],\n// \"national_prefix_formatting_rule\": \"0$1\",\n// \"format\": \"$2 15-$3-$4\",\n// \"international_format\": \"$1 $2 $3-$4\"\n// }\n//\n// In the format above, the `format` adds `15` to the digits when formatting a number.\n// A sidenote: this format actually is suitable because `national_prefix_for_parsing`\n// has previously removed `15` from a national number, so re-adding `15` in `format`\n// doesn't actually result in any extra digits added to user's input.\n// But verifying that would be a complex procedure, so the code chooses a simpler path:\n// it simply filters out all `format`s that contain anything but \"captured group\" ids.\n//\n// This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's\n// `libphonenumber` code.\n//\nconst NON_ALTERING_FORMAT_REG_EXP = new RegExp(\n\t'[' + VALID_PUNCTUATION + ']*' +\n\t// Google developers say:\n\t// \"We require that the first matching group is present in the\n\t// output pattern to ensure no data is lost while formatting.\"\n\t'\\\\$1' +\n\t'[' + VALID_PUNCTUATION + ']*' +\n\t'(\\\\$\\\\d[' + VALID_PUNCTUATION + ']*)*' +\n\t'$'\n)\n\n// This is the minimum length of the leading digits of a phone number\n// to guarantee the first \"leading digits pattern\" for a phone number format\n// to be preemptive.\nconst MIN_LEADING_DIGITS_LENGTH = 3\n\nexport default class AsYouTypeFormatter {\n\tconstructor({\n\t\tstate,\n\t\tmetadata\n\t}) {\n\t\tthis.metadata = metadata\n\t\tthis.resetFormat()\n\t}\n\n\tresetFormat() {\n\t\tthis.chosenFormat = undefined\n\t\tthis.template = undefined\n\t\tthis.nationalNumberTemplate = undefined\n\t\tthis.populatedNationalNumberTemplate = undefined\n\t\tthis.populatedNationalNumberTemplatePosition = -1\n\t}\n\n\treset(numberingPlan, state) {\n\t\tthis.resetFormat()\n\t\tif (numberingPlan) {\n\t\t\tthis.isNANP = numberingPlan.callingCode() === '1'\n\t\t\tthis.matchingFormats = numberingPlan.formats()\n\t\t\tif (state.nationalSignificantNumber) {\n\t\t\t\tthis.narrowDownMatchingFormats(state)\n\t\t\t}\n\t\t} else {\n\t\t\tthis.isNANP = undefined\n\t\t\tthis.matchingFormats = []\n\t\t}\n\t}\n\n\t/**\n\t * Formats an updated phone number.\n\t * @param {string} nextDigits — Additional phone number digits.\n\t * @param {object} state — `AsYouType` state.\n\t * @return {[string]} Returns undefined if the updated phone number can't be formatted using any of the available formats.\n\t */\n\tformat(nextDigits, state) {\n\t\t// See if the phone number digits can be formatted as a complete phone number.\n\t\t// If not, use the results from `formatNationalNumberWithNextDigits()`,\n\t\t// which formats based on the chosen formatting pattern.\n\t\t//\n\t\t// Attempting to format complete phone number first is how it's done\n\t\t// in Google's `libphonenumber`, so this library just follows it.\n\t\t// Google's `libphonenumber` code doesn't explain in detail why does it\n\t\t// attempt to format digits as a complete phone number\n\t\t// instead of just going with a previoulsy (or newly) chosen `format`:\n\t\t//\n\t\t// \"Checks to see if there is an exact pattern match for these digits.\n\t\t// If so, we should use this instead of any other formatting template\n\t\t// whose leadingDigitsPattern also matches the input.\"\n\t\t//\n\t\tif (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {\n\t\t\tfor (const format of this.matchingFormats) {\n\t\t\t\tconst formattedCompleteNumber = formatCompleteNumber(\n\t\t\t\t\tstate,\n\t\t\t\t\tformat,\n\t\t\t\t\t{\n\t\t\t\t\t\tmetadata: this.metadata,\n\t\t\t\t\t\tshouldTryNationalPrefixFormattingRule: (format) => this.shouldTryNationalPrefixFormattingRule(format, {\n\t\t\t\t\t\t\tinternational: state.international,\n\t\t\t\t\t\t\tnationalPrefix: state.nationalPrefix\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tgetSeparatorAfterNationalPrefix: (format) => this.getSeparatorAfterNationalPrefix(format)\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t\tif (formattedCompleteNumber) {\n\t\t\t\t\tthis.resetFormat()\n\t\t\t\t\tthis.chosenFormat = format\n\t\t\t\t\tthis.setNationalNumberTemplate(formattedCompleteNumber.replace(/\\d/g, DIGIT_PLACEHOLDER), state)\n\t\t\t\t\tthis.populatedNationalNumberTemplate = formattedCompleteNumber\n\t\t\t\t\t// With a new formatting template, the matched position\n\t\t\t\t\t// using the old template needs to be reset.\n\t\t\t\t\tthis.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(DIGIT_PLACEHOLDER)\n\t\t\t\t\treturn formattedCompleteNumber\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\t// Format the digits as a partial (incomplete) phone number\n\t\t// using the previously chosen formatting pattern (or a newly chosen one).\n\t\treturn this.formatNationalNumberWithNextDigits(nextDigits, state)\n\t}\n\n\t// Formats the next phone number digits.\n\tformatNationalNumberWithNextDigits(nextDigits, state) {\n\t\tconst previouslyChosenFormat = this.chosenFormat\n\n\t\t// Choose a format from the list of matching ones.\n\t\tconst newlyChosenFormat = this.chooseFormat(state)\n\n\t\tif (newlyChosenFormat) {\n\t\t\tif (newlyChosenFormat === previouslyChosenFormat) {\n\t\t\t\t// If it can format the next (current) digits\n\t\t\t\t// using the previously chosen phone number format\n\t\t\t\t// then return the updated formatted number.\n\t\t\t\treturn this.formatNextNationalNumberDigits(nextDigits)\n\t\t\t} else {\n\t\t\t\t// If a more appropriate phone number format\n\t\t\t\t// has been chosen for these \"leading digits\",\n\t\t\t\t// then re-format the national phone number part\n\t\t\t\t// using the newly selected format.\n\t\t\t\treturn this.formatNextNationalNumberDigits(state.getNationalDigits())\n\t\t\t}\n\t\t}\n\t}\n\n\tnarrowDownMatchingFormats({\n\t\tnationalSignificantNumber,\n\t\tnationalPrefix,\n\t\tinternational\n\t}) {\n\t\tconst leadingDigits = nationalSignificantNumber\n\n\t\t// \"leading digits\" pattern list starts with a\n\t\t// \"leading digits\" pattern fitting a maximum of 3 leading digits.\n\t\t// So, after a user inputs 3 digits of a national (significant) phone number\n\t\t// this national (significant) number can already be formatted.\n\t\t// The next \"leading digits\" pattern is for 4 leading digits max,\n\t\t// and the \"leading digits\" pattern after it is for 5 leading digits max, etc.\n\n\t\t// This implementation is different from Google's\n\t\t// in that it searches for a fitting format\n\t\t// even if the user has entered less than\n\t\t// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.\n\t\t// Because some leading digit patterns already match for a single first digit.\n\t\tlet leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH\n\t\tif (leadingDigitsPatternIndex < 0) {\n\t\t\tleadingDigitsPatternIndex = 0\n\t\t}\n\n\t\tthis.matchingFormats = this.matchingFormats.filter(\n\t\t\tformat => this.formatSuits(format, international, nationalPrefix)\n\t\t\t\t&& this.formatMatches(format, leadingDigits, leadingDigitsPatternIndex)\n\t\t)\n\n\t\t// If there was a phone number format chosen\n\t\t// and it no longer holds given the new leading digits then reset it.\n\t\t// The test for this `if` condition is marked as:\n\t\t// \"Reset a chosen format when it no longer holds given the new leading digits\".\n\t\t// To construct a valid test case for this one can find a country\n\t\t// in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`\n\t\t// and yielding another format for 4 `<leadingDigits>` (Australia in this case).\n\t\tif (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {\n\t\t\tthis.resetFormat()\n\t\t}\n\t}\n\n\tformatSuits(format, international, nationalPrefix) {\n\t\t// When a prefix before a national (significant) number is\n\t\t// simply a national prefix, then it's parsed as `this.nationalPrefix`.\n\t\t// In more complex cases, a prefix before national (significant) number\n\t\t// could include a national prefix as well as some \"capturing groups\",\n\t\t// and in that case there's no info whether a national prefix has been parsed.\n\t\t// If national prefix is not used when formatting a phone number\n\t\t// using this format, but a national prefix has been entered by the user,\n\t\t// and was extracted, then discard such phone number format.\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184\n\t\tif (nationalPrefix &&\n\t\t\t!format.usesNationalPrefix() &&\n\t\t\t// !format.domesticCarrierCodeFormattingRule() &&\n\t\t\t!format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {\n\t\t\treturn false\n\t\t}\n\t\t// If national prefix is mandatory for this phone number format\n\t\t// and there're no guarantees that a national prefix is present in user input\n\t\t// then discard this phone number format as not suitable.\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193\n\t\tif (!international &&\n\t\t\t!nationalPrefix &&\n\t\t\tformat.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t}\n\n\tformatMatches(format, leadingDigits, leadingDigitsPatternIndex) {\n\t\tconst leadingDigitsPatternsCount = format.leadingDigitsPatterns().length\n\n\t\t// If this format is not restricted to a certain\n\t\t// leading digits pattern then it fits.\n\t\t// The test case could be found by searching for \"leadingDigitsPatternsCount === 0\".\n\t\tif (leadingDigitsPatternsCount === 0) {\n\t\t\treturn true\n\t\t}\n\n\t\t// Start narrowing down the list of possible formats based on the leading digits.\n\t\t// (only previously matched formats take part in the narrowing down process)\n\n\t\t// `leading_digits_patterns` start with 3 digits min\n\t\t// and then go up from there one digit at a time.\n\t\tleadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1)\n\t\tconst leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]\n\n\t\t// Google imposes a requirement on the leading digits\n\t\t// to be minimum 3 digits long in order to be eligible\n\t\t// for checking those with a leading digits pattern.\n\t\t//\n\t\t// Since `leading_digits_patterns` start with 3 digits min,\n\t\t// Google's original `libphonenumber` library only starts\n\t\t// excluding any non-matching formats only when the\n\t\t// national number entered so far is at least 3 digits long,\n\t\t// otherwise format matching would give false negatives.\n\t\t//\n\t\t// For example, when the digits entered so far are `2`\n\t\t// and the leading digits pattern is `21` –\n\t\t// it's quite obvious in this case that the format could be the one\n\t\t// but due to the absence of further digits it would give false negative.\n\t\t//\n\t\t// Also, `leading_digits_patterns` doesn't always correspond to a single\n\t\t// digits count. For example, `60|8` pattern would already match `8`\n\t\t// but the `60` part would require having at least two leading digits,\n\t\t// so the whole pattern would require inputting two digits first in order to\n\t\t// decide on whether it matches the input, even when the input is \"80\".\n\t\t//\n\t\t// This library — `libphonenumber-js` — allows filtering by `leading_digits_patterns`\n\t\t// even when there's only 1 or 2 digits of the national (significant) number.\n\t\t// To do that, it uses a non-strict pattern matcher written specifically for that.\n\t\t//\n\t\tif (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {\n\t\t\t// Before leading digits < 3 matching was implemented:\n\t\t\t// return true\n\t\t\t//\n\t\t\t// After leading digits < 3 matching was implemented:\n\t\t\ttry {\n\t\t\t\treturn new PatternMatcher(leadingDigitsPattern).match(leadingDigits, { allowOverflow: true }) !== undefined\n\t\t\t} catch (error) /* istanbul ignore next */ {\n\t\t\t\t// There's a slight possibility that there could be some undiscovered bug\n\t\t\t\t// in the pattern matcher code. Since the \"leading digits < 3 matching\"\n\t\t\t\t// feature is not \"essential\" for operation, it can fall back to the old way\n\t\t\t\t// in case of any issues rather than halting the application's execution.\n\t\t\t\tconsole.error(error)\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\n\t\t// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are\n\t\t// available then use the usual regular expression matching.\n\t\t//\n\t\t// The whole pattern is wrapped in round brackets (`()`) because\n\t\t// the pattern can use \"or\" operator (`|`) at the top level of the pattern.\n\t\t//\n\t\treturn new RegExp(`^(${leadingDigitsPattern})`).test(leadingDigits)\n\t}\n\n\tgetFormatFormat(format, international) {\n\t\treturn international ? format.internationalFormat() : format.format()\n\t}\n\n\tchooseFormat(state) {\n\t\t// When there are multiple available formats, the formatter uses the first\n\t\t// format where a formatting template could be created.\n\t\t//\n\t\t// For some weird reason, `istanbul` says \"else path not taken\"\n\t\t// for the `for of` line below. Supposedly that means that\n\t\t// the loop doesn't ever go over the last element in the list.\n\t\t// That's true because there always is `this.chosenFormat`\n\t\t// when `this.matchingFormats` is non-empty.\n\t\t// And, for some weird reason, it doesn't think that the case\n\t\t// with empty `this.matchingFormats` qualifies for a valid \"else\" path.\n\t\t// So simply muting this `istanbul` warning.\n\t\t// It doesn't skip the contents of the `for of` loop,\n\t\t// it just skips the `for of` line.\n\t\t//\n\t\t/* istanbul ignore next */\n\t\tfor (const format of this.matchingFormats.slice()) {\n\t\t\t// If this format is currently being used\n\t\t\t// and is still suitable, then stick to it.\n\t\t\tif (this.chosenFormat === format) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\t// Sometimes, a formatting rule inserts additional digits in a phone number,\n\t\t\t// and \"as you type\" formatter can't do that: it should only use the digits\n\t\t\t// that the user has input.\n\t\t\t//\n\t\t\t// For example, in Argentina, there's a format for mobile phone numbers:\n\t\t\t//\n\t\t\t// {\n\t\t\t// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\n\t\t\t// \"leading_digits_patterns\": [\"91\"],\n\t\t\t// \"national_prefix_formatting_rule\": \"0$1\",\n\t\t\t// \"format\": \"$2 15-$3-$4\",\n\t\t\t// \"international_format\": \"$1 $2 $3-$4\"\n\t\t\t// }\n\t\t\t//\n\t\t\t// In that format, `international_format` is used instead of `format`\n\t\t\t// because `format` inserts `15` in the formatted number,\n\t\t\t// and `AsYouType` formatter should only use the digits\n\t\t\t// the user has actually input, without adding any extra digits.\n\t\t\t// In this case, it wouldn't make a difference, because the `15`\n\t\t\t// is first stripped when applying `national_prefix_for_parsing`\n\t\t\t// and then re-added when using `format`, so in reality it doesn't\n\t\t\t// add any new digits to the number, but to detect that, the code\n\t\t\t// would have to be more complex: it would have to try formatting\n\t\t\t// the digits using the format and then see if any digits have\n\t\t\t// actually been added or removed, and then, every time a new digit\n\t\t\t// is input, it should re-check whether the chosen format doesn't\n\t\t\t// alter the digits.\n\t\t\t//\n\t\t\t// Google's code doesn't go that far, and so does this library:\n\t\t\t// it simply requires that a `format` doesn't add any additonal\n\t\t\t// digits to user's input.\n\t\t\t//\n\t\t\t// Also, people in general should move from inputting phone numbers\n\t\t\t// in national format (possibly with national prefixes)\n\t\t\t// and use international phone number format instead:\n\t\t\t// it's a logical thing in the modern age of mobile phones,\n\t\t\t// globalization and the internet.\n\t\t\t//\n\t\t\t/* istanbul ignore if */\n\t\t\tif (!NON_ALTERING_FORMAT_REG_EXP.test(this.getFormatFormat(format, state.international))) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!this.createTemplateForFormat(format, state)) {\n\t\t\t\t// Remove the format if it can't generate a template.\n\t\t\t\tthis.matchingFormats = this.matchingFormats.filter(_ => _ !== format)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tthis.chosenFormat = format\n\t\t\tbreak\n\t\t}\n\t\tif (!this.chosenFormat) {\n\t\t\t// No format matches the national (significant) phone number.\n\t\t\tthis.resetFormat()\n\t\t}\n\t\treturn this.chosenFormat\n\t}\n\n\tcreateTemplateForFormat(format, state) {\n\t\t// The formatter doesn't format numbers when numberPattern contains '|', e.g.\n\t\t// (20|3)\\d{4}. In those cases we quickly return.\n\t\t// (Though there's no such format in current metadata)\n\t\t/* istanbul ignore if */\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {\n\t\t\treturn\n\t\t}\n\t\t// Get formatting template for this phone number format\n\t\tconst template = this.getTemplateForFormat(format, state)\n\t\t// If the national number entered is too long\n\t\t// for any phone number format, then abort.\n\t\tif (template) {\n\t\t\tthis.setNationalNumberTemplate(template, state)\n\t\t\treturn true\n\t\t}\n\t}\n\n\tgetSeparatorAfterNationalPrefix(format) {\n\t\t// `US` metadata doesn't have a `national_prefix_formatting_rule`,\n\t\t// so the `if` condition below doesn't apply to `US`,\n\t\t// but in reality there shoudl be a separator\n\t\t// between a national prefix and a national (significant) number.\n\t\t// So `US` national prefix separator is a \"special\" \"hardcoded\" case.\n\t\tif (this.isNANP) {\n\t\t\treturn ' '\n\t\t}\n\t\t// If a `format` has a `national_prefix_formatting_rule`\n\t\t// and that rule has a separator after a national prefix,\n\t\t// then it means that there should be a separator\n\t\t// between a national prefix and a national (significant) number.\n\t\tif (format &&\n\t\t\tformat.nationalPrefixFormattingRule() &&\n\t\t\tNATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {\n\t\t\treturn ' '\n\t\t}\n\t\t// At this point, there seems to be no clear evidence that\n\t\t// there should be a separator between a national prefix\n\t\t// and a national (significant) number. So don't insert one.\n\t\treturn ''\n\t}\n\n\tgetInternationalPrefixBeforeCountryCallingCode({ IDDPrefix, missingPlus }, options) {\n\t\tif (IDDPrefix) {\n\t\t\treturn options && options.spacing === false ? IDDPrefix : IDDPrefix + ' '\n\t\t}\n\t\tif (missingPlus) {\n\t\t\treturn ''\n\t\t}\n\t\treturn '+'\n\t}\n\n\tgetTemplate(state) {\n\t\tif (!this.template) {\n\t\t\treturn\n\t\t}\n\t\t// `this.template` holds the template for a \"complete\" phone number.\n\t\t// The currently entered phone number is most likely not \"complete\",\n\t\t// so trim all non-populated digits.\n\t\tlet index = -1\n\t\tlet i = 0\n\t\tconst internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, { spacing: false }) : ''\n\t\twhile (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {\n\t\t\tindex = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)\n\t\t\ti++\n\t\t}\n\t\treturn cutAndStripNonPairedParens(this.template, index + 1)\n\t}\n\n\tsetNationalNumberTemplate(template, state) {\n\t\tthis.nationalNumberTemplate = template\n\t\tthis.populatedNationalNumberTemplate = template\n\t\t// With a new formatting template, the matched position\n\t\t// using the old template needs to be reset.\n\t\tthis.populatedNationalNumberTemplatePosition = -1\n\t\t// For convenience, the public `.template` property\n\t\t// contains the whole international number\n\t\t// if the phone number being input is international:\n\t\t// 'x' for the '+' sign, 'x'es for the country phone code,\n\t\t// a spacebar and then the template for the formatted national number.\n\t\tif (state.international) {\n\t\t\tthis.template =\n\t\t\t\tthis.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER) +\n\t\t\t\trepeat(DIGIT_PLACEHOLDER, state.callingCode.length) +\n\t\t\t\t' ' +\n\t\t\t\ttemplate\n\t\t} else {\n\t\t\tthis.template = template\n\t\t}\n\t}\n\n\t/**\n\t * Generates formatting template for a national phone number,\n\t * optionally containing a national prefix, for a format.\n\t * @param {Format} format\n\t * @param {string} nationalPrefix\n\t * @return {string}\n\t */\n\tgetTemplateForFormat(format, {\n\t\tnationalSignificantNumber,\n\t\tinternational,\n\t\tnationalPrefix,\n\t\tprefixBeforeNationalSignificantNumberThatIsNotNationalPrefix\n\t}) {\n\t\tlet pattern = format.pattern()\n\n\t\t/* istanbul ignore else */\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS) {\n\t\t\tpattern = pattern\n\t\t\t\t// Replace anything in the form of [..] with \\d\n\t\t\t\t.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\\\d')\n\t\t\t\t// Replace any standalone digit (not the one in `{}`) with \\d\n\t\t\t\t.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\\\d')\n\t\t}\n\n\t\t// Generate a dummy national number (consisting of `9`s)\n\t\t// that fits this format's `pattern`.\n\t\t//\n\t\t// This match will always succeed,\n\t\t// because the \"longest dummy phone number\"\n\t\t// has enough length to accomodate any possible\n\t\t// national phone number format pattern.\n\t\t//\n\t\tlet digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]\n\n\t\t// If the national number entered is too long\n\t\t// for any phone number format, then abort.\n\t\tif (nationalSignificantNumber.length > digits.length) {\n\t\t\treturn\n\t\t}\n\n\t\t// Get a formatting template which can be used to efficiently format\n\t\t// a partial number where digits are added one by one.\n\n\t\t// Below `strictPattern` is used for the\n\t\t// regular expression (with `^` and `$`).\n\t\t// This wasn't originally in Google's `libphonenumber`\n\t\t// and I guess they don't really need it\n\t\t// because they're not using \"templates\" to format phone numbers\n\t\t// but I added `strictPattern` after encountering\n\t\t// South Korean phone number formatting bug.\n\t\t//\n\t\t// Non-strict regular expression bug demonstration:\n\t\t//\n\t\t// this.nationalSignificantNumber : `111111111` (9 digits)\n\t\t//\n\t\t// pattern : (\\d{2})(\\d{3,4})(\\d{4})\n\t\t// format : `$1 $2 $3`\n\t\t// digits : `9999999999` (10 digits)\n\t\t//\n\t\t// '9999999999'.replace(new RegExp(/(\\d{2})(\\d{3,4})(\\d{4})/g), '$1 $2 $3') = \"99 9999 9999\"\n\t\t//\n\t\t// template : xx xxxx xxxx\n\t\t//\n\t\t// But the correct template in this case is `xx xxx xxxx`.\n\t\t// The template was generated incorrectly because of the\n\t\t// `{3,4}` variability in the `pattern`.\n\t\t//\n\t\t// The fix is, if `this.nationalSignificantNumber` has already sufficient length\n\t\t// to satisfy the `pattern` completely then `this.nationalSignificantNumber`\n\t\t// is used instead of `digits`.\n\n\t\tconst strictPattern = new RegExp('^' + pattern + '$')\n\t\tconst nationalNumberDummyDigits = nationalSignificantNumber.replace(/\\d/g, DUMMY_DIGIT)\n\n\t\t// If `this.nationalSignificantNumber` has already sufficient length\n\t\t// to satisfy the `pattern` completely then use it\n\t\t// instead of `digits`.\n\t\tif (strictPattern.test(nationalNumberDummyDigits)) {\n\t\t\tdigits = nationalNumberDummyDigits\n\t\t}\n\n\t\tlet numberFormat = this.getFormatFormat(format, international)\n\t\tlet nationalPrefixIncludedInTemplate\n\n\t\t// If a user did input a national prefix (and that's guaranteed),\n\t\t// and if a `format` does have a national prefix formatting rule,\n\t\t// then see if that national prefix formatting rule\n\t\t// prepends exactly the same national prefix the user has input.\n\t\t// If that's the case, then use the `format` with the national prefix formatting rule.\n\t\t// Otherwise, use the `format` without the national prefix formatting rule,\n\t\t// and prepend a national prefix manually to it.\n\t\tif (this.shouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix })) {\n\t\t\tconst numberFormatWithNationalPrefix = numberFormat.replace(\n\t\t\t\tFIRST_GROUP_PATTERN,\n\t\t\t\tformat.nationalPrefixFormattingRule()\n\t\t\t)\n\t\t\t// If `national_prefix_formatting_rule` of a `format` simply prepends\n\t\t\t// national prefix at the start of a national (significant) number,\n\t\t\t// then such formatting can be used with `AsYouType` formatter.\n\t\t\t// There seems to be no `else` case: everywhere in metadata,\n\t\t\t// national prefix formatting rule is national prefix + $1,\n\t\t\t// or `($1)`, in which case such format isn't even considered\n\t\t\t// when the user has input a national prefix.\n\t\t\t/* istanbul ignore else */\n\t\t\tif (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {\n\t\t\t\tnumberFormat = numberFormatWithNationalPrefix\n\t\t\t\tnationalPrefixIncludedInTemplate = true\n\t\t\t\t// Replace all digits of the national prefix in the formatting template\n\t\t\t\t// with `DIGIT_PLACEHOLDER`s.\n\t\t\t\tif (nationalPrefix) {\n\t\t\t\t\tlet i = nationalPrefix.length\n\t\t\t\t\twhile (i > 0) {\n\t\t\t\t\t\tnumberFormat = numberFormat.replace(/\\d/, DIGIT_PLACEHOLDER)\n\t\t\t\t\t\ti--\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Generate formatting template for this phone number format.\n\t\tlet template = digits\n\t\t\t// Format the dummy phone number according to the format.\n\t\t\t.replace(new RegExp(pattern), numberFormat)\n\t\t\t// Replace each dummy digit with a DIGIT_PLACEHOLDER.\n\t\t\t.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)\n\n\t\t// If a prefix of a national (significant) number is not as simple\n\t\t// as just a basic national prefix, then just prepend such prefix\n\t\t// before the national (significant) number, optionally spacing\n\t\t// the two with a whitespace.\n\t\tif (!nationalPrefixIncludedInTemplate) {\n\t\t\tif (prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix) {\n\t\t\t\t// Prepend the prefix to the template manually.\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix.length) +\n\t\t\t\t\t' ' +\n\t\t\t\t\ttemplate\n\t\t\t} else if (nationalPrefix) {\n\t\t\t\t// Prepend national prefix to the template manually.\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +\n\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\n\t\t\t\t\ttemplate\n\t\t\t}\n\t\t}\n\n\t\tif (international) {\n\t\t\ttemplate = applyInternationalSeparatorStyle(template)\n\t\t}\n\n\t\treturn template\n\t}\n\n\tformatNextNationalNumberDigits(digits) {\n\t\tconst result = populateTemplateWithDigits(\n\t\t\tthis.populatedNationalNumberTemplate,\n\t\t\tthis.populatedNationalNumberTemplatePosition,\n\t\t\tdigits\n\t\t)\n\n\t\tif (!result) {\n\t\t\t// Reset the format.\n\t\t\tthis.resetFormat()\n\t\t\treturn\n\t\t}\n\n\t\tthis.populatedNationalNumberTemplate = result[0]\n\t\tthis.populatedNationalNumberTemplatePosition = result[1]\n\n\t\t// Return the formatted phone number so far.\n\t\treturn cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\n\n\t\t// The old way which was good for `input-format` but is not so good\n\t\t// for `react-phone-number-input`'s default input (`InputBasic`).\n\t\t// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\n\t\t// \t.replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')\n\t}\n\n\tshouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix }) {\n\t\tif (format.nationalPrefixFormattingRule()) {\n\t\t\t// In some countries, `national_prefix_formatting_rule` is `($1)`,\n\t\t\t// so it applies even if the user hasn't input a national prefix.\n\t\t\t// `format.usesNationalPrefix()` detects such cases.\n\t\t\tconst usesNationalPrefix = format.usesNationalPrefix()\n\t\t\tif ((usesNationalPrefix && nationalPrefix) ||\n\t\t\t\t(!usesNationalPrefix && !international)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t}\n}"],"mappings":";;;;;;;;;AAAA,SACCA,iBAAiB,EACjBC,MAAM,EACNC,0BAA0B,EAC1BC,0BAA0B,QACpB,8BAA8B;AAEr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A+B,GAAGsF,MAAM,CAAC,CAAC,CAAC;MAChD,IAAI,CAACrF,uCAAuC,GAAGqF,MAAM,CAAC,CAAC,CAAC;;MAExD;MACA,OAAOtH,0BAA0B,CAAC,IAAI,CAACgC,+BAA+B,EAAE,IAAI,CAACC,uCAAuC,GAAG,CAAC,CAAC;;MAEzH;MACA;MACA;MACA;IACD;EAAC;IAAAP,GAAA;IAAAC,KAAA,EAED,SAAAuB,qCAAqCA,CAACR,MAAM,EAAA6E,KAAA,EAAqC;MAAA,IAAjCpE,aAAa,GAAAoE,KAAA,CAAbpE,aAAa;QAAEC,cAAc,GAAAmE,KAAA,CAAdnE,cAAc;MAC5E,IAAIV,MAAM,CAACwD,4BAA4B,CAAC,CAAC,EAAE;QAC1C;QACA;QACA;QACA,IAAM1B,kBAAkB,GAAG9B,MAAM,CAAC8B,kBAAkB,CAAC,CAAC;QACtD,IAAKA,kBAAkB,IAAIpB,cAAc,IACvC,CAACoB,kBAAkB,IAAI,CAACrB,aAAc,EAAE;UACzC,OAAO,IAAI;QACZ;MACD;IACD;EAAC;AAAA;AAAA,SAhmBmBhC,kBAAkB,IAAAqG,OAAA","ignoreList":[]}
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Strips any national prefix (such as 0, 1) present in a
3
3
  * (possibly incomplete) number provided.
4
+ * Also strips a "carrier code", if it's present.
4
5
  * "Carrier codes" are only used in Colombia and Brazil,
5
6
  * and only when dialing within those countries from a mobile phone to a fixed line number.
6
7
  * Sometimes it won't actually strip national prefix
@@ -1 +1 @@
1
- {"version":3,"file":"extractNationalNumberFromPossiblyIncompleteNumber.js","names":["extractNationalNumberFromPossiblyIncompleteNumber","number","metadata","numberingPlan","nationalPrefixForParsing","prefixPattern","RegExp","prefixMatch","exec","nationalNumber","carrierCode","capturedGroupsCount","length","hasCapturedGroups","nationalPrefixTransformRule","replace","prefixBeforeNationalNumber","slice","nationalPrefix","possiblePositionOfTheFirstCapturedGroup","indexOf","possibleNationalPrefix"],"sources":["../../source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js"],"sourcesContent":["/**\n * Strips any national prefix (such as 0, 1) present in a\n * (possibly incomplete) number provided.\n * \"Carrier codes\" are only used in Colombia and Brazil,\n * and only when dialing within those countries from a mobile phone to a fixed line number.\n * Sometimes it won't actually strip national prefix\n * and will instead prepend some digits to the `number`:\n * for example, when number `2345678` is passed with `VI` country selected,\n * it will return `{ number: \"3402345678\" }`, because `340` area code is prepended.\n * @param {string} number — National number digits.\n * @param {object} metadata — Metadata with country selected.\n * @return {object} `{ nationalNumber: string, nationalPrefix: string? carrierCode: string? }`. Even if a national prefix was extracted, it's not necessarily present in the returned object, so don't rely on its presence in the returned object in order to find out whether a national prefix has been extracted or not.\n */\nexport default function extractNationalNumberFromPossiblyIncompleteNumber(number, metadata) {\n\tif (number && metadata.numberingPlan.nationalPrefixForParsing()) {\n\t\t// See METADATA.md for the description of\n\t\t// `national_prefix_for_parsing` and `national_prefix_transform_rule`.\n\t\t// Attempt to parse the first digits as a national prefix.\n\t\tconst prefixPattern = new RegExp('^(?:' + metadata.numberingPlan.nationalPrefixForParsing() + ')')\n\t\tconst prefixMatch = prefixPattern.exec(number)\n\t\tif (prefixMatch) {\n\t\t\tlet nationalNumber\n\t\t\tlet carrierCode\n\t\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/blob/master/METADATA.md#national_prefix_for_parsing--national_prefix_transform_rule\n\t\t\t// If a `national_prefix_for_parsing` has any \"capturing groups\"\n\t\t\t// then it means that the national (significant) number is equal to\n\t\t\t// those \"capturing groups\" transformed via `national_prefix_transform_rule`,\n\t\t\t// and nothing could be said about the actual national prefix:\n\t\t\t// what is it and was it even there.\n\t\t\t// If a `national_prefix_for_parsing` doesn't have any \"capturing groups\",\n\t\t\t// then everything it matches is a national prefix.\n\t\t\t// To determine whether `national_prefix_for_parsing` matched any\n\t\t\t// \"capturing groups\", the value of the result of calling `.exec()`\n\t\t\t// is looked at, and if it has non-undefined values where there're\n\t\t\t// \"capturing groups\" in the regular expression, then it means\n\t\t\t// that \"capturing groups\" have been matched.\n\t\t\t// It's not possible to tell whether there'll be any \"capturing gropus\"\n\t\t\t// before the matching process, because a `national_prefix_for_parsing`\n\t\t\t// could exhibit both behaviors.\n\t\t\tconst capturedGroupsCount = prefixMatch.length - 1\n\t\t\tconst hasCapturedGroups = capturedGroupsCount > 0 && prefixMatch[capturedGroupsCount]\n\t\t\tif (metadata.nationalPrefixTransformRule() && hasCapturedGroups) {\n\t\t\t\tnationalNumber = number.replace(\n\t\t\t\t\tprefixPattern,\n\t\t\t\t\tmetadata.nationalPrefixTransformRule()\n\t\t\t\t)\n\t\t\t\t// If there's more than one captured group,\n\t\t\t\t// then carrier code is the second one.\n\t\t\t\tif (capturedGroupsCount > 1) {\n\t\t\t\t\tcarrierCode = prefixMatch[1]\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If there're no \"capturing groups\",\n\t\t\t// or if there're \"capturing groups\" but no\n\t\t\t// `national_prefix_transform_rule`,\n\t\t\t// then just strip the national prefix from the number,\n\t\t\t// and possibly a carrier code.\n\t\t\t// Seems like there could be more.\n\t\t\telse {\n\t\t\t\t// `prefixBeforeNationalNumber` is the whole substring matched by\n\t\t\t\t// the `national_prefix_for_parsing` regular expression.\n\t\t\t\t// There seem to be no guarantees that it's just a national prefix.\n\t\t\t\t// For example, if there's a carrier code, it's gonna be a\n\t\t\t\t// part of `prefixBeforeNationalNumber` too.\n\t\t\t\tconst prefixBeforeNationalNumber = prefixMatch[0]\n\t\t\t\tnationalNumber = number.slice(prefixBeforeNationalNumber.length)\n\t\t\t\t// If there's at least one captured group,\n\t\t\t\t// then carrier code is the first one.\n\t\t\t\tif (hasCapturedGroups) {\n\t\t\t\t\tcarrierCode = prefixMatch[1]\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Tries to guess whether a national prefix was present in the input.\n\t\t\t// This is not something copy-pasted from Google's library:\n\t\t\t// they don't seem to have an equivalent for that.\n\t\t\t// So this isn't an \"officially approved\" way of doing something like that.\n\t\t\t// But since there seems no other existing method, this library uses it.\n\t\t\tlet nationalPrefix\n\t\t\tif (hasCapturedGroups) {\n\t\t\t\tconst possiblePositionOfTheFirstCapturedGroup = number.indexOf(prefixMatch[1])\n\t\t\t\tconst possibleNationalPrefix = number.slice(0, possiblePositionOfTheFirstCapturedGroup)\n\t\t\t\t// Example: an Argentinian (AR) phone number `0111523456789`.\n\t\t\t\t// `prefixMatch[0]` is `01115`, and `$1` is `11`,\n\t\t\t\t// and the rest of the phone number is `23456789`.\n\t\t\t\t// The national number is transformed via `9$1` to `91123456789`.\n\t\t\t\t// National prefix `0` is detected being present at the start.\n\t\t\t\t// if (possibleNationalPrefix.indexOf(metadata.numberingPlan.nationalPrefix()) === 0) {\n\t\t\t\tif (possibleNationalPrefix === metadata.numberingPlan.nationalPrefix()) {\n\t\t\t\t\tnationalPrefix = metadata.numberingPlan.nationalPrefix()\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnationalPrefix = prefixMatch[0]\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tnationalNumber,\n\t\t\t\tnationalPrefix,\n\t\t\t\tcarrierCode\n\t\t\t}\n\t\t}\n\t}\n return {\n \tnationalNumber: number\n }\n}"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,iDAAiDA,CAACC,MAAM,EAAEC,QAAQ,EAAE;EAC3F,IAAID,MAAM,IAAIC,QAAQ,CAACC,aAAa,CAACC,wBAAwB,CAAC,CAAC,EAAE;IAChE;IACA;IACA;IACA,IAAMC,aAAa,GAAG,IAAIC,MAAM,CAAC,MAAM,GAAGJ,QAAQ,CAACC,aAAa,CAACC,wBAAwB,CAAC,CAAC,GAAG,GAAG,CAAC;IAClG,IAAMG,WAAW,GAAGF,aAAa,CAACG,IAAI,CAACP,MAAM,CAAC;IAC9C,IAAIM,WAAW,EAAE;MAChB,IAAIE,cAAc;MAClB,IAAIC,WAA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X,WAAW,CAAC,CAAC,CAAC;MAChC;MACA,OAAO;QACNE,cAAc,EAAdA,cAAc;QACdS,cAAc,EAAdA,cAAc;QACdR,WAAW,EAAXA;MACD,CAAC;IACF;EACD;EACE,OAAO;IACND,cAAc,EAAER;EACjB,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"extractNationalNumberFromPossiblyIncompleteNumber.js","names":["extractNationalNumberFromPossiblyIncompleteNumber","number","metadata","numberingPlan","nationalPrefixForParsing","prefixPattern","RegExp","prefixMatch","exec","nationalNumber","carrierCode","capturedGroupsCount","length","hasCapturedGroups","nationalPrefixTransformRule","replace","prefixBeforeNationalNumber","slice","nationalPrefix","possiblePositionOfTheFirstCapturedGroup","indexOf","possibleNationalPrefix"],"sources":["../../source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js"],"sourcesContent":["/**\n * Strips any national prefix (such as 0, 1) present in a\n * (possibly incomplete) number provided.\n * Also strips a \"carrier code\", if it's present.\n * \"Carrier codes\" are only used in Colombia and Brazil,\n * and only when dialing within those countries from a mobile phone to a fixed line number.\n * Sometimes it won't actually strip national prefix\n * and will instead prepend some digits to the `number`:\n * for example, when number `2345678` is passed with `VI` country selected,\n * it will return `{ number: \"3402345678\" }`, because `340` area code is prepended.\n * @param {string} number — National number digits.\n * @param {object} metadata — Metadata with country selected.\n * @return {object} `{ nationalNumber: string, nationalPrefix: string? carrierCode: string? }`. Even if a national prefix was extracted, it's not necessarily present in the returned object, so don't rely on its presence in the returned object in order to find out whether a national prefix has been extracted or not.\n */\nexport default function extractNationalNumberFromPossiblyIncompleteNumber(number, metadata) {\n\tif (number && metadata.numberingPlan.nationalPrefixForParsing()) {\n\t\t// See METADATA.md for the description of\n\t\t// `national_prefix_for_parsing` and `national_prefix_transform_rule`.\n\t\t// Attempt to parse the first digits as a national prefix.\n\t\tconst prefixPattern = new RegExp('^(?:' + metadata.numberingPlan.nationalPrefixForParsing() + ')')\n\t\tconst prefixMatch = prefixPattern.exec(number)\n\t\tif (prefixMatch) {\n\t\t\tlet nationalNumber\n\t\t\tlet carrierCode\n\t\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/blob/master/METADATA.md#national_prefix_for_parsing--national_prefix_transform_rule\n\t\t\t// If a `national_prefix_for_parsing` has any \"capturing groups\"\n\t\t\t// then it means that the national (significant) number is equal to\n\t\t\t// those \"capturing groups\" transformed via `national_prefix_transform_rule`,\n\t\t\t// and nothing could be said about the actual national prefix:\n\t\t\t// what is it and was it even there.\n\t\t\t// If a `national_prefix_for_parsing` doesn't have any \"capturing groups\",\n\t\t\t// then everything it matches is a national prefix.\n\t\t\t// To determine whether `national_prefix_for_parsing` matched any\n\t\t\t// \"capturing groups\", the value of the result of calling `.exec()`\n\t\t\t// is looked at, and if it has non-undefined values where there're\n\t\t\t// \"capturing groups\" in the regular expression, then it means\n\t\t\t// that \"capturing groups\" have been matched.\n\t\t\t// It's not possible to tell whether there'll be any \"capturing gropus\"\n\t\t\t// before the matching process, because a `national_prefix_for_parsing`\n\t\t\t// could exhibit both behaviors.\n\t\t\tconst capturedGroupsCount = prefixMatch.length - 1\n\t\t\tconst hasCapturedGroups = capturedGroupsCount > 0 && prefixMatch[capturedGroupsCount]\n\t\t\tif (metadata.nationalPrefixTransformRule() && hasCapturedGroups) {\n\t\t\t\tnationalNumber = number.replace(\n\t\t\t\t\tprefixPattern,\n\t\t\t\t\tmetadata.nationalPrefixTransformRule()\n\t\t\t\t)\n\t\t\t\t// If there's more than one captured group,\n\t\t\t\t// then carrier code is the second one.\n\t\t\t\tif (capturedGroupsCount > 1) {\n\t\t\t\t\tcarrierCode = prefixMatch[1]\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If there're no \"capturing groups\",\n\t\t\t// or if there're \"capturing groups\" but no\n\t\t\t// `national_prefix_transform_rule`,\n\t\t\t// then just strip the national prefix from the number,\n\t\t\t// and possibly a carrier code.\n\t\t\t// Seems like there could be more.\n\t\t\telse {\n\t\t\t\t// `prefixBeforeNationalNumber` is the whole substring matched by\n\t\t\t\t// the `national_prefix_for_parsing` regular expression.\n\t\t\t\t// There seem to be no guarantees that it's just a national prefix.\n\t\t\t\t// For example, if there's a carrier code, it's gonna be a\n\t\t\t\t// part of `prefixBeforeNationalNumber` too.\n\t\t\t\tconst prefixBeforeNationalNumber = prefixMatch[0]\n\t\t\t\tnationalNumber = number.slice(prefixBeforeNationalNumber.length)\n\t\t\t\t// If there's at least one captured group,\n\t\t\t\t// then carrier code is the first one.\n\t\t\t\tif (hasCapturedGroups) {\n\t\t\t\t\tcarrierCode = prefixMatch[1]\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Tries to guess whether a national prefix was present in the input.\n\t\t\t// This is not something copy-pasted from Google's library:\n\t\t\t// they don't seem to have an equivalent for that.\n\t\t\t// So this isn't an \"officially approved\" way of doing something like that.\n\t\t\t// But since there seems no other existing method, this library uses it.\n\t\t\tlet nationalPrefix\n\t\t\tif (hasCapturedGroups) {\n\t\t\t\tconst possiblePositionOfTheFirstCapturedGroup = number.indexOf(prefixMatch[1])\n\t\t\t\tconst possibleNationalPrefix = number.slice(0, possiblePositionOfTheFirstCapturedGroup)\n\t\t\t\t// Example: an Argentinian (AR) phone number `0111523456789`.\n\t\t\t\t// `prefixMatch[0]` is `01115`, and `$1` is `11`,\n\t\t\t\t// and the rest of the phone number is `23456789`.\n\t\t\t\t// The national number is transformed via `9$1` to `91123456789`.\n\t\t\t\t// National prefix `0` is detected being present at the start.\n\t\t\t\t// if (possibleNationalPrefix.indexOf(metadata.numberingPlan.nationalPrefix()) === 0) {\n\t\t\t\tif (possibleNationalPrefix === metadata.numberingPlan.nationalPrefix()) {\n\t\t\t\t\tnationalPrefix = metadata.numberingPlan.nationalPrefix()\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnationalPrefix = prefixMatch[0]\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tnationalNumber,\n\t\t\t\tnationalPrefix,\n\t\t\t\tcarrierCode\n\t\t\t}\n\t\t}\n\t}\n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