UNPKG

@tgwf/co2

Version:
58 lines (57 loc) 1.28 kB
"use strict"; async function check(domain, db) { if (typeof domain === "string") { return checkInJSON(domain, db); } else { return checkDomainsInJSON(domain, db); } } function checkInJSON(domain, db) { if (db.indexOf(domain) > -1) { return true; } return false; } function greenDomainsFromResults(greenResults) { const entries = Object.entries(greenResults); const greenEntries = entries.filter(([key, val]) => val.green); return greenEntries.map(([key, val]) => val.url); } function checkDomainsInJSON(domains, db) { let greenDomains = []; for (let domain of domains) { if (db.indexOf(domain) > -1) { greenDomains.push(domain); } } return greenDomains; } function find(domain, db) { if (typeof domain === "string") { return findInJSON(domain, db); } else { return findDomainsInJSON(domain, db); } } function findInJSON(domain, db) { if (db.indexOf(domain) > -1) { return domain; } return { url: domain, green: false }; } function findDomainsInJSON(domains, db) { const result = {}; for (let domain of domains) { result[domain] = findInJSON(domain, db); } return result; } module.exports = { check, greenDomainsFromResults, find }; //# sourceMappingURL=hosting-json.js.map