UNPKG

@wocker/core

Version:
51 lines (50 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigCollection = void 0; /** * @deprecated */ /* istanbul ignore next */ class ConfigCollection { constructor(ConfigClass, items) { this.ConfigClass = ConfigClass; this.items = items.map((props) => { return new this.ConfigClass(props); }); } setConfig(config) { let exists = false; for (let i = 0; i < this.items.length; i++) { if (this.items[i].name === config.name) { exists = true; this.items[i] = config; } } if (!exists) { this.items.push(config); } } getConfig(name) { return this.items.find((config) => { return config.name === name; }); } removeConfig(name) { const index = this.items.findIndex((storage) => { return storage.name === name; }); if (index === -1) { return; } this.items = [ ...this.items.slice(0, index), ...this.items.slice(index + 1) ]; } toArray() { return this.items.map((item) => { return item.toObject(); }); } } exports.ConfigCollection = ConfigCollection;