88 lines
4.7 KiB
JavaScript
88 lines
4.7 KiB
JavaScript
"use strict";
|
|
const plugins = require("./lik.plugins");
|
|
class Stringmap {
|
|
constructor() {
|
|
this._stringArray = [];
|
|
this._triggerUntilTrueFunctionArray = [];
|
|
}
|
|
/**
|
|
* add a string to the Stringmap
|
|
*/
|
|
addString(stringArg) {
|
|
this._stringArray.push(stringArg);
|
|
this.notifyTrigger();
|
|
}
|
|
/**
|
|
* removes a string from Stringmap
|
|
*/
|
|
removeString(stringArg) {
|
|
for (let keyArg in this._stringArray) {
|
|
if (this._stringArray[keyArg] === stringArg) {
|
|
this._stringArray.splice(parseInt(keyArg), 1);
|
|
}
|
|
}
|
|
this.notifyTrigger();
|
|
}
|
|
/**
|
|
* wipes the Stringmap
|
|
*/
|
|
wipe() {
|
|
this._stringArray = [];
|
|
this.notifyTrigger();
|
|
}
|
|
/**
|
|
* check if string is in Stringmap
|
|
*/
|
|
checkString(stringArg) {
|
|
return this._stringArray.indexOf(stringArg) !== -1;
|
|
}
|
|
/**
|
|
* checks stringPresence with minimatch
|
|
*/
|
|
checkMinimatch(miniMatchStringArg) {
|
|
let foundMatch = false;
|
|
for (let stringItem of this._stringArray) {
|
|
if (plugins.minimatch(stringItem, miniMatchStringArg)) {
|
|
foundMatch = true;
|
|
}
|
|
}
|
|
return foundMatch;
|
|
}
|
|
/**
|
|
* checks if the Stringmap is empty
|
|
*/
|
|
checkIsEmpty() {
|
|
return (this._stringArray.length === 0);
|
|
}
|
|
/**
|
|
* gets a cloned copy of the current string Array
|
|
*/
|
|
getStringArray() {
|
|
return plugins.lodash.cloneDeep(this._stringArray);
|
|
}
|
|
// trigger registering
|
|
/**
|
|
* register a new trigger
|
|
*/
|
|
registerUntilTrue(functionArg, doFunctionArg) {
|
|
this._triggerUntilTrueFunctionArray.push(() => {
|
|
let result = functionArg();
|
|
if (result === true) {
|
|
doFunctionArg();
|
|
}
|
|
return result;
|
|
});
|
|
this.notifyTrigger();
|
|
}
|
|
/**
|
|
* notifies triggers
|
|
*/
|
|
notifyTrigger() {
|
|
let filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
|
|
return !functionArg();
|
|
});
|
|
this._triggerUntilTrueFunctionArray = filteredArray;
|
|
}
|
|
}
|
|
exports.Stringmap = Stringmap;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLnN0cmluZ21hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5zdHJpbmdtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHlDQUF3QztBQVV4QztJQUdJO1FBRlEsaUJBQVksR0FBYSxFQUFFLENBQUE7UUFDM0IsbUNBQThCLEdBQXVCLEVBQUUsQ0FBQTtJQUNoRCxDQUFDO0lBQ2hCOztPQUVHO0lBQ0gsU0FBUyxDQUFDLFNBQWlCO1FBQ3ZCLElBQUksQ0FBQyxZQUFZLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxDQUFBO1FBQ2pDLElBQUksQ0FBQyxhQUFhLEVBQUUsQ0FBQTtJQUN4QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxZQUFZLENBQUMsU0FBaUI7UUFDMUIsR0FBRyxDQUFDLENBQUMsSUFBSSxNQUFNLElBQUksSUFBSSxDQUFDLFlBQVksQ0FBQyxDQUFDLENBQUM7WUFDbkMsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLFlBQVksQ0FBQyxNQUFNLENBQUMsS0FBSyxTQUFTLENBQUMsQ0FBQyxDQUFDO2dCQUMxQyxJQUFJLENBQUMsWUFBWSxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsTUFBTSxDQUFDLEVBQUMsQ0FBQyxDQUFDLENBQUE7WUFDaEQsQ0FBQztRQUNMLENBQUM7UUFDRCxJQUFJLENBQUMsYUFBYSxFQUFFLENBQUE7SUFDeEIsQ0FBQztJQUVEOztPQUVHO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