UNPKG

apisearch

Version:
137 lines (136 loc) 3 kB
"use strict"; exports.__esModule = true; exports.Counter = void 0; var Metadata_1 = require("../Model/Metadata"); /** * Aggregation class */ var Counter = /** @class */ (function () { /** * Constructor * * @param values * @param used * @param n */ function Counter(values, used, n) { this.values = values; this.used = used; this.n = n; } /** * Get id * * @return {string|null} */ Counter.prototype.getId = function () { return typeof this.values.id == "string" ? this.values.id : null; }; /** * Get name * * @return {string|null} */ Counter.prototype.getName = function () { return typeof this.values.name == "string" ? this.values.name : null; }; /** * Get slug * * @return {string|null} */ Counter.prototype.getSlug = function () { return typeof this.values.slug == "string" ? this.values.slug : null; }; /** * Get level * * @return {number} */ Counter.prototype.getLevel = function () { return typeof this.values.level == "number" ? this.values.level : 0; }; /** * Get values * * @returns {{}} */ Counter.prototype.getValues = function () { return this.values; }; /** * Is used * * @returns {boolean} */ Counter.prototype.isUsed = function () { return this.used; }; /** * Get N * * @returns {number} */ Counter.prototype.getN = function () { return this.n; }; /** * Create by active elements * * @param name * @param n * @param activeElements */ Counter.createByActiveElements = function (name, n, activeElements) { var values = Metadata_1.Metadata.fromMetadata(name); if (values == null) { return null; } var i = activeElements.length; var inActiveElements = false; while (i--) { if (activeElements[i] == values.id) { inActiveElements = true; } } return new Counter(values, inActiveElements, n); }; /** * To array * * @return {{}} */ Counter.prototype.toArray = function () { var values = { values: this.values, n: this.n }; if (this.used === true) { values.used = true; } return values; }; /** * Create from array * * @param array * * @return {Counter} */ Counter.createFromArray = function (array) { array = JSON.parse(JSON.stringify(array)); return new Counter(array.values, (typeof array.used == "boolean") ? array.used : false, array.n); }; return Counter; }()); exports.Counter = Counter;