UNPKG

3.62 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../source/validate_.js"],"names":["isValidNumber","input","options","metadata","Metadata","country","selectNumberingPlan","countryCallingCode","hasTypes","undefined","national_number","v2","nationalNumber","phone","nationalNumberPattern"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6Be,SAASA,aAAT,CAAuBC,KAAvB,EAA8BC,OAA9B,EAAuCC,QAAvC,EACf;AACC;AACA;AACAD,EAAAA,OAAO,GAAGA,OAAO,IAAI,EAArB;AAEAC,EAAAA,QAAQ,GAAG,IAAIC,oBAAJ,CAAaD,QAAb,CAAX,CALD,CAOC;AACA;;AACA,MAAI,CAACF,KAAK,CAACI,OAAX,EACA;AACC,WAAO,KAAP;AACA;;AAEDF,EAAAA,QAAQ,CAACG,mBAAT,CAA6BL,KAAK,CAACI,OAAnC,EAA4CJ,KAAK,CAACM,kBAAlD,EAdD,CAgBC;AACA;;AACA,MAAIJ,QAAQ,CAACK,QAAT,EAAJ,EACA;AACC,WAAO,+BAAcP,KAAd,EAAqBC,OAArB,EAA8BC,QAAQ,CAACA,QAAvC,MAAqDM,SAA5D;AACA,GArBF,CAuBC;AACA;;;AACA,MAAMC,eAAe,GAAGR,OAAO,CAACS,EAAR,GAAaV,KAAK,CAACW,cAAnB,GAAoCX,KAAK,CAACY,KAAlE;AACA,SAAO,iCAAgBH,eAAhB,EAAiCP,QAAQ,CAACW,qBAAT,EAAjC,CAAP;AACA","sourcesContent":["import Metadata from './metadata'\r\nimport matchesEntirely from './helpers/matchesEntirely'\r\nimport getNumberType from './helpers/getNumberType'\r\n\r\n/**\r\n * Checks if a given phone number is valid.\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\t// This is just to support `isValidNumber({})`\r\n\t// for cases when `parseNumber()` returns `{}`.\r\n\tif (!input.country)\r\n\t{\r\n\t\treturn false\r\n\t}\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{\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 national_number = options.v2 ? input.nationalNumber : input.phone\r\n\treturn matchesEntirely(national_number, metadata.nationalNumberPattern())\r\n}"],"file":"validate_.js"}
\No newline at end of file