isValid.js.map 4.1 KB

1
  1. {"version":3,"file":"isValid.js","names":["isValidNumber","input","options","metadata","Metadata","selectNumberingPlan","country","countryCallingCode","hasTypes","getNumberType","undefined","nationalNumber","v2","phone","matchesEntirely","nationalNumberPattern"],"sources":["../source/isValid.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport matchesEntirely from './helpers/matchesEntirely.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\n\r\n/**\r\n * Checks if a given phone number is valid.\r\n *\r\n * isValid(phoneNumberInstance, { ..., v2: true }, metadata)\r\n *\r\n * isPossible({ phone: '8005553535', country: 'RU' }, { ... }, metadata)\r\n * isPossible({ phone: '8005553535', country: 'RU' }, undefined, metadata)\r\n *\r\n * If the `number` is a string, it will be parsed to an object,\r\n * but only if it contains only valid phone number characters (including punctuation).\r\n * If the `number` is an object, it is used as is.\r\n *\r\n * The optional `defaultCountry` argument is the default country.\r\n * I.e. it does not restrict to just that country,\r\n * e.g. in those cases where several countries share\r\n * the same phone numbering rules (NANPA, Britain, etc).\r\n * For example, even though the number `07624 369230`\r\n * belongs to the Isle of Man (\"IM\" country code)\r\n * calling `isValidNumber('07624369230', 'GB', metadata)`\r\n * still returns `true` because the country is not restricted to `GB`,\r\n * it's just that `GB` is the default one for the phone numbering rules.\r\n * For restricting the country see `isValidNumberForRegion()`\r\n * though restricting a country might not be a good idea.\r\n * https://github.com/googlei18n/libphonenumber/blob/master/FAQ.md#when-should-i-use-isvalidnumberforregion\r\n *\r\n * Examples:\r\n *\r\n * ```js\r\n * isValidNumber('+78005553535', metadata)\r\n * isValidNumber('8005553535', 'RU', metadata)\r\n * isValidNumber('88005553535', 'RU', metadata)\r\n * isValidNumber({ phone: '8005553535', country: 'RU' }, metadata)\r\n * ```\r\n */\r\nexport default function isValidNumber(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\tmetadata = new Metadata(metadata)\r\n\r\n/**\r\n * Checks if a phone number is \"possible\" (basically just checks its length).\r\n *\r\n * @param {object|PhoneNumber} input — If `options.v2: true` flag is passed, the `input` should be a `PhoneNumber` instance. Otherwise, it should be an object of shape `{ phone: '...', country: '...' }`.\r\n * @param {object} [options]\r\n * @param {object} metadata\r\n * @return {string}\r\n */\r\n\r\n\tmetadata.selectNumberingPlan(input.country, input.countryCallingCode)\r\n\r\n\t// By default, countries only have type regexps when it's required for\r\n\t// distinguishing different countries having the same `countryCallingCode`.\r\n\tif (metadata.hasTypes()) {\r\n\t\treturn getNumberType(input, options, metadata.metadata) !== undefined\r\n\t}\r\n\r\n\t// If there are no type regexps for this country in metadata then use\r\n\t// `nationalNumberPattern` as a \"better than nothing\" replacement.\r\n\tconst nationalNumber = options.v2 ? input.nationalNumber : input.phone\r\n\treturn matchesEntirely(nationalNumber, metadata.nationalNumberPattern())\r\n}"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,aAAT,CAAuBC,KAAvB,EAA8BC,OAA9B,EAAuCC,QAAvC,EACf;EACC;EACA;EACAD,OAAO,GAAGA,OAAO,IAAI,EAArB;EAEAC,QAAQ,GAAG,IAAIC,oBAAJ,CAAaD,QAAb,CAAX;EAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;EAECA,QAAQ,CAACE,mBAAT,CAA6BJ,KAAK,CAACK,OAAnC,EAA4CL,KAAK,CAACM,kBAAlD,EAhBD,CAkBC;EACA;;EACA,IAAIJ,QAAQ,CAACK,QAAT,EAAJ,EAAyB;IACxB,OAAO,IAAAC,yBAAA,EAAcR,KAAd,EAAqBC,OAArB,EAA8BC,QAAQ,CAACA,QAAvC,MAAqDO,SAA5D;EACA,CAtBF,CAwBC;EACA;;;EACA,IAAMC,cAAc,GAAGT,OAAO,CAACU,EAAR,GAAaX,KAAK,CAACU,cAAnB,GAAoCV,KAAK,CAACY,KAAjE;EACA,OAAO,IAAAC,2BAAA,EAAgBH,cAAhB,EAAgCR,QAAQ,CAACY,qBAAT,EAAhC,CAAP;AACA"}