typescript-libraries
Version:
To install this library, run:
84 lines (83 loc) • 3.03 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TSPool = void 0;
var TSNumber_1 = require("../utils/TSNumber");
var TSObject_1 = require("../utils/TSObject");
var TSString_1 = require("../utils/TSString");
var TSPool = /** @class */ (function () {
function TSPool(params) {
this.params = params;
this.items = [];
this.selected = {};
if (!this.params.reserve) {
this.params.reserve = [];
}
this.options = this.params;
this.items = this.options.matches.concat(this.options.reserve);
this.options.size = this.items.length;
this.calculate;
}
TSPool.prototype.toggleLine = function (k) {
this.toggle(k);
return this.calculate;
};
TSPool.prototype.favoriteLines = function (kItem, property) {
if (kItem === void 0) { kItem = 'oc'; }
if (property === void 0) { property = 'o'; }
this.clearLines();
for (var _i = 0, _a = this.items; _i < _a.length; _i++) {
var i = _a[_i];
var min = i[kItem].reduce(function (m, c, ci, pool) { return c[property] < pool[m][property] ? ci : m; }, 0);
this.toggle(i[kItem][min].sk);
}
return this.calculate;
};
TSPool.prototype.randomLines = function (kItem) {
if (kItem === void 0) { kItem = 'oc'; }
this.clearLines();
for (var _i = 0, _a = this.items; _i < _a.length; _i++) {
var i = _a[_i];
var k = TSNumber_1.TSNumber.random(0, i[kItem].length - 1);
this.toggle(i[kItem][k].sk);
}
return this.calculate;
};
TSPool.prototype.clearLines = function () {
this.selected = {};
return this.calculate;
};
TSPool.prototype.key = function (key) {
return TSString_1.TSString.splitBy(key, '_', 'first')[0];
};
TSPool.prototype.toggle = function (k) {
var key = this.key(k);
if (!this.selected[key]) {
this.selected[key] = [k];
}
else {
var iIndex = this.selected[key].findIndex(function (v) { return v === k; });
iIndex !== -1 ? this.selected[key].splice(iIndex, 1) : this.selected[key].push(k);
}
};
Object.defineProperty(TSPool.prototype, "calculate", {
get: function () {
var lines = TSObject_1.TSObject.value(this.selected) ? 1 : 0, size = 0;
TSObject_1.TSObject.forOwn(this.selected, function (v) {
if (v.length) {
lines *= v.length;
size++;
}
});
this.result = {
stake: this.options.stake, amount: this.options.stake * lines,
lines: lines,
selected: this.selected, completed: size === this.options.size
};
return this.result;
},
enumerable: false,
configurable: true
});
return TSPool;
}());
exports.TSPool = TSPool;