now adhering to standard js added getStringArray method

This commit is contained in:
2016-09-21 13:44:11 +02:00
parent c0a5cb6e30
commit e917c8b9f7
17 changed files with 271 additions and 258 deletions

View File

@ -1,6 +1,6 @@
import * as plugins from "./lik.plugins";
import * as plugins from './lik.plugins'
// import modules
export * from "./lik.stringmap";
export * from "./lik.objectmap";
export * from './lik.stringmap'
export * from './lik.objectmap'

View File

@ -1,81 +1,76 @@
import * as plugins from "./lik.plugins";
import * as plugins from './lik.plugins'
export interface IObjectmapForEachFunction<T> {
(itemArg: T): void
};
}
export interface IObjectmapFindFunction<T> {
(itemArg: T): boolean
};
}
/**
* allows keeping track of objects
*/
export class Objectmap<T> {
private objectArray:T[] = [];
private objectArray: T[] = []
/**
* returns a new instance
*/
constructor() {
};
}
/**
* add object to Objectmap
*/
add(objectArg:T) {
this.objectArray.push(objectArg);
};
add(objectArg: T) {
this.objectArray.push(objectArg)
}
/**
* remove object from Objectmap
*/
remove(objectArg:T) {
let replacmentArray = [];
remove(objectArg: T) {
let replacmentArray = []
for (let item of this.objectArray) {
if (item !== objectArg) {
replacmentArray.push(item);
replacmentArray.push(item)
}
};
this.objectArray = replacmentArray;
};
}
this.objectArray = replacmentArray
}
/**
* check if object is in Objectmap
*/
checkForObject(objectArg:T) {
checkForObject(objectArg: T) {
return this.objectArray.indexOf(objectArg) !== -1
};
}
/**
* find object
*/
find(findFunction: IObjectmapFindFunction<T>) {
let resultArray = this.objectArray.filter(findFunction);
let resultArray = this.objectArray.filter(findFunction)
if (resultArray.length > 0) {
return resultArray[0];
return resultArray[0]
} else {
return undefined;
};
return undefined
}
}
/**
* run function for each item in Objectmap
*/
forEach(functionArg: IObjectmapForEachFunction<T>) {
return this.objectArray.forEach(functionArg);
};
return this.objectArray.forEach(functionArg)
}
/**
* wipe Objectmap
*/
wipe() {
this.objectArray = [];
this.objectArray = []
}
}
}

View File

@ -1,3 +1,4 @@
import "typings-global";
export import q = require("q");
export import minimatch = require("minimatch");
import 'typings-global'
export import q = require('q')
export import lodash = require('lodash')
export import minimatch = require('minimatch')

View File

@ -1,99 +1,105 @@
import * as plugins from "./lik.plugins";
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 interface ITriggerFunction {
(): boolean
}
export class Stringmap {
private _stringArray:string[] = [];
private _triggerUntilTrueFunctionArray:triggerFunction[] = [];
constructor(){
};
private _stringArray: string[] = []
private _triggerUntilTrueFunctionArray: ITriggerFunction[] = []
constructor() {}
/**
* add a string to the Stringmap
*/
addString(stringArg:string){
this._stringArray.push(stringArg);
this.notifyTrigger();
};
addString(stringArg: string) {
this._stringArray.push(stringArg)
this.notifyTrigger()
}
/**
* removes a string from Stringmap
*/
removeString(stringArg:string){
for (let keyArg in this._stringArray){
if(this._stringArray[keyArg] === stringArg){
this._stringArray.splice(parseInt(keyArg),1);
};
};
this.notifyTrigger();
removeString(stringArg: string) {
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();
wipe() {
this._stringArray = []
this.notifyTrigger()
}
/**
* check if string is in Stringmap
*/
checkString(stringArg:string):boolean {
return this._stringArray.indexOf(stringArg) != -1;
checkString(stringArg: string): boolean {
return this._stringArray.indexOf(stringArg) !== -1
}
/**
* checks stringPresence with minimatch
*/
checkMinimatch(miniMatchStringArg:string):boolean {
let foundMatch:boolean = false;
for(let stringItem of this._stringArray){
if(plugins.minimatch(stringItem,miniMatchStringArg)){
foundMatch = true;
};
};
return foundMatch;
};
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);
checkIsEmpty() {
return (this._stringArray.length === 0)
}
/**
* gets a cloned copy of the current string Array
*/
getStringArray() {
return plugins.lodash.cloneDeep(this._stringArray)
}
// 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){
registerUntilTrue(functionArg: ITriggerFunction,doFunctionArg) {
this._triggerUntilTrueFunctionArray.push(
() => {
let result = functionArg();
if(result === true){
doFunctionArg();
let result = functionArg()
if (result === true) {
doFunctionArg()
}
return result;
return result
}
);
this.notifyTrigger();
)
this.notifyTrigger()
}
}
/**
* notifies triggers
*/
private notifyTrigger() {
let filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
return !functionArg()
})
this._triggerUntilTrueFunctionArray = filteredArray
}
}