{"version":3,"sources":["../source/getNumberType_.js"],"names":["NON_FIXED_LINE_PHONE_TYPES","getNumberType","input","options","metadata","country","Metadata","selectNumberingPlan","countryCallingCode","nationalNumber","v2","phone","nationalNumberPattern","is_of_type","type","pattern","_type","possibleLengths","indexOf","length","checkNumberLengthForType","type_info","possible_lengths","mobile_type","actual_length","minimum_length"],"mappings":";;;;;;;;;AAAA;;AACA;;;;AAEA,IAAMA,0BAA0B,GAChC,CACC,QADD,EAEC,cAFD,EAGC,WAHD,EAIC,aAJD,EAKC,MALD,EAMC,iBAND,EAOC,OAPD,EAQC,KARD,EASC,WATD,CADA,C,CAaA;;AACe,SAASC,aAAT,CAAuBC,KAAvB,EAA8BC,OAA9B,EAAuCC,QAAvC,EACf;AACC;AACA;AACAD,EAAAA,OAAO,GAAGA,OAAO,IAAI,EAArB,CAHD,CAKC;AACA;;AACA,MAAI,CAACD,KAAK,CAACG,OAAX,EAAoB;AACnB;AACA;;AAEDD,EAAAA,QAAQ,GAAG,IAAIE,oBAAJ,CAAaF,QAAb,CAAX;AAEAA,EAAAA,QAAQ,CAACG,mBAAT,CAA6BL,KAAK,CAACG,OAAnC,EAA4CH,KAAK,CAACM,kBAAlD;AAEA,MAAMC,cAAc,GAAGN,OAAO,CAACO,EAAR,GAAaR,KAAK,CAACO,cAAnB,GAAoCP,KAAK,CAACS,KAAjE,CAfD,CAiBC;AACA;AAEA;;AACA,MAAI,CAAC,2BAAgBF,cAAhB,EAAgCL,QAAQ,CAACQ,qBAAT,EAAhC,CAAL,EACA;AACC;AACA,GAxBF,CA0BC;;;AACA,MAAIC,UAAU,CAACJ,cAAD,EAAiB,YAAjB,EAA+BL,QAA/B,CAAd,EACA;AACC;AACA;AACA;AACA;AACA,QAAIA,QAAQ,CAACU,IAAT,CAAc,QAAd,KAA2BV,QAAQ,CAACU,IAAT,CAAc,QAAd,EAAwBC,OAAxB,OAAsC,EAArE,EACA;AACC,aAAO,sBAAP;AACA,KARF,CAUC;AACA;AACA;;;AACA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AAIR,IAAI,KAAK,sBAAb,EACA;AACC;;AACA;AACA,QAAI,CAACV,QAAQ,CAACU,IAAT,CAAc,YAAd,CAAL,EACA;AACC;AACA;AACA,aAAOM,wBAAwB,CAACX,cAAD,EAAiB,QAAjB,EAA2BL,QAA3B,CAA/B;AACA;;AAED,QAAMmB,WAAW,GAAGnB,QAAQ,CAACU,IAAT,CAAc,QAAd,CAApB;;AAEA,QAAIS,WAAJ,EACA;AACC;AACA;AACA;AACA;AACA;AACAD,MAAAA,gBAAgB,GAAG,uBAAYA,gBAAZ,EAA8BC,WAAW,CAACN,eAAZ,EAA9B,CAAnB,CAND,CAOC;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACD,GAlCD,CAmCA;AAnCA,OAoCK,IAAIH,IAAI,IAAI,CAACO,SAAb,EACL;AACC,aAAO,gBAAP;AACA;;AAED,MAAMG,aAAa,GAAGf,cAAc,CAACU,MAArC,CA3DD,CA6DC;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMM,cAAc,GAAGH,gBAAgB,CAAC,CAAD,CAAvC;;AAEA,MAAIG,cAAc,KAAKD,aAAvB,EACA;AACC,WAAO,aAAP;AACA;;AAED,MAAIC,cAAc,GAAGD,aAArB,EACA;AACC,WAAO,WAAP;AACA;;AAED,MAAIF,gBAAgB,CAACA,gBAAgB,CAACH,MAAjB,GAA0B,CAA3B,CAAhB,GAAgDK,aAApD,EACA;AACC,WAAO,UAAP;AACA,GApFF,CAsFC;;;AACA,SAAOF,gBAAgB,CAACJ,OAAjB,CAAyBM,aAAzB,EAAwC,CAAxC,KAA8C,CAA9C,GAAkD,aAAlD,GAAkE,gBAAzE;AACA","sourcesContent":["import Metadata from './metadata'\r\nimport { matchesEntirely, mergeArrays } from './util'\r\n\r\nconst NON_FIXED_LINE_PHONE_TYPES =\r\n[\r\n\t'MOBILE',\r\n\t'PREMIUM_RATE',\r\n\t'TOLL_FREE',\r\n\t'SHARED_COST',\r\n\t'VOIP',\r\n\t'PERSONAL_NUMBER',\r\n\t'PAGER',\r\n\t'UAN',\r\n\t'VOICEMAIL'\r\n]\r\n\r\n// Finds out national phone number type (fixed line, mobile, etc)\r\nexport default function getNumberType(input, options, metadata)\r\n{\r\n\t// If assigning the `{}` default value is moved to the arguments above,\r\n\t// code coverage would decrease for some weird reason.\r\n\toptions = options || {}\r\n\r\n\t// When `parse()` returned `{}`\r\n\t// meaning that the phone number is not a valid one.\r\n\tif (!input.country) {\r\n\t\treturn\r\n\t}\r\n\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\tmetadata.selectNumberingPlan(input.country, input.countryCallingCode)\r\n\r\n\tconst nationalNumber = options.v2 ? input.nationalNumber : input.phone\r\n\r\n\t// The following is copy-pasted from the original function:\r\n\t// https://github.com/googlei18n/libphonenumber/blob/3ea547d4fbaa2d0b67588904dfa5d3f2557c27ff/javascript/i18n/phonenumbers/phonenumberutil.js#L2835\r\n\r\n\t// Is this national number even valid for this country\r\n\tif (!matchesEntirely(nationalNumber, metadata.nationalNumberPattern()))\r\n\t{\r\n\t\treturn\r\n\t}\r\n\r\n\t// Is it fixed line number\r\n\tif (is_of_type(nationalNumber, 'FIXED_LINE', metadata))\r\n\t{\r\n\t\t// Because duplicate regular expressions are removed\r\n\t\t// to reduce metadata size, if \"mobile\" pattern is \"\"\r\n\t\t// then it means it was removed due to being a duplicate of the fixed-line pattern.\r\n\t\t//\r\n\t\tif (metadata.type('MOBILE') && metadata.type('MOBILE').pattern() === '')\r\n\t\t{\r\n\t\t\treturn 'FIXED_LINE_OR_MOBILE'\r\n\t\t}\r\n\r\n\t\t// v1 metadata.\r\n\t\t// Legacy.\r\n\t\t// Deprecated.\r\n\t\tif (!metadata.type('MOBILE'))\r\n\t\t{\r\n\t\t\treturn 'FIXED_LINE_OR_MOBILE'\r\n\t\t}\r\n\r\n\t\t// Check if the number happens to qualify as both fixed line and mobile.\r\n\t\t// (no such country in the minimal metadata set)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (is_of_type(nationalNumber, 'MOBILE', metadata))\r\n\t\t{\r\n\t\t\treturn 'FIXED_LINE_OR_MOBILE'\r\n\t\t}\r\n\r\n\t\treturn 'FIXED_LINE'\r\n\t}\r\n\r\n\tfor (const _type of NON_FIXED_LINE_PHONE_TYPES)\r\n\t{\r\n\t\tif (is_of_type(nationalNumber, _type, metadata))\r\n\t\t{\r\n\t\t\treturn _type\r\n\t\t}\r\n\t}\r\n}\r\n\r\nexport function is_of_type(nationalNumber, type, metadata)\r\n{\r\n\ttype = metadata.type(type)\r\n\r\n\tif (!type || !type.pattern())\r\n\t{\r\n\t\treturn false\r\n\t}\r\n\r\n\t// Check if any possible number lengths are present;\r\n\t// if so, we use them to avoid checking\r\n\t// the validation pattern if they don't match.\r\n\t// If they are absent, this means they match\r\n\t// the general description, which we have\r\n\t// already checked before a specific number type.\r\n\tif (type.possibleLengths() &&\r\n\t\ttype.possibleLengths().indexOf(nationalNumber.length) < 0)\r\n\t{\r\n\t\treturn false\r\n\t}\r\n\r\n\treturn matchesEntirely(nationalNumber, type.pattern())\r\n}\r\n\r\n// Should only be called for the \"new\" metadata which has \"possible lengths\".\r\nexport function checkNumberLengthForType(nationalNumber, type, metadata)\r\n{\r\n\tconst type_info = metadata.type(type)\r\n\r\n\t// There should always be \"\" set for every type element.\r\n\t// This is declared in the XML schema.\r\n\t// For size efficiency, where a sub-description (e.g. fixed-line)\r\n\t// has the same \"\" as the \"general description\", this is missing,\r\n\t// so we fall back to the \"general description\". Where no numbers of the type\r\n\t// exist at all, there is one possible length (-1) which is guaranteed\r\n\t// not to match the length of any real phone number.\r\n\tlet possible_lengths = type_info && type_info.possibleLengths() || metadata.possibleLengths()\r\n\t// let local_lengths = type_info && type.possibleLengthsLocal() || metadata.possibleLengthsLocal()\r\n\r\n\t// Metadata before version `1.0.18` didn't contain `possible_lengths`.\r\n\tif (!possible_lengths) {\r\n\t\treturn 'IS_POSSIBLE'\r\n\t}\r\n\r\n\tif (type === 'FIXED_LINE_OR_MOBILE')\r\n\t{\r\n\t\t// No such country in metadata.\r\n\t\t/* istanbul ignore next */\r\n\t\tif (!metadata.type('FIXED_LINE'))\r\n\t\t{\r\n\t\t\t// The rare case has been encountered where no fixedLine data is available\r\n\t\t\t// (true for some non-geographic entities), so we just check mobile.\r\n\t\t\treturn checkNumberLengthForType(nationalNumber, 'MOBILE', metadata)\r\n\t\t}\r\n\r\n\t\tconst mobile_type = metadata.type('MOBILE')\r\n\r\n\t\tif (mobile_type)\r\n\t\t{\r\n\t\t\t// Merge the mobile data in if there was any. \"Concat\" creates a new\r\n\t\t\t// array, it doesn't edit possible_lengths in place, so we don't need a copy.\r\n\t\t\t// Note that when adding the possible lengths from mobile, we have\r\n\t\t\t// to again check they aren't empty since if they are this indicates\r\n\t\t\t// they are the same as the general desc and should be obtained from there.\r\n\t\t\tpossible_lengths = mergeArrays(possible_lengths, mobile_type.possibleLengths())\r\n\t\t\t// The current list is sorted; we need to merge in the new list and\r\n\t\t\t// re-sort (duplicates are okay). Sorting isn't so expensive because\r\n\t\t\t// the lists are very small.\r\n\r\n\t\t\t// if (local_lengths)\r\n\t\t\t// {\r\n\t\t\t// \tlocal_lengths = mergeArrays(local_lengths, mobile_type.possibleLengthsLocal())\r\n\t\t\t// }\r\n\t\t\t// else\r\n\t\t\t// {\r\n\t\t\t// \tlocal_lengths = mobile_type.possibleLengthsLocal()\r\n\t\t\t// }\r\n\t\t}\r\n\t}\r\n\t// If the type doesn't exist then return 'INVALID_LENGTH'.\r\n\telse if (type && !type_info)\r\n\t{\r\n\t\treturn 'INVALID_LENGTH'\r\n\t}\r\n\r\n\tconst actual_length = nationalNumber.length\r\n\r\n\t// In `libphonenumber-js` all \"local-only\" formats are dropped for simplicity.\r\n\t// // This is safe because there is never an overlap beween the possible lengths\r\n\t// // and the local-only lengths; this is checked at build time.\r\n\t// if (local_lengths && local_lengths.indexOf(nationalNumber.length) >= 0)\r\n\t// {\r\n\t// \treturn 'IS_POSSIBLE_LOCAL_ONLY'\r\n\t// }\r\n\r\n\tconst minimum_length = possible_lengths[0]\r\n\r\n\tif (minimum_length === actual_length)\r\n\t{\r\n\t\treturn 'IS_POSSIBLE'\r\n\t}\r\n\r\n\tif (minimum_length > actual_length)\r\n\t{\r\n\t\treturn 'TOO_SHORT'\r\n\t}\r\n\r\n\tif (possible_lengths[possible_lengths.length - 1] < actual_length)\r\n\t{\r\n\t\treturn 'TOO_LONG'\r\n\t}\r\n\r\n\t// We skip the first element since we've already checked it.\r\n\treturn possible_lengths.indexOf(actual_length, 1) >= 0 ? 'IS_POSSIBLE' : 'INVALID_LENGTH'\r\n}"],"file":"getNumberType_.js"}