lik/dist/lik.stringmap.js

97 lines
5.1 KiB
JavaScript
Raw Normal View History

2016-07-21 22:16:45 +00:00
"use strict";
2017-04-09 14:29:14 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./lik.plugins");
2016-07-21 22:16:45 +00:00
class Stringmap {
constructor() {
this._stringArray = [];
this._triggerUntilTrueFunctionArray = [];
2016-07-21 22:16:45 +00:00
}
/**
* add a string to the Stringmap
*/
addString(stringArg) {
this._stringArray.push(stringArg);
this.notifyTrigger();
2016-07-21 22:16:45 +00:00
}
2016-09-21 13:57:57 +00:00
/**
* like addString, but accepts an array of strings
*/
addStringArray(stringArrayArg) {
for (let stringItem of stringArrayArg) {
this.addString(stringItem);
}
}
2016-07-21 22:16:45 +00:00
/**
* removes a string from Stringmap
*/
removeString(stringArg) {
for (let keyArg in this._stringArray) {
2016-07-30 22:54:46 +00:00
if (this._stringArray[keyArg] === stringArg) {
2016-07-21 22:16:45 +00:00
this._stringArray.splice(parseInt(keyArg), 1);
}
}
this.notifyTrigger();
}
/**
* wipes the Stringmap
*/
wipe() {
this._stringArray = [];
this.notifyTrigger();
2016-07-21 22:16:45 +00:00
}
/**
* check if string is in Stringmap
*/
checkString(stringArg) {
return this._stringArray.indexOf(stringArg) !== -1;
2016-07-21 22:16:45 +00:00
}
2016-07-22 12:59:09 +00:00
/**
* 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() {
2016-07-30 22:54:46 +00:00
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();
2016-07-30 22:54:46 +00:00
if (result === true) {
doFunctionArg();
}
return result;
});
this.notifyTrigger();
2016-07-22 12:59:09 +00:00
}
/**
* notifies triggers
*/
notifyTrigger() {
let filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
return !functionArg();
});
this._triggerUntilTrueFunctionArray = filteredArray;
}
2016-07-21 22:16:45 +00:00
}
exports.Stringmap = Stringmap;
2017-04-09 14:29:14 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLnN0cmluZ21hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5zdHJpbmdtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx5Q0FBd0M7QUFVeEM7SUFHSTtRQUZRLGlCQUFZLEdBQWEsRUFBRSxDQUFBO1FBQzNCLG1DQUE4QixHQUF1QixFQUFFLENBQUE7SUFDaEQsQ0FBQztJQUNoQjs7T0FFRztJQUNILFNBQVMsQ0FBQyxTQUFpQjtRQUN2QixJQUFJLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQTtRQUNqQyxJQUFJLENBQUMsYUFBYSxFQUFFLENBQUE7SUFDeEIsQ0FBQztJQUVEOztPQUVHO0lBQ0gsY0FBYyxDQUFDLGNBQXdCO1FBQ25DLEdBQUcsQ0FBQyxDQUFDLElBQUksVUFBVSxJQUFJLGNBQWMsQ0FBQyxDQUFBLENBQUM7WUFDbkMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUM5QixDQUFDO0lBQ0wsQ0FBQztJQUVEOztPQUVHO0lBQ0gsWUFBWSxDQUFDLFNBQWlCO1FBQzFCLEdBQUcsQ0FBQyxDQUFDLElBQUksTUFBTSxJQUFJLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQyxDQUFDO1lBQ25DLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0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