lik/dist/lik.stringmap.js

97 lines
5.2 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-10-24 11:19:52 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLnN0cmluZ21hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5zdHJpbmdtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx5Q0FBd0M7QUFVeEM7SUFHRTtRQUZRLGlCQUFZLEdBQWEsRUFBRSxDQUFBO1FBQzNCLG1DQUE4QixHQUF1QixFQUFFLENBQUE7SUFDL0MsQ0FBQztJQUNqQjs7T0FFRztJQUNILFNBQVMsQ0FBRSxTQUFpQjtRQUMxQixJQUFJLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQTtRQUNqQyxJQUFJLENBQUMsYUFBYSxFQUFFLENBQUE7SUFDdEIsQ0FBQztJQUVEOztPQUVHO0lBQ0gsY0FBYyxDQUFFLGNBQXdCO1FBQ3RDLEdBQUcsQ0FBQyxDQUFDLElBQUksVUFBVSxJQUFJLGNBQWMsQ0FBQyxDQUFDLENBQUM7WUFDdEMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUM1QixDQUFDO0lBQ0gsQ0FBQztJQUVEOztPQUVHO0lBQ0gsWUFBWSxDQUFFLFNBQWlCO1FBQzdCLEdBQUcsQ0FBQyxDQUFDLElBQUksTUFBTSxJQUFJLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQyxDQUFDO1lBQ3JDLEVBQUUsQ0FBQyxDQUFDLElBQUksQ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