UNPKG

fetch-dns

Version:

A drop-in replacement of Node's 'dns' module using 'fetch' and DNS-over-HTTPS

48 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const RrtypesData_json_1 = tslib_1.__importDefault(require("./RrtypesData.json")); const lodash_1 = tslib_1.__importDefault(require("lodash")); const debug_1 = tslib_1.__importDefault(require("debug")); const log = debug_1.default("fetch-dns:rrtypes"); const debug = log.extend("debug"); if (debug.enabled) log.enabled = true; const rrtypeMap = lodash_1.default.fromPairs(lodash_1.default.flatMap(RrtypesData_json_1.default, (rrtype) => { debug("Processing RRTYPE map entry", rrtype); const { TYPE, Value } = rrtype || {}; if (TYPE === "Unassigned" || TYPE === "Private use" || TYPE === "Reserved") { debug("Skipping unused RRTYPE allocation", TYPE, Value); return []; } const [start, stop] = lodash_1.default.map(lodash_1.default.split(Value, "-", 2), lodash_1.default.toFinite); if (lodash_1.default.includes(Value, "-")) { if (start === 0 || stop === 0) { log("Discovered an unbounded value", rrtype); return []; } else { return lodash_1.default.map(lodash_1.default.range(start, stop + 1), (i) => [lodash_1.default.toString(i), TYPE]); } } else { return [[Value, TYPE]]; } })); log(rrtypeMap); function lookupRrtype(rrtype) { const result = lodash_1.default.get(rrtypeMap, lodash_1.default.toString(rrtype), null); debug("Lookup up RRTYPE", { rrtype, result }); if (lodash_1.default.isNil(result) || result === false) return false; if (lodash_1.default.isString(result)) { return result; } else { throw new Error(`INTERNAL ERROR: rrtype return was neither nil nor a string, but '${typeof result}'`); } } exports.default = lookupRrtype; //# sourceMappingURL=Rrtypes.js.map