{"version":3,"sources":["../source/AsYouType.js"],"names":["DUMMY_DIGIT","LONGEST_NATIONAL_PHONE_NUMBER_LENGTH","LONGEST_DUMMY_PHONE_NUMBER","repeat","DIGIT_PLACEHOLDER","DIGIT_PLACEHOLDER_MATCHER","RegExp","NATIONAL_PREFIX_SEPARATORS_PATTERN","SUPPORT_LEGACY_FORMATTING_PATTERNS","CREATE_CHARACTER_CLASS_PATTERN","CREATE_STANDALONE_DIGIT_PATTERN","ELIGIBLE_FORMAT_PATTERN","VALID_PUNCTUATION","MIN_LEADING_DIGITS_LENGTH","VALID_FORMATTED_PHONE_NUMBER_PART","VALID_DIGITS","VALID_FORMATTED_PHONE_NUMBER_PART_PATTERN","VALID_PHONE_NUMBER","PLUS_CHARS","AFTER_PHONE_NUMBER_DIGITS_END_PATTERN","USE_NON_GEOGRAPHIC_COUNTRY_CODE","AsYouType","optionsOrDefaultCountry","metadata","Metadata","defaultCountry","defaultCallingCode","hasCountry","isNonGeographicCallingCode","reset","formattedOutput","international","internationalPrefix","undefined","countryCallingCode","digits","nationalNumberDigits","nationalPrefix","carrierCode","setCountry","chosenFormat","template","populatedNationalNumberTemplate","populatedNationalNumberTemplatePosition","countryCode","country","callingCode","selectNumberingPlan","hasSelectedNumberingPlan","initializePhoneNumberFormatsForCountry","matchingFormats","resetFormat","text","formattedDigits","extractFormattedDigits","test","getFullNumber","inputDigits","getNonFormattedNationalNumber","extractedNumber","extractFormattedPhoneNumber","slice","length","startInternationalNumber","nextDigits","numberWithoutIDD","isInternational","isCountryCallingCodeAmbiguous","determineTheCountry","extractCountryCallingCode","previousNationalPrefix","extractNationalPrefix","matchFormats","formatNationalNumberWithNextDigits","formattedNumber","attemptToFormatCompletePhoneNumber","previouslyChosenFormat","newlyChosenFormat","chooseFormat","formatNextNationalNumberDigits","reformatNationalNumber","format","createFormattingTemplate","formats","filter","internationalFormat","leadingDigits","leadingDigitsPatternIndex","nationalPrefixIsMandatoryWhenFormattingInNationalFormat","leadingDigitsPatternsCount","leadingDigitsPatterns","Math","min","leadingDigitsPattern","indexOf","nationalPrefixFormattingRule","matcher","pattern","formattedNationalNumber","formattedNationalNumberWithNationalPrefix","getSeparatorAfterNationalPrefix","replace","options","spacing","prefix","getInternationalPrefix","number","chooseCountryByCountryCallingCode","nationalNumber","index","countryCodes","getCountryCodesForCallingCode","getTemplateForNumberFormatPattern","match","strictPattern","nationalNumberDummyDigits","numberFormat","getFormatFormat","includesNationalPrefix","numberFormatWithNationalPrefix","FIRST_GROUP_PATTERN","i","split","digit","search","cutAndStripNonPairedParens","getCountry","getCountryCallingCode","shorterNationalNumber","newCarrierCode","phoneNumber","PhoneNumber","getNumber","isPossible","isValid","getNonFormattedTemplate","stripNonPairedParens","string","dangling_braces","push","pop","start","cleared_string","cutBeforeIndex","closeNonPairedParens","cut_before","retained_template","opening_braces","countOccurences","closing_braces","symbol","count","character","times","result","startsAt","hasPlus"],"mappings":";;;;;;;;;;;;AAUA;;AAEA;;AAEA;;AAMA;;AAEA;;AAQA;;AAMA;;AAEA;;AAEA;;;;;;;;;;;;;;AAEA;AACA;AACA,IAAMA,WAAW,GAAG,GAApB,C,CACA;;AACA,IAAMC,oCAAoC,GAAG,EAA7C,C,CACA;AACA;;AACA,IAAMC,0BAA0B,GAAGC,MAAM,CAACH,WAAD,EAAcC,oCAAd,CAAzC,C,CAEA;AACA;;AACO,IAAMG,iBAAiB,GAAG,GAA1B,C,CAA8B;;;AACrC,IAAMC,yBAAyB,GAAG,IAAIC,MAAJ,CAAWF,iBAAX,CAAlC,C,CAEA;AACA;;AACA,IAAMG,kCAAkC,GAAG,MAA3C,C,CAEA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,kCAAkC,GAAG,IAA3C,C,CAEA;AACA;;AACA,IAAMC,8BAA8B,GAAGD,kCAAkC,IAAK;AAAA,SAAM,iBAAN;AAAA,CAA9E,C,CAEA;AACA;AACA;AACA;AACA;;;AACA,IAAME,+BAA+B,GAAGF,kCAAkC,IAAK;AAAA,SA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,MAAM,GAAGjB,MAAhB;AACA;AAED;;;;;;;AAKA,SAAS7E,2BAAT,CAAqCR,IAArC,EAA2C;AAC1C;AACA,MAAMuG,QAAQ,GAAGvG,IAAI,CAACwE,MAAL,CAAY3G,kBAAZ,CAAjB;;AACA,MAAI0I,QAAQ,GAAG,CAAf,EAAkB;AACjB;AACA,GALyC,CAM1C;;;AACAvG,EAAAA,IAAI,GAAGA,IAAI,CAACS,KAAL,CAAW8F,QAAX,CAAP,CAP0C,CAQ1C;;AACA,MAAIC,OAAJ;;AACA,MAAIxG,IAAI,CAAC,CAAD,CAAJ,KAAY,GAAhB,EAAqB;AACpBwG,IAAAA,OAAO,GAAG,IAAV;AACAxG,IAAAA,IAAI,GAAGA,IAAI,CAACS,KAAL,CAAW,IAAIC,MAAf,CAAP;AACA,GAbyC,CAc1C;;;AACAV,EAAAA,IAAI,GAAGA,IAAI,CAACiD,OAAL,CAAalF,qCAAb,EAAoD,EAApD,CAAP,CAf0C,CAgB1C;;AACA,MAAIyI,OAAJ,EAAa;AACZxG,IAAAA,IAAI,GAAG,MAAMA,IAAb;AACA;;AACD,SAAOA,IAAP;AACA","sourcesContent":["// This is an enhanced port of Google Android `libphonenumber`'s\r\n// `asyoutypeformatter.js` of December 31th, 2018.\r\n//\r\n// https://github.com/googlei18n/libphonenumber/blob/8d21a365061de2ba0675c878a710a7b24f74d2ae/javascript/i18n/phonenumbers/asyoutypeformatter.js\r\n//\r\n// Simplified: does not differentiate between \"local-only\" numbers\r\n// and \"internationally dialable\" numbers.\r\n// For example, doesn't include changes like this:\r\n// https://github.com/googlei18n/libphonenumber/commit/865da605da12b01053c4f053310bac7c5fbb7935\r\n\r\nimport Metadata from './metadata'\r\n\r\nimport PhoneNumber from './PhoneNumber'\r\n\r\nimport {\r\n\tVALID_DIGITS,\r\n\tVALID_PUNCTUATION,\r\n\tPLUS_CHARS\r\n} from './constants'\r\n\r\nimport { matchesEntirely } from './util'\r\n\r\nimport {\r\n\textractCountryCallingCode,\r\n\tfindCountryCode,\r\n\tstripNationalPrefixAndCarrierCode,\r\n\tstripNationalPrefixAndCarrierCodeFromCompleteNumber,\r\n\textractCountryCallingCodeFromInternationalNumberWithoutPlusSign\r\n} from './parse_'\r\n\r\nimport {\r\n\tFIRST_GROUP_PATTERN,\r\n\tformatNationalNumberUsingFormat,\r\n\tapplyInternationalSeparatorStyle\r\n} from './format_'\r\n\r\nimport { stripIDDPrefix } from './IDD'\r\n\r\nimport { checkNumberLengthForType } from './getNumberType_'\r\n\r\nimport parseDigits from './parseDigits'\r\n\r\n// Used in phone number format template creation.\r\n// Could be any digit, I guess.\r\nconst DUMMY_DIGIT = '9'\r\n// I don't know why is it exactly `15`\r\nconst LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15\r\n// Create a phone number consisting only of the digit 9 that matches the\r\n// `number_pattern` by applying the pattern to the \"longest phone number\" string.\r\nconst LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH)\r\n\r\n// The digits that have not been entered yet will be represented by a \\u2008,\r\n// the punctuation space.\r\nexport const DIGIT_PLACEHOLDER = 'x' // '\\u2008' (punctuation space)\r\nconst DIGIT_PLACEHOLDER_MATCHER = new RegExp(DIGIT_PLACEHOLDER)\r\n\r\n// A set of characters that, if found in a national prefix formatting rules, are an indicator to\r\n// us that we should separate the national prefix from the number when formatting.\r\nconst NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/\r\n\r\n// Deprecated: Google has removed some formatting pattern related code from their repo.\r\n// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c\r\n// \"We no longer have numbers in formatting matching patterns, only \\d.\"\r\n// Because this library supports generating custom metadata\r\n// some users may still be using old metadata so the relevant\r\n// code seems to stay until some next major version update.\r\nconst SUPPORT_LEGACY_FORMATTING_PATTERNS = true\r\n\r\n// A pattern that is used to match character classes in regular expressions.\r\n// An example of a character class is \"[1-4]\".\r\nconst CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\[([^\\[\\]])*\\]/g)\r\n\r\n// Any digit in a regular expression that actually denotes a digit. For\r\n// example, in the regular expression \"80[0-2]\\d{6,10}\", the first 2 digits\r\n// (8 and 0) are standalone digits, but the rest are not.\r\n// Two look-aheads are needed because the number following \\\\d could be a\r\n// two-digit number, since the phone number can be as long as 15 digits.\r\nconst CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\d(?=[^,}][^,}])/g)\r\n\r\n// A pattern that is used to determine if a `format` is eligible\r\n// to be used by the \"as you type formatter\".\r\n// It is eligible when the `format` contains groups of the dollar sign\r\n// followed by a single digit, separated by valid phone number punctuation.\r\n// This prevents invalid punctuation (such as the star sign in Israeli star numbers)\r\n// getting into the output of the \"as you type formatter\".\r\nconst ELIGIBLE_FORMAT_PATTERN = new RegExp(\r\n\t'^' +\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t'(\\\\$\\\\d[' + VALID_PUNCTUATION + ']*)+' +\r\n\t'$'\r\n)\r\n\r\n// This is the minimum length of the leading digits of a phone number\r\n// to guarantee the first \"leading digits pattern\" for a phone number format\r\n// to be preemptive.\r\nconst MIN_LEADING_DIGITS_LENGTH = 3\r\n\r\nconst VALID_FORMATTED_PHONE_NUMBER_PART =\r\n\t'[' +\r\n\t\tVALID_PUNCTUATION +\r\n\t\tVALID_DIGITS +\r\n\t']+'\r\n\r\nconst VALID_FORMATTED_PHONE_NUMBER_PART_PATTERN = new RegExp('^' + VALID_FORMATTED_PHONE_NUMBER_PART + '$', 'i')\r\n\r\nconst VALID_PHONE_NUMBER =\r\n\t'(?:' +\r\n\t\t'[' + PLUS_CHARS + ']' +\r\n\t\t'[' +\r\n\t\t\tVALID_PUNCTUATION +\r\n\t\t\tVALID_DIGITS +\r\n\t\t']*' +\r\n\t\t'|' +\r\n\t\t'[' +\r\n\t\t\tVALID_PUNCTUATION +\r\n\t\t\tVALID_DIGITS +\r\n\t\t']+' +\r\n\t')'\r\n\r\nconst AFTER_PHONE_NUMBER_DIGITS_END_PATTERN = new RegExp(\r\n\t'[^' +\r\n\t\tVALID_PUNCTUATION +\r\n\t\tVALID_DIGITS +\r\n\t']+' +\r\n\t'.*' +\r\n\t'$'\r\n)\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default class AsYouType {\r\n\t// Not setting `options` to a constructor argument\r\n\t// not to break backwards compatibility\r\n\t// for older versions of the library.\r\n\toptions = {}\r\n\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\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\tthis.defaultCountry = defaultCountry\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\tthis.defaultCountry = '001'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tthis.defaultCallingCode = defaultCallingCode\r\n\t\t}\r\n\t\t// Reset.\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.formattedOutput = ''\r\n\t\tthis.international = false\r\n\t\tthis.internationalPrefix = undefined\r\n\t\tthis.countryCallingCode = undefined\r\n\t\tthis.digits = ''\r\n\t\tthis.nationalNumberDigits = ''\r\n\t\tthis.nationalPrefix = ''\r\n\t\tthis.carrierCode = ''\r\n\t\tthis.setCountry(this.defaultCountry, this.defaultCallingCode)\r\n\t\treturn this\r\n\t}\r\n\r\n\tresetFormat() {\r\n\t\tthis.chosenFormat = undefined\r\n\t\tthis.template = undefined\r\n\t\tthis.populatedNationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\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.international\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the \"country calling code\" part of the phone number.\r\n\t * Returns `undefined` if the number is not being input in international format.\r\n\t * Returns \"country calling code\" for \"non-geographic\" phone numbering plans too.\r\n\t * @return {string} [countryCallingCode]\r\n\t */\r\n\tgetCountryCallingCode() {\r\n\t\treturn this.countryCallingCode\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\t// If no digits have been input yet,\r\n\t\t// then `this.country` is the `defaultCountry`.\r\n\t\t// Won't return the `defaultCountry` in such case.\r\n\t\tif (!this.digits) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tlet countryCode = this.country\r\n\t\t/* istanbul ignore if */\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\tif (this.country === '001') {\r\n\t\t\t\tcountryCode = undefined\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn countryCode\r\n\t}\r\n\r\n\tsetCountry(country, callingCode) {\r\n\t\tthis.country = country\r\n\t\tthis.metadata.selectNumberingPlan(country, callingCode)\r\n\t\tif (this.metadata.hasSelectedNumberingPlan()) {\r\n\t\t\tthis.initializePhoneNumberFormatsForCountry()\r\n\t\t} else {\r\n\t\t\tthis.matchingFormats = []\r\n\t\t}\r\n\t\tthis.resetFormat()\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 formattedDigits = this.extractFormattedDigits(text)\r\n\t\t// If the extracted phone number part\r\n\t\t// can possibly be a part of some valid phone number\r\n\t\t// then parse phone number characters from a formatted phone number.\r\n\t\tif (VALID_FORMATTED_PHONE_NUMBER_PART_PATTERN.test(formattedDigits)) {\r\n\t\t\tthis.formattedOutput = this.getFullNumber(\r\n\t\t\t\tthis.inputDigits(parseDigits(formattedDigits)) ||\r\n\t\t\t\tthis.getNonFormattedNationalNumber()\r\n\t\t\t)\r\n\t\t}\r\n\t\treturn this.formattedOutput\r\n\t}\r\n\r\n\t/**\r\n\t * Extracts formatted phone number digits from text (if there're any).\r\n\t * @param {string} text\r\n\t * @return {string}\r\n\t */\r\n\textractFormattedDigits(text) {\r\n\t\t// Extract a formatted phone number part from text.\r\n\t\tlet extractedNumber = extractFormattedPhoneNumber(text) || ''\r\n\t\t// Trim a `+`.\r\n\t\tif (extractedNumber[0] === '+') {\r\n\t\t\t// Trim the `+`.\r\n\t\t\textractedNumber = extractedNumber.slice('+'.length)\r\n\t\t\tif (this.digits) {\r\n\t\t\t\t// If an out of position `+` is detected\r\n\t\t\t\t// (or a second `+`) then just ignore it.\r\n\t\t\t} else {\r\n\t\t\t\tthis.formattedOutput = '+'\r\n\t\t\t\tthis.startInternationalNumber()\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn extractedNumber\r\n\t}\r\n\r\n\tstartInternationalNumber() {\r\n\t\t// Prepend the `+` to parsed input.\r\n\t\tthis.international = true\r\n\t\t// If a default country was set then reset it\r\n\t\t// because an explicitly international phone\r\n\t\t// number is being entered.\r\n\t\tthis.setCountry()\r\n\t}\r\n\r\n\t/**\r\n\t * Inputs \"next\" phone number digits.\r\n\t * @param {string} digits\r\n\t * @return {string} [formattedNumber] Formatted national phone number (if it can be formatted at this stage). Returning `undefined` means \"don't format the national phone number at this stage\".\r\n\t */\r\n\tinputDigits(nextDigits) {\r\n\t\t// Some users input their phone number in \"out-of-country\"\r\n\t\t// dialing format instead of using the leading `+`.\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/185\r\n\t\t// Detect such numbers.\r\n\t\tif (!this.digits) {\r\n\t\t\tconst numberWithoutIDD = stripIDDPrefix(\r\n\t\t\t\tnextDigits,\r\n\t\t\t\tthis.defaultCountry,\r\n\t\t\t\tthis.defaultCallingCode,\r\n\t\t\t\tthis.metadata.metadata\r\n\t\t\t)\r\n\t\t\tif (numberWithoutIDD && numberWithoutIDD !== nextDigits) {\r\n\t\t\t\t// If an IDD prefix was stripped then\r\n\t\t\t\t// convert the number to international one\r\n\t\t\t\t// for subsequent parsing.\r\n\t\t\t\tthis.internationalPrefix = nextDigits.slice(0, nextDigits.length - numberWithoutIDD.length)\r\n\t\t\t\tnextDigits = numberWithoutIDD\r\n\t\t\t\tthis.startInternationalNumber()\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Append phone number digits.\r\n\t\tthis.digits += nextDigits\r\n\t\t// Try to format the parsed input\r\n\t\tif (this.isInternational()) {\r\n\t\t\tif (this.countryCallingCode) {\r\n\t\t\t\tthis.nationalNumberDigits += nextDigits\r\n\t\t\t\t// `this.country` could be `undefined`, for example, when there is\r\n\t\t\t\t// ambiguity in a form of several different countries,\r\n\t\t\t\t// each corresponding to the same country phone code\r\n\t\t\t\t// (e.g. NANPA: USA, Canada, etc), and there's not enough digits\r\n\t\t\t\t// to reliably determine the country the phone number belongs to.\r\n\t\t\t\t// Therefore, in cases of such ambiguity, each time something is input,\r\n\t\t\t\t// try to determine the country (if it hasn't been determined yet).\r\n\t\t\t\tif (!this.country || this.isCountryCallingCodeAmbiguous()) {\r\n\t\t\t\t\tthis.determineTheCountry()\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\t// Extract country calling code from the digits entered so far.\r\n\t\t\t\t// There must be some digits in order to extract anything from them.\r\n\t\t\t\t//\r\n\t\t\t\t// If one looks at country phone codes\r\n\t\t\t\t// then they can notice that no one country phone code\r\n\t\t\t\t// is ever a (leftmost) substring of another country phone code.\r\n\t\t\t\t// So if a valid country code is extracted so far\r\n\t\t\t\t// then it means that this is the country code.\r\n\t\t\t\t//\r\n\t\t\t\t// If no country phone code could be extracted so far,\r\n\t\t\t\t// then don't format the phone number.\r\n\t\t\t\t//\r\n\t\t\t\tif (!this.extractCountryCallingCode()) {\r\n\t\t\t\t\t// Don't format the phone number.\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\t\t\t\t// Possibly extract a national prefix.\r\n\t\t\t\t// Some people incorrectly input national prefix\r\n\t\t\t\t// in an international phone number.\r\n\t\t\t\t// For example, some people write British phone numbers as `+44(0)...`.\r\n\t\t\t\t// Also, mobile phone numbers in Mexico are supposed to be dialled\r\n\t\t\t\t// internationally using a `15` national prefix.\r\n\t\t\t\t//\r\n\t\t\t\t// https://www.mexperience.com/dialing-cell-phones-in-mexico/\r\n\t\t\t\t//\r\n\t\t\t\t// \"Dialing a Mexican cell phone from abroad\r\n\t\t\t\t// When you are calling a cell phone number in Mexico from outside Mexico,\r\n\t\t\t\t// it’s necessary to dial an additional “1” after Mexico’s country code\r\n\t\t\t\t// (which is “52”) and before the area code.\r\n\t\t\t\t// You also ignore the 045, and simply dial the area code and the\r\n\t\t\t\t// cell phone’s number.\r\n\t\t\t\t//\r\n\t\t\t\t// If you don’t add the “1”, you’ll receive a recorded announcement\r\n\t\t\t\t// asking you to redial using it.\r\n\t\t\t\t//\r\n\t\t\t\t// For example, if you are calling from the USA to a cell phone\r\n\t\t\t\t// in Mexico City, you would dial +52 – 1 – 55 – 1234 5678.\r\n\t\t\t\t// (Note that this is different to calling a land line in Mexico City\r\n\t\t\t\t// from abroad, where the number dialed would be +52 – 55 – 1234 5678)\".\r\n\t\t\t\t//\r\n\t\t\t\tthis.nationalNumberDigits = this.digits.slice(this.countryCallingCode.length)\r\n\t\t\t\t// this.extractNationalPrefix()\r\n\t\t\t\t//\r\n\t\t\t\t// Determine the country from country calling code and national number.\r\n\t\t\t\tthis.determineTheCountry()\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tthis.nationalNumberDigits += nextDigits\r\n\t\t\t// If `defaultCallingCode` is set,\r\n\t\t\t// see if the `country` could be derived.\r\n\t\t\tif (!this.country) {\r\n\t\t\t\tthis.determineTheCountry()\r\n\t\t\t}\r\n\t\t\t// Some national prefixes are substrings of other national prefixes\r\n\t\t\t// (for the same country), therefore try to extract national prefix each time\r\n\t\t\t// because a longer national prefix might be available at some point in time.\r\n\t\t\tconst previousNationalPrefix = this.nationalPrefix\r\n\t\t\tthis.nationalNumberDigits = this.nationalPrefix + this.nationalNumberDigits\r\n\t\t\t// Re-extract national prefix.\r\n\t\t\tthis.extractNationalPrefix()\r\n\t\t\t// If another national prefix has been extracted.\r\n\t\t\tif (this.nationalPrefix !== previousNationalPrefix) {\r\n\t\t\t\t// National number has changed\r\n\t\t\t\t// (due to another national prefix been extracted)\r\n\t\t\t\t// therefore national number has changed\r\n\t\t\t\t// therefore reset all previous formatting data.\r\n\t\t\t\t// (and leading digits matching state)\r\n\t\t\t\tthis.initializePhoneNumberFormatsForCountry()\r\n\t\t\t\tthis.resetFormat()\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (this.nationalNumberDigits) {\r\n\t\t\t// Match the available formats by the currently available leading digits.\r\n\t\t\tthis.matchFormats(this.nationalNumberDigits)\r\n\t\t}\r\n\r\n\t\t// Format the phone number (given the next digits)\r\n\t\treturn this.formatNationalNumberWithNextDigits(nextDigits)\r\n\t}\r\n\r\n\tformatNationalNumberWithNextDigits(nextDigits) {\r\n\t\t// See if the phone number digits can be formatted as a complete phone number.\r\n\t\t// If not, use the results from `formatNextNationalNumberDigits()`,\r\n\t\t// which formats based on the chosen formatting pattern.\r\n\t\t// Attempting to format complete phone number first is how it's done\r\n\t\t// in Google's `libphonenumber`.\r\n\t\tconst formattedNumber = this.attemptToFormatCompletePhoneNumber()\r\n\r\n\t\t// Just because a phone number doesn't have a suitable format\r\n\t\t// that doesn't mean that the phone number is invalid,\r\n\t\t// because phone number formats only format phone numbers,\r\n\t\t// they don't validate them and some (rare) phone numbers\r\n\t\t// are meant to stay non-formatted.\r\n\t\tif (formattedNumber) {\r\n\t\t\treturn formattedNumber\r\n\t\t}\r\n\r\n\t\t// Format the next phone number digits\r\n\t\t// using the previously chosen phone number format.\r\n\t\t//\r\n\t\t// This is done here because if `attemptToFormatCompletePhoneNumber`\r\n\t\t// was placed before this call then the `template`\r\n\t\t// wouldn't reflect the situation correctly (and would therefore be inconsistent)\r\n\t\t//\r\n\t\tconst previouslyChosenFormat = this.chosenFormat\r\n\t\t// Choose a format from the list of matching ones.\r\n\t\tconst newlyChosenFormat = this.chooseFormat()\r\n\t\tif (newlyChosenFormat) {\r\n\t\t\tif (newlyChosenFormat === previouslyChosenFormat) {\r\n\t\t\t\t// If could format the next (current) digit\r\n\t\t\t\t// using the previously chosen phone number format\r\n\t\t\t\t// then return the formatted number so far.\r\n\t\t\t\t//\r\n\t\t\t\t// If no new phone number format could be chosen,\r\n\t\t\t\t// and couldn't format the supplied national number\r\n\t\t\t\t// using the previously chosen phone number pattern,\r\n\t\t\t\t// then return `undefined`.\r\n\t\t\t\t//\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(nextDigits)\r\n\t\t\t} else {\r\n\t\t\t\t// If a more appropriate phone number format\r\n\t\t\t\t// has been chosen for these \"leading digits\",\r\n\t\t\t\t// then format the national phone number (so far)\r\n\t\t\t\t// using the newly selected format.\r\n\t\t\t\t//\r\n\t\t\t\t// Will return `undefined` if it couldn't format\r\n\t\t\t\t// the supplied national number\r\n\t\t\t\t// using the selected phone number pattern.\r\n\t\t\t\t//\r\n\t\t\t\treturn this.reformatNationalNumber()\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tchooseFormat() {\r\n\t\t// When there are multiple available formats, the formatter uses the first\r\n\t\t// format where a formatting template could be created.\r\n\t\tfor (const format of this.matchingFormats) {\r\n\t\t\t// If this format is currently being used\r\n\t\t\t// and is still possible, then stick to it.\r\n\t\t\tif (this.chosenFormat === format) {\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\tif (!this.createFormattingTemplate(format)) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tthis.chosenFormat = format\r\n\t\t\t// With a new formatting template, the matched position\r\n\t\t\t// using the old template needs to be reset.\r\n\t\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tif (!this.chosenFormat) {\r\n\t\t\t// No format matches the national phone number entered.\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t\treturn this.chosenFormat\r\n\t}\r\n\r\n\t// Formats each digit of the national phone number (so far)\r\n\t// using the selected format.\r\n\treformatNationalNumber() {\r\n\t\treturn this.formatNextNationalNumberDigits(\r\n\t\t\tthis.nationalPrefix + this.nationalNumberDigits\r\n\t\t)\r\n\t}\r\n\r\n\tinitializePhoneNumberFormatsForCountry() {\r\n\t\t// Get all \"eligible\" phone number formats for this country\r\n\t\tthis.matchingFormats = this.metadata.formats().filter((format) => {\r\n\t\t\t// Compared to `libphonenumber`'s code, the two \"Discard a few formats\r\n\t\t\t// that we know are not relevant based on the presence of the national prefix\"\r\n\t\t\t// checks have changed: the first one has been moved to `.matchFormats()`,\r\n\t\t\t// and the second one doesn't apply to this library because it doesn't deal with\r\n\t\t\t// \"incomplete\" phone numbers (for example, phone numbers, entered without \"area code\").\r\n\t\t\treturn ELIGIBLE_FORMAT_PATTERN.test(format.internationalFormat())\r\n\t\t})\r\n\t}\r\n\r\n\tmatchFormats(leadingDigits) {\r\n\t\t// \"leading digits\" pattern list starts with a\r\n\t\t// \"leading digits\" pattern fitting a maximum of 3 leading digits.\r\n\t\t// So, after a user inputs 3 digits of a national (significant) phone number\r\n\t\t// this national (significant) number can already be formatted.\r\n\t\t// The next \"leading digits\" pattern is for 4 leading digits max,\r\n\t\t// and the \"leading digits\" pattern after it is for 5 leading digits max, etc.\r\n\r\n\t\t// This implementation is different from Google's\r\n\t\t// in that it searches for a fitting format\r\n\t\t// even if the user has entered less than\r\n\t\t// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.\r\n\t\t// Because some leading digit patterns already match for a single first digit.\r\n\t\tlet leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH\r\n\t\tif (leadingDigitsPatternIndex < 0) {\r\n\t\t\tleadingDigitsPatternIndex = 0\r\n\t\t}\r\n\r\n\t\tthis.matchingFormats = this.matchingFormats.filter((format) => {\r\n\t\t\t// If national prefix is mandatory for this phone number format\r\n\t\t\t// and the user didn't input the national prefix\r\n\t\t\t// then this phone number format isn't suitable.\r\n\t\t\tif (!this.isInternational() && !this.nationalPrefix && format.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {\r\n\t\t\t\treturn false\r\n\t\t\t}\r\n\t\t\tconst leadingDigitsPatternsCount = format.leadingDigitsPatterns().length\r\n\t\t\t// If this format is not restricted to a certain\r\n\t\t\t// leading digits pattern then it fits.\r\n\t\t\tif (leadingDigitsPatternsCount === 0) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t\t// Start excluding any non-matching formats only when the\r\n\t\t\t// national number entered so far is at least 3 digits long,\r\n\t\t\t// otherwise format matching would give false negatives.\r\n\t\t\t// For example, when the digits entered so far are `2`\r\n\t\t\t// and the leading digits pattern is `21` –\r\n\t\t\t// it's quite obvious in this case that the format could be the one\r\n\t\t\t// but due to the absence of further digits it would give false negative.\r\n\t\t\tif (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t\t// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are available\r\n\t\t\t// then format matching starts narrowing down the list of possible formats\r\n\t\t\t// (only previously matched formats are considered for next digits).\r\n\t\t\tleadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1)\r\n\t\t\tconst leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]\r\n\t\t\t// Brackets are required for `^` to be applied to\r\n\t\t\t// all or-ed (`|`) parts, not just the first one.\r\n\t\t\treturn new RegExp(`^(${leadingDigitsPattern})`).test(leadingDigits)\r\n\t\t})\r\n\r\n\t\t// If there was a phone number format chosen\r\n\t\t// and it no longer holds given the new leading digits then reset it.\r\n\t\t// The test for this `if` condition is marked as:\r\n\t\t// \"Reset a chosen format when it no longer holds given the new leading digits\".\r\n\t\t// To construct a valid test case for this one can find a country\r\n\t\t// in `PhoneNumberMetadata.xml` yielding one format for 3 ``\r\n\t\t// and yielding another format for 4 `` (Australia in this case).\r\n\t\tif (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t}\r\n\r\n\tgetSeparatorAfterNationalPrefix(format) {\r\n\t\tif (this.metadata.countryCallingCode() === '1') {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\tif (format &&\r\n\t\t\tformat.nationalPrefixFormattingRule() &&\r\n\t\t\tNATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\treturn ''\r\n\t}\r\n\r\n\t// This is in accordance to how Google's `libphonenumber` does it.\r\n\t// \"Check to see if there is an exact pattern match for these digits.\r\n\t// If so, we should use this instead of any other formatting template\r\n\t// whose `leadingDigitsPattern` also matches the input.\"\r\n\tattemptToFormatCompletePhoneNumber() {\r\n\t\tfor (const format of this.matchingFormats) {\r\n\t\t\tconst matcher = new RegExp(`^(?:${format.pattern()})$`)\r\n\t\t\tif (!matcher.test(this.nationalNumberDigits)) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\t// Here, national number is formatted without \"national prefix\r\n\t\t\t// formatting rule\", because otherwise there'd be a bug\r\n\t\t\t// when \"area code\" is \"duplicated\" during input:\r\n\t\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/318\r\n\t\t\tlet formattedNationalNumber = formatNationalNumberUsingFormat(\r\n\t\t\t\tthis.nationalNumberDigits,\r\n\t\t\t\tformat,\r\n\t\t\t\tthis.isInternational(),\r\n\t\t\t\tfalse, // Don't prepend national prefix (it will be prepended manually).\r\n\t\t\t\tthis.metadata\r\n\t\t\t)\r\n\t\t\t// Check if this `format` preserves all digits.\r\n\t\t\t// This is how it's done in Google's `libphonenumber`.\r\n\t\t\t// Also, it fixes the bug when \"area code\" is \"duplicated\" during input:\r\n\t\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/318\r\n\t\t\t//\r\n\t\t\t// \"Check that we didn't remove nor add any extra digits when we matched\r\n\t\t\t// this formatting pattern. This usually happens after we entered the last\r\n\t\t\t// digit during AYTF. Eg: In case of MX, we swallow mobile token (1) when\r\n\t\t\t// formatted but AYTF should retain all the number entered and not change\r\n\t\t\t// in order to match a format (of same leading digits and length) display\r\n\t\t\t// in that way.\"\r\n\t\t\t// \"If it's the same (i.e entered number and format is same), then it's\r\n\t\t\t// safe to return this in formatted number as nothing is lost / added.\"\r\n\t\t\t// Otherwise, don't use this format.\r\n\t\t\t// https://github.com/google/libphonenumber/commit/3e7c1f04f5e7200f87fb131e6f85c6e99d60f510#diff-9149457fa9f5d608a11bb975c6ef4bc5\r\n\t\t\t// https://github.com/google/libphonenumber/commit/3ac88c7106e7dcb553bcc794b15f19185928a1c6#diff-2dcb77e833422ee304da348b905cde0b\r\n\t\t\t//\r\n\t\t\tif (parseDigits(formattedNationalNumber) !== this.nationalNumberDigits) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\t// Prepend national prefix (if any).\r\n\t\t\tif (this.nationalPrefix) {\r\n\t\t\t\t// Here, national number is formatted with \"national prefix\r\n\t\t\t\t// formatting rule\". The reason is that \"national prefix\r\n\t\t\t\t// formatting rule\" often adds parentheses, and while Google's\r\n\t\t\t\t// `libphonenumber` dismisses those preferring simply prepending\r\n\t\t\t\t// national prefix followed by a \" \" character, this library\r\n\t\t\t\t// looks if the national prefix could be formatted better.\r\n\t\t\t\tconst formattedNationalNumberWithNationalPrefix = formatNationalNumberUsingFormat(\r\n\t\t\t\t\tthis.nationalNumberDigits,\r\n\t\t\t\t\tformat,\r\n\t\t\t\t\tthis.isInternational(),\r\n\t\t\t\t\ttrue, // Prepend national prefix.\r\n\t\t\t\t\tthis.metadata\r\n\t\t\t\t)\r\n\t\t\t\tif (parseDigits(formattedNationalNumberWithNationalPrefix) === this.nationalPrefix + this.nationalNumberDigits) {\r\n\t\t\t\t\tformattedNationalNumber = formattedNationalNumberWithNationalPrefix\r\n\t\t\t\t} else {\r\n\t\t\t\t\tformattedNationalNumber = this.nationalPrefix +\r\n\t\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\r\n\t\t\t\t\t\tformattedNationalNumber\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// formats national number (probably) without national prefix.\r\n\t\t\t// Formatting a national number with national prefix could result in\r\n\t\t\t// bugs when \"area code\" is \"duplicated\" during input:\r\n\t\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/318\r\n\t\t\t// The \"are all digits preserved\" check fixes that type of bug.\r\n\r\n\t\t\t// To leave the formatter in a consistent state\r\n\t\t\tthis.resetFormat()\r\n\t\t\tthis.chosenFormat = format\r\n\t\t\t// Set `this.template` and `this.populatedNationalNumberTemplate`.\r\n\t\t\t/* istanbul ignore else */\r\n\t\t\tif (this.createFormattingTemplate(format)) {\r\n\t\t\t\t// Populate `this.populatedNationalNumberTemplate` with phone number digits.\r\n\t\t\t\tthis.reformatNationalNumber()\r\n\t\t\t} else {\r\n\t\t\t\t// If the formatting template couldn't be created for a format,\r\n\t\t\t\t// create it manually from the formatted phone number.\r\n\t\t\t\t// This case doesn't ever happen with the current metadata.\r\n\t\t\t\tthis.template = this.getFullNumber(formattedNationalNumber).replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER)\r\n\t\t\t\tthis.populatedNationalNumberTemplate = formattedNationalNumber\r\n\t\t\t\tthis.populatedNationalNumberTemplatePosition = this.populatedNationalNumberTemplate.length - 1\r\n\t\t\t}\r\n\t\t\treturn formattedNationalNumber\r\n\t\t}\r\n\t}\r\n\r\n\tgetInternationalPrefix(options) {\r\n\t\treturn this.internationalPrefix ? (\r\n\t\t\toptions && options.spacing === false ? this.internationalPrefix : this.internationalPrefix + ' '\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 = this.getInternationalPrefix()\r\n\t\t\tif (!this.countryCallingCode) {\r\n\t\t\t\treturn `${prefix}${this.digits}`\r\n\t\t\t}\r\n\t\t\tif (!formattedNationalNumber) {\r\n\t\t\t\treturn `${prefix}${this.countryCallingCode}`\r\n\t\t\t}\r\n\t\t\treturn `${prefix}${this.countryCallingCode} ${formattedNationalNumber}`\r\n\t\t}\r\n\t\treturn formattedNationalNumber\r\n\t}\r\n\r\n\tgetNonFormattedNationalNumber() {\r\n\t\treturn this.nationalPrefix +\r\n\t\t\t(this.nationalPrefix && this.nationalNumberDigits && this.getSeparatorAfterNationalPrefix()) +\r\n\t\t\tthis.nationalNumberDigits\r\n\t}\r\n\r\n\t// Extracts the country calling code from the beginning\r\n\t// of the entered `national_number` (so far),\r\n\t// and places the remaining input into the `national_number`.\r\n\textractCountryCallingCode() {\r\n\t\tconst {\r\n\t\t\tcountryCallingCode,\r\n\t\t\tnumber\r\n\t\t} = extractCountryCallingCode(\r\n\t\t\t'+' + this.digits,\r\n\t\t\tthis.defaultCountry,\r\n\t\t\tthis.defaultCallingCode,\r\n\t\t\tthis.metadata.metadata\r\n\t\t)\r\n\t\tif (!countryCallingCode) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tthis.nationalNumberDigits = number\r\n\t\tthis.countryCallingCode = countryCallingCode\r\n\t\tthis.metadata.chooseCountryByCountryCallingCode(countryCallingCode)\r\n\t\tthis.initializePhoneNumberFormatsForCountry()\r\n\t\tthis.resetFormat()\r\n\t\treturn this.metadata.hasSelectedNumberingPlan()\r\n\t}\r\n\r\n\textractNationalPrefix() {\r\n\t\tthis.nationalPrefix = ''\r\n\t\tif (!this.metadata.hasSelectedNumberingPlan()) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Only strip national prefixes for non-international phone numbers\r\n\t\t// because national prefixes can't be present in international phone numbers.\r\n\t\t// While `parseNumber()` is forgiving is such cases, `AsYouType` is not.\r\n\t\tconst {\r\n\t\t\tnationalNumber,\r\n\t\t\tcarrierCode\r\n\t\t} = stripNationalPrefixAndCarrierCode(\r\n\t\t\tthis.nationalNumberDigits,\r\n\t\t\tthis.metadata\r\n\t\t)\r\n\t\t// Sometimes `stripNationalPrefixAndCarrierCode()` won't actually\r\n\t\t// strip national prefix and will instead prepend some digits to the `number`:\r\n\t\t// for example, when number `2345678` is passed with `VI` country selected,\r\n\t\t// it will return `{ number: \"3402345678\" }`, because `340` area code is prepended.\r\n\t\t// So check if the `nationalNumber` is actually at the end of `this.nationalNumberDigits`.\r\n\t\tif (nationalNumber) {\r\n\t\t\tconst index = this.nationalNumberDigits.indexOf(nationalNumber)\r\n\t\t\tif (index < 0 || index !== this.nationalNumberDigits.length - nationalNumber.length) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (carrierCode) {\r\n\t\t\tthis.carrierCode = carrierCode\r\n\t\t}\r\n\t\tthis.nationalPrefix = this.nationalNumberDigits.slice(0, this.nationalNumberDigits.length - nationalNumber.length)\r\n\t\tthis.nationalNumberDigits = nationalNumber\r\n\t\treturn this.nationalPrefix\r\n\t}\r\n\r\n\t// isPossibleNumber(number) {\r\n\t// \tswitch (checkNumberLengthForType(number, undefined, this.metadata)) {\r\n\t// \t\tcase 'IS_POSSIBLE':\r\n\t// \t\t\treturn true\r\n\t// \t\t// case 'IS_POSSIBLE_LOCAL_ONLY':\r\n\t// \t\t// \treturn !this.isInternational()\r\n\t// \t\tdefault:\r\n\t// \t\t\treturn false\r\n\t// \t}\r\n\t// }\r\n\r\n\tisCountryCallingCodeAmbiguous() {\r\n\t\tconst countryCodes = this.metadata.getCountryCodesForCallingCode(this.countryCallingCode)\r\n\t\treturn countryCodes && countryCodes.length > 1\r\n\t}\r\n\r\n\tcreateFormattingTemplate(format) {\r\n\t\t// The formatter doesn't format numbers when numberPattern contains '|', e.g.\r\n\t\t// (20|3)\\d{4}. In those cases we quickly return.\r\n\t\t// (Though there's no such format in current metadata)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Get formatting template for this phone number format\r\n\t\tlet template = this.getTemplateForNumberFormatPattern(format, this.nationalPrefix)\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (!template) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tthis.template = template\r\n\t\tthis.populatedNationalNumberTemplate = template\r\n\t\t// For convenience, the public `.template` property\r\n\t\t// contains the whole international number\r\n\t\t// if the phone number being input is international:\r\n\t\t// 'x' for the '+' sign, 'x'es for the country phone code,\r\n\t\t// a spacebar and then the template for the formatted national number.\r\n\t\tif (this.isInternational()) {\r\n\t\t\tthis.template =\r\n\t\t\t\tthis.getInternationalPrefix().replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER) +\r\n\t\t\t\trepeat(DIGIT_PLACEHOLDER, this.countryCallingCode.length) +\r\n\t\t\t\t' ' +\r\n\t\t\t\ttemplate\r\n\t\t}\r\n\t\treturn this.template\r\n\t}\r\n\r\n\t/**\r\n\t * Generates formatting template for a national phone number,\r\n\t * optionally containing a national prefix, for a format.\r\n\t * @param {Format} format\r\n\t * @param {string} nationalPrefix\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplateForNumberFormatPattern(format, nationalPrefix) {\r\n\t\tlet pattern = format.pattern()\r\n\r\n\t\t/* istanbul ignore else */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS) {\r\n\t\t\tpattern = pattern\r\n\t\t\t\t// Replace anything in the form of [..] with \\d\r\n\t\t\t\t.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\\\d')\r\n\t\t\t\t// Replace any standalone digit (not the one in `{}`) with \\d\r\n\t\t\t\t.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\\\d')\r\n\t\t}\r\n\r\n\t\t// Generate a dummy national number (consisting of `9`s)\r\n\t\t// that fits this format's `pattern`.\r\n\t\t//\r\n\t\t// This match will always succeed,\r\n\t\t// because the \"longest dummy phone number\"\r\n\t\t// has enough length to accomodate any possible\r\n\t\t// national phone number format pattern.\r\n\t\t//\r\n\t\tlet digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]\r\n\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (this.nationalNumberDigits.length > digits.length) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// Get a formatting template which can be used to efficiently format\r\n\t\t// a partial number where digits are added one by one.\r\n\r\n\t\t// Below `strictPattern` is used for the\r\n\t\t// regular expression (with `^` and `$`).\r\n\t\t// This wasn't originally in Google's `libphonenumber`\r\n\t\t// and I guess they don't really need it\r\n\t\t// because they're not using \"templates\" to format phone numbers\r\n\t\t// but I added `strictPattern` after encountering\r\n\t\t// South Korean phone number formatting bug.\r\n\t\t//\r\n\t\t// Non-strict regular expression bug demonstration:\r\n\t\t//\r\n\t\t// this.nationalNumberDigits : `111111111` (9 digits)\r\n\t\t//\r\n\t\t// pattern : (\\d{2})(\\d{3,4})(\\d{4})\r\n\t\t// format : `$1 $2 $3`\r\n\t\t// digits : `9999999999` (10 digits)\r\n\t\t//\r\n\t\t// '9999999999'.replace(new RegExp(/(\\d{2})(\\d{3,4})(\\d{4})/g), '$1 $2 $3') = \"99 9999 9999\"\r\n\t\t//\r\n\t\t// template : xx xxxx xxxx\r\n\t\t//\r\n\t\t// But the correct template in this case is `xx xxx xxxx`.\r\n\t\t// The template was generated incorrectly because of the\r\n\t\t// `{3,4}` variability in the `pattern`.\r\n\t\t//\r\n\t\t// The fix is, if `this.nationalNumberDigits` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then `this.nationalNumberDigits`\r\n\t\t// is used instead of `digits`.\r\n\r\n\t\tconst strictPattern = new RegExp('^' + pattern + '$')\r\n\t\tconst nationalNumberDummyDigits = this.nationalNumberDigits.replace(/\\d/g, DUMMY_DIGIT)\r\n\r\n\t\t// If `this.nationalNumberDigits` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then use it\r\n\t\t// instead of `digits`.\r\n\t\tif (strictPattern.test(nationalNumberDummyDigits)) {\r\n\t\t\tdigits = nationalNumberDummyDigits\r\n\t\t}\r\n\r\n\t\tlet numberFormat = this.getFormatFormat(format)\r\n\t\tlet includesNationalPrefix\r\n\r\n\t\tif (nationalPrefix) {\r\n\t\t\tif (format.nationalPrefixFormattingRule()) {\r\n\t\t\t\tconst numberFormatWithNationalPrefix = numberFormat.replace(\r\n\t\t\t\t\tFIRST_GROUP_PATTERN,\r\n\t\t\t\t\tformat.nationalPrefixFormattingRule()\r\n\t\t\t\t)\r\n\t\t\t\tif (parseDigits(numberFormatWithNationalPrefix) === nationalPrefix + parseDigits(numberFormat)) {\r\n\t\t\t\t\tnumberFormat = numberFormatWithNationalPrefix\r\n\t\t\t\t\tincludesNationalPrefix = true\r\n\t\t\t\t\tlet i = nationalPrefix.length\r\n\t\t\t\t\twhile (i > 0) {\r\n\t\t\t\t\t\tnumberFormat = numberFormat.replace(/\\d/, DIGIT_PLACEHOLDER)\r\n\t\t\t\t\t\ti--\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\t// Generate formatting template for this phone number format.\r\n\t\tlet template = digits\r\n\t\t\t// Format the dummy phone number according to the format.\r\n\t\t\t.replace(new RegExp(pattern), numberFormat)\r\n\t\t\t// Replace each dummy digit with a DIGIT_PLACEHOLDER.\r\n\t\t\t.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)\r\n\r\n\t\tif (nationalPrefix) {\r\n\t\t\tif (!includesNationalPrefix) {\r\n\t\t\t\t// Prepend national prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +\r\n\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\r\n\t\t\t\t\ttemplate\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn template\r\n\t}\r\n\r\n\tformatNextNationalNumberDigits(digits) {\r\n\t\t// Using `.split('')` to iterate through a string here\r\n\t\t// to avoid requiring `Symbol.iterator` polyfill.\r\n\t\t// `.split('')` is generally not safe for Unicode,\r\n\t\t// but in this particular case for `digits` it is safe.\r\n\t\t// for (const digit of digits)\r\n\t\tfor (const digit of digits.split('')) {\r\n\t\t\t// If there is room for more digits in current `template`,\r\n\t\t\t// then set the next digit in the `template`,\r\n\t\t\t// and return the formatted digits so far.\r\n\t\t\t// If more digits are entered than the current format could handle.\r\n\t\t\tif (this.populatedNationalNumberTemplate.slice(this.populatedNationalNumberTemplatePosition + 1).search(DIGIT_PLACEHOLDER_MATCHER) < 0) {\r\n\t\t\t\t// Reset the format.\r\n\t\t\t\tthis.resetFormat()\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\r\n\t\t\tthis.populatedNationalNumberTemplatePosition = this.populatedNationalNumberTemplate.search(DIGIT_PLACEHOLDER_MATCHER)\r\n\t\t\tthis.populatedNationalNumberTemplate = this.populatedNationalNumberTemplate.replace(DIGIT_PLACEHOLDER_MATCHER, digit)\r\n\t\t}\r\n\r\n\t\t// Return the formatted phone number so far.\r\n\t\treturn cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\r\n\t\t// The old way which was good for `input-format` but is not so good\r\n\t\t// for `react-phone-number-input`'s default input (`InputBasic`).\r\n\t\t// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\t\t// \t.replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')\r\n\t}\r\n\r\n\tgetFormatFormat(format) {\r\n\t\tif (this.isInternational()) {\r\n\t\t\treturn applyInternationalSeparatorStyle(format.internationalFormat())\r\n\t\t}\r\n\t\treturn format.format()\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.country = findCountryCode(\r\n\t\t\tthis.isInternational() ? this.countryCallingCode : this.defaultCallingCode,\r\n\t\t\tthis.nationalNumberDigits,\r\n\t\t\tthis.metadata\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\tif (this.isInternational()) {\r\n\t\t\tif (!this.countryCallingCode) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tif (!this.country && !this.defaultCallingCode) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (!this.nationalNumberDigits) {\r\n\t\t\treturn undefined\r\n\t\t}\r\n\t\tlet countryCode = this.getCountry()\r\n\t\tconst callingCode = this.getCountryCallingCode() || this.defaultCallingCode\r\n\t\tlet nationalNumber = this.nationalNumberDigits\r\n\t\tlet carrierCode = this.carrierCode\r\n\t\t// When an international number without a leading `+` has been autocorrected,\r\n\t\t// extract country calling code, because normally it's only extracted\r\n\t\t// for international numbers with a leading `+`.\r\n\t\t// Could also just use `parsePhoneNumberFromString()` here\r\n\t\t// instead of hacking around this single case.\r\n\t\tif (!this.isInternational() && this.nationalNumberDigits === this.digits) {\r\n\t\t\tconst {\r\n\t\t\t\tcountryCallingCode,\r\n\t\t\t\tnumber\r\n\t\t\t} = extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(\r\n\t\t\t\tthis.digits,\r\n\t\t\t\tcountryCode,\r\n\t\t\t\tcallingCode,\r\n\t\t\t\tthis.metadata.metadata\r\n\t\t\t)\r\n\t\t\tif (countryCallingCode) {\r\n\t\t\t\tconst {\r\n\t\t\t\t\tnationalNumber: shorterNationalNumber,\r\n\t\t\t\t\tcarrierCode: newCarrierCode\r\n\t\t\t\t} = stripNationalPrefixAndCarrierCodeFromCompleteNumber(\r\n\t\t\t\t\tnumber,\r\n\t\t\t\t\tthis.metadata\r\n\t\t\t\t)\r\n\t\t\t\tnationalNumber = shorterNationalNumber\r\n\t\t\t\tcarrierCode = newCarrierCode\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst phoneNumber = new PhoneNumber(\r\n\t\t\tcountryCode || callingCode,\r\n\t\t\tnationalNumber,\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.nationalNumberDigits\r\n\t}\r\n\r\n\tgetNonFormattedTemplate() {\r\n\t\treturn this.getFullNumber(this.getNonFormattedNationalNumber())\r\n\t\t\t.replace(/[\\+\\d]/g, DIGIT_PLACEHOLDER)\r\n\t}\r\n\r\n\t/**\r\n\t * Returns formatted phone number template.\r\n\t * @return {string} [template]\r\n\t */\r\n\tgetTemplate() {\r\n\t\tif (!this.template) {\r\n\t\t\treturn this.getNonFormattedTemplate()\r\n\t\t}\r\n\t\tlet index = -1\r\n\t\tlet i = 0\r\n\t\twhile (i < (this.isInternational() ? this.getInternationalPrefix({ spacing: false }).length : 0) + this.digits.length) {\r\n\t\t\tindex = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn cutAndStripNonPairedParens(this.template, index + 1)\r\n\t}\r\n}\r\n\r\nexport function stripNonPairedParens(string) {\r\n\tconst dangling_braces =[]\r\n\tlet i = 0\r\n\twhile (i < string.length) {\r\n\t\tif (string[i] === '(') {\r\n\t\t\tdangling_braces.push(i)\r\n\t\t}\r\n\t\telse if (string[i] === ')') {\r\n\t\t\tdangling_braces.pop()\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\tlet start = 0\r\n\tlet cleared_string = ''\r\n\tdangling_braces.push(string.length)\r\n\tfor (const index of dangling_braces) {\r\n\t\tcleared_string += string.slice(start, index)\r\n\t\tstart = index + 1\r\n\t}\r\n\treturn cleared_string\r\n}\r\n\r\nexport function cutAndStripNonPairedParens(string, cutBeforeIndex) {\r\n\tif (string[cutBeforeIndex] === ')') {\r\n\t\tcutBeforeIndex++\r\n\t}\r\n\treturn stripNonPairedParens(string.slice(0, cutBeforeIndex))\r\n}\r\n\r\nexport function closeNonPairedParens(template, cut_before) {\r\n\tconst retained_template = template.slice(0, cut_before)\r\n\tconst opening_braces = countOccurences('(', retained_template)\r\n\tconst closing_braces = countOccurences(')', retained_template)\r\n\tlet dangling_braces = opening_braces - closing_braces\r\n\twhile (dangling_braces > 0 && cut_before < template.length) {\r\n\t\tif (template[cut_before] === ')') {\r\n\t\t\tdangling_braces--\r\n\t\t}\r\n\t\tcut_before++\r\n\t}\r\n\treturn template.slice(0, cut_before)\r\n}\r\n\r\n// Counts all occurences of a symbol in a string.\r\n// Unicode-unsafe (because using `.split()`).\r\nexport function countOccurences(symbol, string) {\r\n\tlet count = 0\r\n\t// Using `.split('')` to iterate through a string here\r\n\t// to avoid requiring `Symbol.iterator` polyfill.\r\n\t// `.split('')` is generally not safe for Unicode,\r\n\t// but in this particular case for counting brackets it is safe.\r\n\t// for (const character of string)\r\n\tfor (const character of string.split('')) {\r\n\t\tif (character === symbol) {\r\n\t\t\tcount++\r\n\t\t}\r\n\t}\r\n\treturn count\r\n}\r\n\r\n// Repeats a string (or a symbol) N times.\r\n// http://stackoverflow.com/questions/202605/repeat-string-javascript\r\nexport function repeat(string, times) {\r\n\tif (times < 1) {\r\n\t\treturn ''\r\n\t}\r\n\tlet result = ''\r\n\twhile (times > 1) {\r\n\t\tif (times & 1) {\r\n\t\t\tresult += string\r\n\t\t}\r\n\t\ttimes >>= 1\r\n\t\tstring += string\r\n\t}\r\n\treturn result + string\r\n}\r\n\r\n/**\r\n * Extracts formatted phone number from text (if there's any).\r\n * @param {string} text\r\n * @return {string} [formattedPhoneNumber]\r\n */\r\nfunction extractFormattedPhoneNumber(text) {\r\n\t// Attempt to extract a possible number from the string passed in.\r\n\tconst startsAt = text.search(VALID_PHONE_NUMBER)\r\n\tif (startsAt < 0) {\r\n\t\treturn\r\n\t}\r\n\t// Trim everything to the left of the phone number.\r\n\ttext = text.slice(startsAt)\r\n\t// Trim the `+`.\r\n\tlet hasPlus\r\n\tif (text[0] === '+') {\r\n\t\thasPlus = true\r\n\t\ttext = text.slice('+'.length)\r\n\t}\r\n\t// Trim everything to the right of the phone number.\r\n\ttext = text.replace(AFTER_PHONE_NUMBER_DIGITS_END_PATTERN, '')\r\n\t// Re-add the previously trimmed `+`.\r\n\tif (hasPlus) {\r\n\t\ttext = '+' + text\r\n\t}\r\n\treturn text\r\n}"],"file":"AsYouType.js"}