now checking correctly if Stringmap is empty
This commit is contained in:
parent
24df2fd54f
commit
6d22ee466f
1
dist/lik.plugins.d.ts
vendored
1
dist/lik.plugins.d.ts
vendored
@ -1,2 +1,3 @@
|
|||||||
import "typings-global";
|
import "typings-global";
|
||||||
export import q = require("q");
|
export import q = require("q");
|
||||||
|
export import minimatch = require("minimatch");
|
||||||
|
3
dist/lik.plugins.js
vendored
3
dist/lik.plugins.js
vendored
@ -1,4 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
require("typings-global");
|
||||||
exports.q = require("q");
|
exports.q = require("q");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9saWsucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDIn0=
|
exports.minimatch = require("minimatch");
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9saWsucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUMifQ==
|
22
dist/lik.stringmap.d.ts
vendored
22
dist/lik.stringmap.d.ts
vendored
@ -1,8 +1,12 @@
|
|||||||
/**
|
/**
|
||||||
* allows you to easily keep track of a bunch of strings;
|
* allows you to easily keep track of a bunch of strings;
|
||||||
*/
|
*/
|
||||||
|
export interface triggerFunction {
|
||||||
|
(): boolean;
|
||||||
|
}
|
||||||
export declare class Stringmap {
|
export declare class Stringmap {
|
||||||
private _stringArray;
|
private _stringArray;
|
||||||
|
private _triggerUntilTrueFunctionArray;
|
||||||
constructor();
|
constructor();
|
||||||
/**
|
/**
|
||||||
* add a string to the Stringmap
|
* add a string to the Stringmap
|
||||||
@ -12,6 +16,10 @@ export declare class Stringmap {
|
|||||||
* removes a string from Stringmap
|
* removes a string from Stringmap
|
||||||
*/
|
*/
|
||||||
removeString(stringArg: string): void;
|
removeString(stringArg: string): void;
|
||||||
|
/**
|
||||||
|
* wipes the Stringmap
|
||||||
|
*/
|
||||||
|
wipe(): void;
|
||||||
/**
|
/**
|
||||||
* check if string is in Stringmap
|
* check if string is in Stringmap
|
||||||
*/
|
*/
|
||||||
@ -19,5 +27,17 @@ export declare class Stringmap {
|
|||||||
/**
|
/**
|
||||||
* checks stringPresence with minimatch
|
* checks stringPresence with minimatch
|
||||||
*/
|
*/
|
||||||
checkMinimatch(stringArg: string): void;
|
checkMinimatch(miniMatchStringArg: string): boolean;
|
||||||
|
/**
|
||||||
|
* checks if the Stringmap is empty
|
||||||
|
*/
|
||||||
|
checkIsEmpty(): boolean;
|
||||||
|
/**
|
||||||
|
* notifies triggers
|
||||||
|
*/
|
||||||
|
private notifyTrigger();
|
||||||
|
/**
|
||||||
|
* register a new trigger
|
||||||
|
*/
|
||||||
|
registerUntilTrue(functionArg: triggerFunction, doFunctionArg: any): void;
|
||||||
}
|
}
|
||||||
|
59
dist/lik.stringmap.js
vendored
59
dist/lik.stringmap.js
vendored
@ -1,10 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
/**
|
const plugins = require("./lik.plugins");
|
||||||
* allows you to easily keep track of a bunch of strings;
|
|
||||||
*/
|
|
||||||
class Stringmap {
|
class Stringmap {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._stringArray = [];
|
this._stringArray = [];
|
||||||
|
this._triggerUntilTrueFunctionArray = [];
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
/**
|
/**
|
||||||
@ -12,6 +11,7 @@ class Stringmap {
|
|||||||
*/
|
*/
|
||||||
addString(stringArg) {
|
addString(stringArg) {
|
||||||
this._stringArray.push(stringArg);
|
this._stringArray.push(stringArg);
|
||||||
|
this.notifyTrigger();
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
/**
|
/**
|
||||||
@ -24,6 +24,15 @@ class Stringmap {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
;
|
||||||
|
this.notifyTrigger();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* wipes the Stringmap
|
||||||
|
*/
|
||||||
|
wipe() {
|
||||||
|
this._stringArray = [];
|
||||||
|
this.notifyTrigger();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* check if string is in Stringmap
|
* check if string is in Stringmap
|
||||||
@ -34,8 +43,48 @@ class Stringmap {
|
|||||||
/**
|
/**
|
||||||
* checks stringPresence with minimatch
|
* checks stringPresence with minimatch
|
||||||
*/
|
*/
|
||||||
checkMinimatch(stringArg) {
|
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);
|
||||||
|
}
|
||||||
|
// trigger registering
|
||||||
|
/**
|
||||||
|
* notifies triggers
|
||||||
|
*/
|
||||||
|
notifyTrigger() {
|
||||||
|
let filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
|
||||||
|
return !functionArg();
|
||||||
|
});
|
||||||
|
this._triggerUntilTrueFunctionArray = filteredArray;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
/**
|
||||||
|
* register a new trigger
|
||||||
|
*/
|
||||||
|
registerUntilTrue(functionArg, doFunctionArg) {
|
||||||
|
this._triggerUntilTrueFunctionArray.push(() => {
|
||||||
|
let result = functionArg();
|
||||||
|
if (result == true) {
|
||||||
|
doFunctionArg();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
this.notifyTrigger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.Stringmap = Stringmap;
|
exports.Stringmap = Stringmap;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLnN0cmluZ21hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5zdHJpbmdtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUVBOztHQUVHO0FBQ0g7SUFFSTtRQURRLGlCQUFZLEdBQVksRUFBRSxDQUFDO0lBR25DLENBQUM7O0lBQ0Q7O09BRUc7SUFDSCxTQUFTLENBQUMsU0FBZ0I7UUFDdEIsSUFBSSxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUM7SUFDdEMsQ0FBQzs7SUFFRDs7T0FFRztJQUNILFlBQVksQ0FBQyxTQUFnQjtRQUN6QixHQUFHLENBQUMsQ0FBQyxJQUFJLE1BQU0sSUFBSSxJQUFJLENBQUMsWUFBWSxDQUFDLENBQUEsQ0FBQztZQUNsQyxFQUFFLENBQUEsQ0FBQyxJQUFJLENBQUMsWUFBWSxDQUFDLE1BQU0sQ0FBQyxJQUFJLFNBQVMsQ0FBQyxDQUFBLENBQUM7Z0JBQ3ZDLElBQUksQ0FBQyxZQUFZLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBQyxNQUFNLENBQUMsRUFBQyxDQUFDLENBQUMsQ0FBQztZQUNqRCxDQUFDO1lBQUEsQ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OztPQUVHO0lBQ0ssYUFBYTtRQUNqQixJQUFJLGFBQWEsR0FBRyxJQUFJLENBQUMsOEJBQThCLENBQUMsTUFBTSxDQUFDLENBQUMsV0FBVztZQUN2RSxNQUFNLENBQUMsQ0FBQyxXQUFXLEVBQUUsQ0FBQztRQUMxQixDQUFDLENBQUMsQ0FBQztRQUNILElBQUksQ0FBQyw4QkFBOEIsR0FBRyxhQUFhLENBQUM7SUFDeEQsQ0FBQzs7SUFFRDs7T0FFRztJQUNILGlCQUFpQixDQUFDLFdBQTJCLEVBQUMsYUFBYTtRQUN2RCxJQUFJLENBQUMsOEJBQThCLENBQUMsSUFBSSxDQUNwQztZQUNJLElBQUksTUFBTSxHQUFHLFdBQVcsRUFBRSxDQUFDO1lBQzNCLEVBQUUsQ0FBQSxDQUFDLE1BQU0sSUFBSSxJQUFJLENBQUMsQ0FBQSxDQUFDO2dCQUNmLGFBQWEsRUFBRSxDQUFDO1lBQ3BCLENBQUM7WUFDRCxNQUFNLENBQUMsTUFBTSxDQUFDO1FBQ2xCLENBQUMsQ0FDSixDQUFDO1FBQ0YsSUFBSSxDQUFDLGFBQWEsRUFBRSxDQUFDO0lBQ3pCLENBQUM7QUFDTCxDQUFDO0FBeEZZLGlCQUFTLFlBd0ZyQixDQUFBIn0=
|
@ -23,7 +23,9 @@
|
|||||||
"typings-test": "^1.0.1"
|
"typings-test": "^1.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/minimatch": "^2.0.28",
|
||||||
"@types/q": "^0.0.27",
|
"@types/q": "^0.0.27",
|
||||||
|
"minimatch": "^3.0.2",
|
||||||
"q": "^1.4.1"
|
"q": "^1.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,12 @@ describe("lik", function () {
|
|||||||
testStringmap.removeString(testString2);
|
testStringmap.removeString(testString2);
|
||||||
testStringmap.checkString(testString2).should.be.false();
|
testStringmap.checkString(testString2).should.be.false();
|
||||||
});
|
});
|
||||||
|
it("should register a function to trigger when empty", function () {
|
||||||
|
testStringmap.registerUntilTrue(() => { return testStringmap.checkIsEmpty(); }, () => { console.log("Stringmap now is empty"); });
|
||||||
|
});
|
||||||
|
it("should remove wipe and then notify", function () {
|
||||||
|
testStringmap.wipe();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxHQUFHLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDdEMsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUVoQixRQUFRLENBQUMsS0FBSyxFQUFDO0lBQ1gsUUFBUSxDQUFDLFdBQVcsRUFBQztRQUNqQixJQUFJLGFBQTJCLENBQUM7UUFDaEMsSUFBSSxXQUFXLEdBQUcsYUFBYSxDQUFDO1FBQ2hDLElBQUksV0FBVyxHQUFHLGFBQWEsQ0FBQztRQUNoQyxJQUFJLFdBQVcsR0FBRyxhQUFhLENBQUM7UUFDaEMsRUFBRSxDQUFDLHdDQUF3QyxFQUFDO1lBQ3hDLGFBQWEsR0FBRyxJQUFJLEdBQUcsQ0FBQyxTQUFTLEVBQUUsQ0FBQztZQUNwQyxhQUFhLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsR0FBRyxDQUFDLFNBQVMsQ0FBQyxDQUFDO1FBQ3RELENBQUMsQ0FBQyxDQUFDO1FBQ0gsRUFBRSxDQUFDLG9EQUFvRCxFQUFDO1lBQ3BELGFBQWEsQ0FBQyxXQUFXLENBQUMsV0FBVyxDQUFDLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUM3RCxDQUF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ENBQUMsRUFBRSxDQUFDLElBQUksRUFBRSxDQUFDO1lBQ3hELGFBQWEsQ0FBQyxXQUFXLENBQUMsV0FBVyxDQUFDLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxJQUFJLEVBQUUsQ0FBQztRQUM1RCxDQUFDLENBQUMsQ0FBQztRQUNILEVBQUUsQ0FBQyx1Q0FBdUMsRUFBQztZQUN2QyxhQUFhLENBQUMsWUFBWSxDQUFDLFdBQVcsQ0FBQyxDQUFDO1lBQ3hDLGFBQWEsQ0FBQyxXQUFXLENBQUMsV0FBVyxDQUFDLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUM3RCxDQUFDLENBQUMsQ0FBQztRQUNILEVBQUUsQ0FBQyxrREFBa0QsRUFBQztZQUNsRCxhQUFhLENBQUMsaUJBQWlCLENBQzNCLFFBQU8sTUFBTSxDQUFDLGFBQWEsQ0FBQyxZQUFZLEVBQUUsQ0FBQSxDQUFBLENBQUMsRUFDM0MsUUFBTyxPQUFPLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLENBQUEsQ0FBQSxDQUFDLENBQ2hELENBQUM7UUFDTixDQUFDLENBQUMsQ0FBQztRQUNILEVBQUUsQ0FBQyxvQ0FBb0MsRUFBQztZQUNwQyxhQUFhLENBQUMsSUFBSSxFQUFFLENBQUM7UUFDekIsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFDIn0=
|
@ -27,5 +27,14 @@ describe("lik",function(){
|
|||||||
testStringmap.removeString(testString2);
|
testStringmap.removeString(testString2);
|
||||||
testStringmap.checkString(testString2).should.be.false();
|
testStringmap.checkString(testString2).should.be.false();
|
||||||
});
|
});
|
||||||
|
it("should register a function to trigger when empty",function(){
|
||||||
|
testStringmap.registerUntilTrue(
|
||||||
|
() => {return testStringmap.checkIsEmpty()},
|
||||||
|
() => {console.log("Stringmap now is empty")}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it("should remove wipe and then notify",function(){
|
||||||
|
testStringmap.wipe();
|
||||||
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
@ -1,2 +1,3 @@
|
|||||||
import "typings-global";
|
import "typings-global";
|
||||||
export import q = require("q");
|
export import q = require("q");
|
||||||
|
export import minimatch = require("minimatch");
|
@ -3,8 +3,14 @@ import * as plugins from "./lik.plugins";
|
|||||||
/**
|
/**
|
||||||
* allows you to easily keep track of a bunch of strings;
|
* allows you to easily keep track of a bunch of strings;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export interface triggerFunction {
|
||||||
|
():boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export class Stringmap {
|
export class Stringmap {
|
||||||
private _stringArray:string[] = [];
|
private _stringArray:string[] = [];
|
||||||
|
private _triggerUntilTrueFunctionArray:triggerFunction[] = [];
|
||||||
constructor(){
|
constructor(){
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -13,6 +19,7 @@ export class Stringmap {
|
|||||||
*/
|
*/
|
||||||
addString(stringArg:string){
|
addString(stringArg:string){
|
||||||
this._stringArray.push(stringArg);
|
this._stringArray.push(stringArg);
|
||||||
|
this.notifyTrigger();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +30,16 @@ export class Stringmap {
|
|||||||
if(this._stringArray[keyArg] == stringArg){
|
if(this._stringArray[keyArg] == stringArg){
|
||||||
this._stringArray.splice(parseInt(keyArg),1);
|
this._stringArray.splice(parseInt(keyArg),1);
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
this.notifyTrigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wipes the Stringmap
|
||||||
|
*/
|
||||||
|
wipe(){
|
||||||
|
this._stringArray = [];
|
||||||
|
this.notifyTrigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +52,48 @@ export class Stringmap {
|
|||||||
/**
|
/**
|
||||||
* checks stringPresence with minimatch
|
* checks stringPresence with minimatch
|
||||||
*/
|
*/
|
||||||
checkMinimatch(stringArg:string){
|
checkMinimatch(miniMatchStringArg:string):boolean {
|
||||||
|
let foundMatch:boolean = 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
if(result == true){
|
||||||
|
doFunctionArg();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
this.notifyTrigger();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user