bulk-whois-parser
Version:
A lib to parse bulk whois data
74 lines (73 loc) • 5.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _connectorRIPE = _interopRequireDefault(require("./connectors/connectorRIPE"));
var _connectorAFRINIC = _interopRequireDefault(require("./connectors/connectorAFRINIC"));
var _connectorLACNIC = _interopRequireDefault(require("./connectors/connectorLACNIC"));
var _connectorAPNIC = _interopRequireDefault(require("./connectors/connectorAPNIC"));
var _connectorARIN = _interopRequireDefault(require("./connectors/connectorARIN"));
var _batchPromises = _interopRequireDefault(require("batch-promises"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var WhoisParser = exports["default"] = /*#__PURE__*/_createClass(function WhoisParser(params) {
var _this = this;
_classCallCheck(this, WhoisParser);
_defineProperty(this, "_getObjects", function (types, filterFunction, fields, forEachFunction) {
fields = fields || [];
var objects = [];
return (0, _batchPromises["default"])(3, Object.keys(_this.connectors), function (connector) {
return _this.connectors[connector].getObjects(types, filterFunction, fields, forEachFunction).then(function (results) {
return objects.concat(results.flat());
})["catch"](console.log);
});
});
_defineProperty(this, "getObjects", function (types, filterFunction, fields) {
return _this._getObjects(types, filterFunction, fields, null);
});
_defineProperty(this, "forEachObject", function (types, filterFunction, fields, forEachFunction) {
return _this._getObjects(types, filterFunction, fields, forEachFunction).then(function () {
return null;
});
});
this.params = params || {
userAgent: "bulk-whois-parser"
};
this.cacheDir = this.params.cacheDir || ".cache/";
this.connectors = {};
var connectors = {
"ripe": _connectorRIPE["default"],
"afrinic": _connectorAFRINIC["default"],
"apnic": _connectorAPNIC["default"],
"arin": _connectorARIN["default"],
"lacnic": _connectorLACNIC["default"]
};
if (this.params.repos) {
var _iterator = _createForOfIteratorHelper(this.params.repos),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var repo = _step.value;
this.connectors[repo] = new connectors[repo](this.params);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
} else {
for (var _repo in connectors) {
this.connectors[_repo] = new connectors[_repo](this.params);
}
}
});