net-helper/modules/index.js

50 lines
1.2 KiB
JavaScript

// Func
class OperatorsStorage extends Array {
constructor (...p) {
super(...p);
this._indexObject = {};
this._indexObjectIndexOf = {};
}
push (item) {
if (item instanceof Operator) {
if (!this._indexObject[item.operator]) {
super.push(item);
this._indexObject[item.operator] = item;
}
}
else
throw new TypeError("Into OperatorsStorage you can add only Operator's instances");
}
includes (item) {
if (item instanceof Operator) {
return this._indexObject[item.operator] !== undefined;
}
else
throw new TypeError("Into OperatorsStorage storage only Operator type");
}
}
// API
class Operator {
constructor (operatorName, argvHandler = () => true, exec = (argv, module) => {}) {
this.operator = operatorName;
this.handlers = {
argv: argvHandler,
exec
};
}
}
module.exports = class NetProxierModule {
constructor () {
this.operators = new OperatorsStorage();
this.statics = new Object();
this.statics.Operator = Operator;
}
}