2016-07-21 22:16:45 +00:00
|
|
|
import * as plugins from "./lik.plugins";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* allows you to easily keep track of a bunch of strings;
|
|
|
|
*/
|
2016-07-23 02:39:42 +00:00
|
|
|
|
|
|
|
export interface triggerFunction {
|
|
|
|
():boolean;
|
|
|
|
}
|
|
|
|
|
2016-07-21 22:16:45 +00:00
|
|
|
export class Stringmap {
|
|
|
|
private _stringArray:string[] = [];
|
2016-07-23 02:39:42 +00:00
|
|
|
private _triggerUntilTrueFunctionArray:triggerFunction[] = [];
|
2016-07-21 22:16:45 +00:00
|
|
|
constructor(){
|
|
|
|
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* add a string to the Stringmap
|
|
|
|
*/
|
|
|
|
addString(stringArg:string){
|
|
|
|
this._stringArray.push(stringArg);
|
2016-07-23 02:39:42 +00:00
|
|
|
this.notifyTrigger();
|
2016-07-21 22:16:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* removes a string from Stringmap
|
|
|
|
*/
|
|
|
|
removeString(stringArg:string){
|
|
|
|
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);
|
|
|
|
};
|
2016-07-23 02:39:42 +00:00
|
|
|
};
|
|
|
|
this.notifyTrigger();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wipes the Stringmap
|
|
|
|
*/
|
|
|
|
wipe(){
|
|
|
|
this._stringArray = [];
|
|
|
|
this.notifyTrigger();
|
2016-07-21 22:16:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check if string is in Stringmap
|
|
|
|
*/
|
2016-07-23 02:39:42 +00:00
|
|
|
checkString(stringArg:string):boolean {
|
2016-07-21 22:16:45 +00:00
|
|
|
return this._stringArray.indexOf(stringArg) != -1;
|
|
|
|
}
|
2016-07-22 12:59:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* checks stringPresence with minimatch
|
|
|
|
*/
|
2016-07-23 02:39:42 +00:00
|
|
|
checkMinimatch(miniMatchStringArg:string):boolean {
|
|
|
|
let foundMatch:boolean = false;
|
|
|
|
for(let stringItem of this._stringArray){
|
|
|
|
if(plugins.minimatch(stringItem,miniMatchStringArg)){
|
|
|
|
foundMatch = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return foundMatch;
|
|
|
|
};
|
2016-07-22 12:59:09 +00:00
|
|
|
|
2016-07-23 02:39:42 +00:00
|
|
|
/**
|
|
|
|
* checks if the Stringmap is empty
|
|
|
|
*/
|
|
|
|
checkIsEmpty(){
|
2016-07-30 22:54:46 +00:00
|
|
|
return (this._stringArray.length === 0);
|
2016-07-23 02:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// trigger registering
|
|
|
|
|
|
|
|
/**
|
|
|
|
* notifies triggers
|
|
|
|
*/
|
|
|
|
private notifyTrigger(){
|
|
|
|
let filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
|
|
|
|
return !functionArg();
|
|
|
|
});
|
|
|
|
this._triggerUntilTrueFunctionArray = filteredArray;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* register a new trigger
|
|
|
|
*/
|
|
|
|
registerUntilTrue(functionArg:triggerFunction,doFunctionArg){
|
|
|
|
this._triggerUntilTrueFunctionArray.push(
|
|
|
|
() => {
|
|
|
|
let result = functionArg();
|
2016-07-30 22:54:46 +00:00
|
|
|
if(result === true){
|
2016-07-23 02:39:42 +00:00
|
|
|
doFunctionArg();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
this.notifyTrigger();
|
2016-07-22 12:59:09 +00:00
|
|
|
}
|
2016-07-21 22:16:45 +00:00
|
|
|
}
|