{"version":3,"file":"extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js","names":["Metadata","matchesEntirely","extractNationalNumber","checkNumberLength","getCountryCallingCode","extractCountryCallingCodeFromInternationalNumberWithoutPlusSign","number","country","callingCode","metadata","countryCallingCode","indexOf","selectNumberingPlan","possibleShorterNumber","slice","length","possibleShorterNationalNumber","nationalNumber","nationalNumberPattern"],"sources":["../../source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport matchesEntirely from './matchesEntirely.js'\r\nimport extractNationalNumber from './extractNationalNumber.js'\r\nimport checkNumberLength from './checkNumberLength.js'\r\nimport getCountryCallingCode from '../getCountryCallingCode.js'\r\n\r\n/**\r\n * Sometimes some people incorrectly input international phone numbers\r\n * without the leading `+`. This function corrects such input.\r\n * @param {string} number — Phone number digits.\r\n * @param {string?} country\r\n * @param {string?} callingCode\r\n * @param {object} metadata\r\n * @return {object} `{ countryCallingCode: string?, number: string }`.\r\n */\r\nexport default function extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(\r\n\tnumber,\r\n\tcountry,\r\n\tcallingCode,\r\n\tmetadata\r\n) {\r\n\tconst countryCallingCode = country ? getCountryCallingCode(country, metadata) : callingCode\r\n\tif (number.indexOf(countryCallingCode) === 0) {\r\n\t\tmetadata = new Metadata(metadata)\r\n\t\tmetadata.selectNumberingPlan(country, callingCode)\r\n\t\tconst possibleShorterNumber = number.slice(countryCallingCode.length)\r\n\t\tconst {\r\n\t\t\tnationalNumber: possibleShorterNationalNumber,\r\n\t\t} = extractNationalNumber(\r\n\t\t\tpossibleShorterNumber,\r\n\t\t\tmetadata\r\n\t\t)\r\n\t\tconst {\r\n\t\t\tnationalNumber\r\n\t\t} = extractNationalNumber(\r\n\t\t\tnumber,\r\n\t\t\tmetadata\r\n\t\t)\r\n\t\t// If the number was not valid before but is valid now,\r\n\t\t// or if it was too long before, we consider the number\r\n\t\t// with the country calling code stripped to be a better result\r\n\t\t// and keep that instead.\r\n\t\t// For example, in Germany (+49), `49` is a valid area code,\r\n\t\t// so if a number starts with `49`, it could be both a valid\r\n\t\t// national German number or an international number without\r\n\t\t// a leading `+`.\r\n\t\tif (\r\n\t\t\t(\r\n\t\t\t\t!matchesEntirely(nationalNumber, metadata.nationalNumberPattern())\r\n\t\t\t\t&&\r\n\t\t\t\tmatchesEntirely(possibleShorterNationalNumber, metadata.nationalNumberPattern())\r\n\t\t\t)\r\n\t\t\t||\r\n\t\t\tcheckNumberLength(nationalNumber, metadata) === 'TOO_LONG'\r\n\t\t) {\r\n\t\t\treturn {\r\n\t\t\t\tcountryCallingCode,\r\n\t\t\t\tnumber: possibleShorterNumber\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn { number }\r\n}"],"mappings":"AAAA,OAAOA,QAAP,MAAqB,gBAArB;AACA,OAAOC,eAAP,MAA4B,sBAA5B;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AACA,OAAOC,iBAAP,MAA8B,wBAA9B;AACA,OAAOC,qBAAP,MAAkC,6BAAlC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,+DAAT,CACdC,MADc,EAEdC,OAFc,EAGdC,WAHc,EAIdC,QAJc,EAKb;EACD,IAAMC,kBAAkB,GAAGH,OAAO,GAAGH,qBAAqB,CAACG,OAAD,EAAUE,QAAV,CAAxB,GAA8CD,WAAhF;;EACA,IAAIF,MAAM,CAACK,OAAP,CAAeD,kBAAf,MAAuC,CAA3C,EAA8C;IAC7CD,QAAQ,GAAG,IAAIT,QAAJ,CAAaS,QAAb,CAAX;IACAA,QAAQ,CAACG,mBAAT,CAA6BL,OAA7B,EAAsCC,WAAtC;IACA,IAAMK,qBAAqB,GAAGP,MAAM,CAACQ,KAAP,CAAaJ,kBAAkB,CAACK,MAAhC,CAA9B;;IACA,4BAEIb,qBAAqB,CACxBW,qBADwB,EAExBJ,QAFwB,CAFzB;IAAA,IACiBO,6BADjB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