UNPKG

asn-isp

Version:

A module providing ASN data by country with ISP names and ASNs

55 lines (50 loc) 2.03 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var fs = require('fs'); var path = require('path'); var url = require('url'); var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null; const __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.node.cjs', document.baseURI).href))); const __dirname$1 = path.dirname(__filename$1); const isBuilt = __dirname$1.includes('dist'); const jsonPath = isBuilt ? path.join(__dirname$1, 'data/asn_by_countries.json') : path.join(__dirname$1, '../src/data/asn_by_countries.json'); const rawData = JSON.parse(fs.readFileSync(jsonPath, 'utf-8')); const asnData = rawData; function getISPsByCountry(country) { return asnData.filter((data) => data.country === country) || []; } function getISPsByName(name) { return asnData.filter((data) => data.name.toLowerCase().includes(name.toLowerCase())) || []; } function getISPsByASN(asn) { return asnData.find((data) => data.asn === asn) || null; } function getShopifyOptions(name) { const data = asnData.filter((data) => data.name.toLowerCase().includes(name.toLowerCase())) || []; const grouped = {}; data.forEach(({ name, asn, country }) => { if (!grouped[country]) { grouped[country] = { title: country, options: [] }; } grouped[country].options.push({ label: name, value: asn, }); }); return Object.values(grouped); } var index_node = { getShopifyOptions, getISPsByCountry, getISPsByName, getISPsByASN, asnData }; exports.default = index_node; exports.getISPsByASN = getISPsByASN; exports.getISPsByCountry = getISPsByCountry; exports.getISPsByName = getISPsByName; exports.getShopifyOptions = getShopifyOptions; //# sourceMappingURL=index.node.cjs.map