Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
bb3b02ed74 | |||
bb4820e980 | |||
fa17a998f1 | |||
afad357ed0 | |||
59173eebc4 | |||
515571dcb3 | |||
177ed2d03d | |||
23ecaddd5a | |||
924058c90a | |||
30e23a77b7 | |||
b228c3b2f0 | |||
610a037879 | |||
2f681911ae | |||
3b04f81b68 | |||
0c05cf4f7b | |||
5451cceaf3 | |||
04dbc36525 | |||
a820e0d1b3 | |||
57c67a287a | |||
d73bfa8f00 | |||
e917c8b9f7 | |||
c0a5cb6e30 | |||
b85e79b07d | |||
ba714fe637 | |||
3dd4698ce8 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
docs/
|
pages/
|
||||||
|
public/
|
||||||
coverage/
|
coverage/
|
||||||
.nogit/
|
.nogit/
|
@ -3,6 +3,7 @@ image: hosttoday/ht-docker-node:npmts
|
|||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
|
- page
|
||||||
|
|
||||||
testLEGACY:
|
testLEGACY:
|
||||||
stage: test
|
stage: test
|
||||||
@ -34,3 +35,15 @@ release:
|
|||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
|
pages:
|
||||||
|
image: hosttoday/ht-docker-node:npmpage
|
||||||
|
stage: page
|
||||||
|
script:
|
||||||
|
- npmci command npmpage --host gitlab
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- public
|
||||||
|
35
README.md
35
README.md
@ -1,13 +1,44 @@
|
|||||||
# lik
|
# lik
|
||||||
light little helpers for node
|
light little helpers for node
|
||||||
|
|
||||||
## Status
|
## Availabililty
|
||||||
|
[](https://www.npmjs.com/package/lik)
|
||||||
|
[](https://gitlab.com/pushrocks/lik)
|
||||||
|
[](https://github.com/pushrocks/lik)
|
||||||
|
[](https://pushrocks.gitlab.io/lik/gitbook)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
[](https://gitlab.com/pushrocks/lik/commits/master)
|
[](https://gitlab.com/pushrocks/lik/commits/master)
|
||||||
|
[](https://gitlab.com/pushrocks/lik/commits/master)
|
||||||
|
[](https://david-dm.org/pushrocks/lik)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/lik/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/lik)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
We recommend the use of TypeScript for good intellisense.
|
We recommend the use of TypeScript for good intellisense.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// import any tool that you need from lik
|
// import any tool that you need from lik
|
||||||
import {Stringmap} from "lik";
|
import { Stringmap, Objectmap, Observablemap } from "lik";
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### class Stringmap
|
||||||
|
Stringmap allows you to keep track of strings. It allows you to register triggers for certain events
|
||||||
|
like when a certain string is removed or added to the map
|
||||||
|
|
||||||
|
### class Objectmap
|
||||||
|
Sometimes you need to keep track of objects, but implementing logic for removing, finding or updating is tedious.
|
||||||
|
Objectmap takes care of keeping track of objects for you.
|
||||||
|
|
||||||
|
### class Observablemap
|
||||||
|
Event Emitters are nice. However often times you end up with registering multiple listeners for the exact same thing.
|
||||||
|
Observables have a smaller footprint and a more manageable subscribe logic.
|
||||||
|
Observablemap registers only one rxjs observable per event and then continues to reference
|
||||||
|
the same observable that you can subscribe to.
|
||||||
|
|
||||||
|
**For a detailed class overview, please take a look at the API docs**
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
||||||
|
5
dist/index.d.ts
vendored
5
dist/index.d.ts
vendored
@ -1,2 +1,3 @@
|
|||||||
export * from "./lik.stringmap";
|
export * from './lik.stringmap';
|
||||||
export * from "./lik.objectmap";
|
export * from './lik.objectmap';
|
||||||
|
export * from './lik.observablemap';
|
||||||
|
3
dist/index.js
vendored
3
dist/index.js
vendored
@ -5,4 +5,5 @@ function __export(m) {
|
|||||||
// import modules
|
// import modules
|
||||||
__export(require("./lik.stringmap"));
|
__export(require("./lik.stringmap"));
|
||||||
__export(require("./lik.objectmap"));
|
__export(require("./lik.objectmap"));
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaUJBQWlCO0FBRWpCLGlCQUFjLGlCQUFpQixDQUFDLEVBQUE7QUFDaEMsaUJBQWMsaUJBQWlCLENBQUMsRUFBQSJ9
|
__export(require("./lik.observablemap"));
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaUJBQWlCO0FBRWpCLHFDQUErQjtBQUMvQixxQ0FBK0I7QUFDL0IseUNBQW1DIn0=
|
38
dist/lik.objectmap.d.ts
vendored
38
dist/lik.objectmap.d.ts
vendored
@ -1,13 +1,13 @@
|
|||||||
export interface IObjectmapForEachFunction {
|
export interface IObjectmapForEachFunction<T> {
|
||||||
(itemArg: any): void;
|
(itemArg: T): void;
|
||||||
}
|
}
|
||||||
export interface IObjectmapFindFunction {
|
export interface IObjectmapFindFunction<T> {
|
||||||
(itemArg: any): boolean;
|
(itemArg: T): boolean;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* allows keeping track of objects
|
* allows keeping track of objects
|
||||||
*/
|
*/
|
||||||
export declare class Objectmap {
|
export declare class Objectmap<T> {
|
||||||
private objectArray;
|
private objectArray;
|
||||||
/**
|
/**
|
||||||
* returns a new instance
|
* returns a new instance
|
||||||
@ -16,23 +16,39 @@ export declare class Objectmap {
|
|||||||
/**
|
/**
|
||||||
* add object to Objectmap
|
* add object to Objectmap
|
||||||
*/
|
*/
|
||||||
add(objectArg: any): void;
|
add(objectArg: T): void;
|
||||||
/**
|
/**
|
||||||
* remove object from Objectmap
|
* like .add but adds an whole array of objects
|
||||||
*/
|
*/
|
||||||
remove(objectArg: any): void;
|
addArray(objectArrayArg: T[]): void;
|
||||||
/**
|
/**
|
||||||
* check if object is in Objectmap
|
* check if object is in Objectmap
|
||||||
*/
|
*/
|
||||||
checkForObject(objectArg: any): number;
|
checkForObject(objectArg: T): boolean;
|
||||||
/**
|
/**
|
||||||
* find object
|
* find object
|
||||||
*/
|
*/
|
||||||
find(findFunction: IObjectmapFindFunction): any;
|
find(findFunction: IObjectmapFindFunction<T>): T;
|
||||||
/**
|
/**
|
||||||
* run function for each item in Objectmap
|
* run function for each item in Objectmap
|
||||||
*/
|
*/
|
||||||
forEach(functionArg: IObjectmapForEachFunction): void;
|
forEach(functionArg: IObjectmapForEachFunction<T>): void;
|
||||||
|
/**
|
||||||
|
* gets an object in the Observablemap and removes it, so it can't be retrieved again
|
||||||
|
*/
|
||||||
|
getOneAndRemove(): T;
|
||||||
|
/**
|
||||||
|
* finds a specific element and then removes it
|
||||||
|
*/
|
||||||
|
findOneAndRemove(findFunction: any): T;
|
||||||
|
/**
|
||||||
|
* returns a cloned array of all the objects currently in the Objectmap
|
||||||
|
*/
|
||||||
|
getArray(): T[];
|
||||||
|
/**
|
||||||
|
* remove object from Objectmap
|
||||||
|
*/
|
||||||
|
remove(objectArg: T): void;
|
||||||
/**
|
/**
|
||||||
* wipe Objectmap
|
* wipe Objectmap
|
||||||
*/
|
*/
|
||||||
|
61
dist/lik.objectmap.js
vendored
61
dist/lik.objectmap.js
vendored
@ -1,6 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
;
|
const plugins = require("./lik.plugins");
|
||||||
;
|
|
||||||
/**
|
/**
|
||||||
* allows keeping track of objects
|
* allows keeping track of objects
|
||||||
*/
|
*/
|
||||||
@ -11,35 +10,26 @@ class Objectmap {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.objectArray = [];
|
this.objectArray = [];
|
||||||
}
|
}
|
||||||
;
|
|
||||||
/**
|
/**
|
||||||
* add object to Objectmap
|
* add object to Objectmap
|
||||||
*/
|
*/
|
||||||
add(objectArg) {
|
add(objectArg) {
|
||||||
this.objectArray.push(objectArg);
|
this.objectArray.push(objectArg);
|
||||||
}
|
}
|
||||||
;
|
|
||||||
/**
|
/**
|
||||||
* remove object from Objectmap
|
* like .add but adds an whole array of objects
|
||||||
*/
|
*/
|
||||||
remove(objectArg) {
|
addArray(objectArrayArg) {
|
||||||
let replacmentArray = [];
|
for (let item of objectArrayArg) {
|
||||||
for (let item of this.objectArray) {
|
this.add(item);
|
||||||
if (item !== objectArg) {
|
|
||||||
replacmentArray.push(item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
|
||||||
this.objectArray = replacmentArray;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
/**
|
/**
|
||||||
* check if object is in Objectmap
|
* check if object is in Objectmap
|
||||||
*/
|
*/
|
||||||
checkForObject(objectArg) {
|
checkForObject(objectArg) {
|
||||||
return this.objectArray.indexOf(objectArg !== -1);
|
return this.objectArray.indexOf(objectArg) !== -1;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
/**
|
/**
|
||||||
* find object
|
* find object
|
||||||
*/
|
*/
|
||||||
@ -49,9 +39,8 @@ class Objectmap {
|
|||||||
return resultArray[0];
|
return resultArray[0];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return undefined;
|
return null;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* run function for each item in Objectmap
|
* run function for each item in Objectmap
|
||||||
@ -59,6 +48,40 @@ class Objectmap {
|
|||||||
forEach(functionArg) {
|
forEach(functionArg) {
|
||||||
return this.objectArray.forEach(functionArg);
|
return this.objectArray.forEach(functionArg);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* gets an object in the Observablemap and removes it, so it can't be retrieved again
|
||||||
|
*/
|
||||||
|
getOneAndRemove() {
|
||||||
|
return this.objectArray.shift();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* finds a specific element and then removes it
|
||||||
|
*/
|
||||||
|
findOneAndRemove(findFunction) {
|
||||||
|
let foundElement = this.find(findFunction);
|
||||||
|
if (foundElement) {
|
||||||
|
this.remove(foundElement);
|
||||||
|
}
|
||||||
|
return foundElement;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* returns a cloned array of all the objects currently in the Objectmap
|
||||||
|
*/
|
||||||
|
getArray() {
|
||||||
|
return plugins.lodash.cloneDeep(this.objectArray);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* remove object from Objectmap
|
||||||
|
*/
|
||||||
|
remove(objectArg) {
|
||||||
|
let replacementArray = [];
|
||||||
|
for (let item of this.objectArray) {
|
||||||
|
if (item !== objectArg) {
|
||||||
|
replacementArray.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.objectArray = replacementArray;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* wipe Objectmap
|
* wipe Objectmap
|
||||||
*/
|
*/
|
||||||
@ -67,4 +90,4 @@ class Objectmap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.Objectmap = Objectmap;
|
exports.Objectmap = Objectmap;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUtDLENBQUM7QUFJ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xRQUFRO1FBQ0osTUFBTSxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQTtJQUNyRCxDQUFDO0lBRUQ7O09BRUc7SUFDSCxNQUFNLENBQUMsU0FBWTtRQUNmLElBQUksZ0JBQWdCLEdBQUcsRUFBRSxDQUFBO1FBQ3pCLEdBQUcsQ0FBQyxDQUFDLElBQUksSUFBSSxJQUFJLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQyxDQUFDO1lBQ2hDLEVBQUUsQ0FBQyxDQUFDLElBQUksS0FBSyxTQUFTLENBQUMsQ0FBQyxDQUFDO2dCQUNyQixnQkFBZ0IsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUE7WUFDL0IsQ0FBQztRQUNMLENBQUM7UUFDRCxJQUFJLENBQUMsV0FBVyxHQUFHLGdCQUFnQixDQUFBO0lBQ3ZDLENBQUM7SUFFRDs7T0FFRztJQUNILElBQUk7UUFDQSxJQUFJLENBQUMsV0FBVyxHQUFHLEVBQUUsQ0FBQTtJQUN6QixDQUFDO0NBQ0o7QUFoR0QsOEJBZ0dDIn0=
|
23
dist/lik.observablemap.d.ts
vendored
Normal file
23
dist/lik.observablemap.d.ts
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/// <reference types="node" />
|
||||||
|
import * as plugins from './lik.plugins';
|
||||||
|
import { Objectmap } from './lik.objectmap';
|
||||||
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
/**
|
||||||
|
* bundles an observable with an emitter
|
||||||
|
*/
|
||||||
|
export interface ObservableEmitterBundle {
|
||||||
|
observable: plugins.rx.Observable<any>;
|
||||||
|
emitter: plugins.events.EventEmitter;
|
||||||
|
event: string;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* manages observables by making sure that only one observable is regsitered per event
|
||||||
|
*/
|
||||||
|
export declare class Observablemap {
|
||||||
|
ObservableEmitterBundleObjectmap: Objectmap<ObservableEmitterBundle>;
|
||||||
|
/**
|
||||||
|
* creates a new observable if not yet registered for the same event.
|
||||||
|
* In case event has been registered before the same observable is returned.
|
||||||
|
*/
|
||||||
|
getObservableForEmitterEvent(emitterArg: plugins.events.EventEmitter, eventArg: string): Observable<any>;
|
||||||
|
}
|
34
dist/lik.observablemap.js
vendored
Normal file
34
dist/lik.observablemap.js
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
"use strict";
|
||||||
|
const plugins = require("./lik.plugins");
|
||||||
|
const lik_objectmap_1 = require("./lik.objectmap");
|
||||||
|
/**
|
||||||
|
* manages observables by making sure that only one observable is regsitered per event
|
||||||
|
*/
|
||||||
|
class Observablemap {
|
||||||
|
constructor() {
|
||||||
|
this.ObservableEmitterBundleObjectmap = new lik_objectmap_1.Objectmap();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* creates a new observable if not yet registered for the same event.
|
||||||
|
* In case event has been registered before the same observable is returned.
|
||||||
|
*/
|
||||||
|
getObservableForEmitterEvent(emitterArg, eventArg) {
|
||||||
|
let existingBundle = this.ObservableEmitterBundleObjectmap.find((bundleArg) => {
|
||||||
|
return (bundleArg.emitter === emitterArg && bundleArg.event === eventArg);
|
||||||
|
});
|
||||||
|
if (existingBundle) {
|
||||||
|
return existingBundle.observable;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let emitterObservable = plugins.rx.Observable.fromEvent(emitterArg, eventArg);
|
||||||
|
this.ObservableEmitterBundleObjectmap.add({
|
||||||
|
observable: emitterObservable,
|
||||||
|
emitter: emitterArg,
|
||||||
|
event: eventArg
|
||||||
|
});
|
||||||
|
return emitterObservable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.Observablemap = Observablemap;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9ic2VydmFibGVtYXAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9sa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@ -1,3 +1,6 @@
|
|||||||
import "typings-global";
|
import 'typings-global';
|
||||||
export import q = require("q");
|
export import q = require('q');
|
||||||
export import minimatch = require("minimatch");
|
export import events = require('events');
|
||||||
|
export import lodash = require('lodash');
|
||||||
|
export import minimatch = require('minimatch');
|
||||||
|
export import rx = require('rxjs/Rx');
|
||||||
|
5
dist/lik.plugins.js
vendored
5
dist/lik.plugins.js
vendored
@ -1,5 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
require("typings-global");
|
||||||
exports.q = require("q");
|
exports.q = require("q");
|
||||||
|
exports.events = require("events");
|
||||||
|
exports.lodash = require("lodash");
|
||||||
exports.minimatch = require("minimatch");
|
exports.minimatch = require("minimatch");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9saWsucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUMifQ==
|
exports.rx = require("rxjs/Rx");
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9saWsucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHlCQUE4QjtBQUM5QixtQ0FBd0M7QUFDeEMsbUNBQXdDO0FBQ3hDLHlDQUE4QztBQUM5QyxnQ0FBcUMifQ==
|
18
dist/lik.stringmap.d.ts
vendored
18
dist/lik.stringmap.d.ts
vendored
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* 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 {
|
export interface ITriggerFunction {
|
||||||
(): boolean;
|
(): boolean;
|
||||||
}
|
}
|
||||||
export declare class Stringmap {
|
export declare class Stringmap {
|
||||||
@ -12,6 +12,10 @@ export declare class Stringmap {
|
|||||||
* add a string to the Stringmap
|
* add a string to the Stringmap
|
||||||
*/
|
*/
|
||||||
addString(stringArg: string): void;
|
addString(stringArg: string): void;
|
||||||
|
/**
|
||||||
|
* like addString, but accepts an array of strings
|
||||||
|
*/
|
||||||
|
addStringArray(stringArrayArg: string[]): void;
|
||||||
/**
|
/**
|
||||||
* removes a string from Stringmap
|
* removes a string from Stringmap
|
||||||
*/
|
*/
|
||||||
@ -33,11 +37,15 @@ export declare class Stringmap {
|
|||||||
*/
|
*/
|
||||||
checkIsEmpty(): boolean;
|
checkIsEmpty(): boolean;
|
||||||
/**
|
/**
|
||||||
* notifies triggers
|
* gets a cloned copy of the current string Array
|
||||||
*/
|
*/
|
||||||
private notifyTrigger();
|
getStringArray(): string[];
|
||||||
/**
|
/**
|
||||||
* register a new trigger
|
* register a new trigger
|
||||||
*/
|
*/
|
||||||
registerUntilTrue(functionArg: triggerFunction, doFunctionArg: any): void;
|
registerUntilTrue(functionArg: ITriggerFunction, doFunctionArg: any): void;
|
||||||
|
/**
|
||||||
|
* notifies triggers
|
||||||
|
*/
|
||||||
|
private notifyTrigger();
|
||||||
}
|
}
|
||||||
|
40
dist/lik.stringmap.js
vendored
40
dist/lik.stringmap.js
vendored
@ -5,7 +5,6 @@ class Stringmap {
|
|||||||
this._stringArray = [];
|
this._stringArray = [];
|
||||||
this._triggerUntilTrueFunctionArray = [];
|
this._triggerUntilTrueFunctionArray = [];
|
||||||
}
|
}
|
||||||
;
|
|
||||||
/**
|
/**
|
||||||
* add a string to the Stringmap
|
* add a string to the Stringmap
|
||||||
*/
|
*/
|
||||||
@ -13,7 +12,14 @@ class Stringmap {
|
|||||||
this._stringArray.push(stringArg);
|
this._stringArray.push(stringArg);
|
||||||
this.notifyTrigger();
|
this.notifyTrigger();
|
||||||
}
|
}
|
||||||
;
|
/**
|
||||||
|
* like addString, but accepts an array of strings
|
||||||
|
*/
|
||||||
|
addStringArray(stringArrayArg) {
|
||||||
|
for (let stringItem of stringArrayArg) {
|
||||||
|
this.addString(stringItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* removes a string from Stringmap
|
* removes a string from Stringmap
|
||||||
*/
|
*/
|
||||||
@ -22,9 +28,7 @@ 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();
|
this.notifyTrigger();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -38,7 +42,7 @@ class Stringmap {
|
|||||||
* check if string is in Stringmap
|
* check if string is in Stringmap
|
||||||
*/
|
*/
|
||||||
checkString(stringArg) {
|
checkString(stringArg) {
|
||||||
return this._stringArray.indexOf(stringArg) != -1;
|
return this._stringArray.indexOf(stringArg) !== -1;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* checks stringPresence with minimatch
|
* checks stringPresence with minimatch
|
||||||
@ -49,29 +53,22 @@ class Stringmap {
|
|||||||
if (plugins.minimatch(stringItem, miniMatchStringArg)) {
|
if (plugins.minimatch(stringItem, miniMatchStringArg)) {
|
||||||
foundMatch = true;
|
foundMatch = true;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
;
|
|
||||||
return foundMatch;
|
return foundMatch;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
/**
|
/**
|
||||||
* checks if the Stringmap is empty
|
* checks if the Stringmap is empty
|
||||||
*/
|
*/
|
||||||
checkIsEmpty() {
|
checkIsEmpty() {
|
||||||
return (this._stringArray.length === 0);
|
return (this._stringArray.length === 0);
|
||||||
}
|
}
|
||||||
// trigger registering
|
|
||||||
/**
|
/**
|
||||||
* notifies triggers
|
* gets a cloned copy of the current string Array
|
||||||
*/
|
*/
|
||||||
notifyTrigger() {
|
getStringArray() {
|
||||||
let filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
|
return plugins.lodash.cloneDeep(this._stringArray);
|
||||||
return !functionArg();
|
|
||||||
});
|
|
||||||
this._triggerUntilTrueFunctionArray = filteredArray;
|
|
||||||
}
|
}
|
||||||
;
|
// trigger registering
|
||||||
/**
|
/**
|
||||||
* register a new trigger
|
* register a new trigger
|
||||||
*/
|
*/
|
||||||
@ -85,6 +82,15 @@ class Stringmap {
|
|||||||
});
|
});
|
||||||
this.notifyTrigger();
|
this.notifyTrigger();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* notifies triggers
|
||||||
|
*/
|
||||||
|
notifyTrigger() {
|
||||||
|
let filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
|
||||||
|
return !functionArg();
|
||||||
|
});
|
||||||
|
this._triggerUntilTrueFunctionArray = filteredArray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.Stringmap = Stringmap;
|
exports.Stringmap = Stringmap;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLnN0cmluZ21hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5zdHJpbmdtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLGVBQWUsQ0FBQyxDQUFBO0FBVXpDO0lBR0k7UUFGUSxpQkFBWSxHQUFZLEVBQUUsQ0FBQztRQUMzQixtQ0FBOEIsR0FBcUIsRUFBRSxDQUFDO0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BQztJQUVELHNCQUFzQjtJQUV0Qjs7T0FFRztJQUNILGlCQUFpQixDQUFDLFdBQTZCLEVBQUMsYUFBYTtRQUN6RCxJQUFJLENBQUMsOEJBQThCLENBQUMsSUFBSSxDQUNwQztZQUNJLElBQUksTUFBTSxHQUFHLFdBQVcsRUFBRSxDQUFBO1lBQzFCLEVBQUUsQ0FBQyxDQUFDLE1BQU0sS0FBSyxJQUFJLENBQUMsQ0FBQyxDQUFDO2dCQUNsQixhQUFhLEVBQUUsQ0FBQTtZQUNuQixDQUFDO1lBQ0QsTUFBTSxDQUFDLE1BQU0sQ0FBQTtRQUNqQixDQUFDLENBQ0osQ0FBQTtRQUNELElBQUksQ0FBQyxhQUFhLEVBQUUsQ0FBQTtJQUN4QixDQUFDO0lBRUQ7O09BRUc7SUFDSyxhQUFhO1FBQ2pCLElBQUksYUFBYSxHQUFHLElBQUksQ0FBQyw4QkFBOEIsQ0FBQyxNQUFNLENBQUMsQ0FBQyxXQUFXO1lBQ3ZFLE1BQU0sQ0FBQyxDQUFDLFdBQVcsRUFBRSxDQUFBO1FBQ3pCLENBQUMsQ0FBQyxDQUFBO1FBQ0YsSUFBSSxDQUFDLDhCQUE4QixHQUFHLGFBQWEsQ0FBQTtJQUN2RCxDQUFDO0NBRUo7QUF2R0QsOEJBdUdDIn0=
|
17
package.json
17
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lik",
|
"name": "lik",
|
||||||
"version": "1.0.13",
|
"version": "1.0.26",
|
||||||
"description": "light little helpers for node",
|
"description": "light little helpers for node",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
@ -18,14 +18,19 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/lik#README",
|
"homepage": "https://gitlab.com/pushrocks/lik#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts-g": "^5.2.6",
|
"@types/should": "^8.1.30",
|
||||||
"should": "^10.0.0",
|
"npmts-g": "^5.2.8",
|
||||||
"typings-test": "^1.0.1"
|
"should": "^11.1.0",
|
||||||
|
"typings-test": "^1.0.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/lodash": "^4.14.35",
|
||||||
"@types/minimatch": "2.x.x",
|
"@types/minimatch": "2.x.x",
|
||||||
"@types/q": "0.x.x",
|
"@types/q": "0.x.x",
|
||||||
"minimatch": "^3.0.2",
|
"lodash": "^4.16.1",
|
||||||
"q": "^1.4.1"
|
"minimatch": "^3.0.3",
|
||||||
|
"q": "^1.4.1",
|
||||||
|
"rxjs": "^5.0.0-beta.12",
|
||||||
|
"typings-global": "^1.0.14"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
test/test.d.ts
vendored
3
test/test.d.ts
vendored
@ -1,2 +1 @@
|
|||||||
import "typings-test";
|
import 'typings-test';
|
||||||
import "should";
|
|
||||||
|
133
test/test.js
133
test/test.js
File diff suppressed because one or more lines are too long
202
test/test.ts
202
test/test.ts
@ -1,84 +1,134 @@
|
|||||||
import "typings-test";
|
import 'typings-test'
|
||||||
import lik = require("../dist/index");
|
import * as events from 'events'
|
||||||
import "should";
|
import * as rx from 'rxjs/Rx'
|
||||||
|
import * as should from 'should'
|
||||||
|
|
||||||
describe("lik",function(){
|
import lik = require('../dist/index')
|
||||||
describe("Stringmap",function(){
|
describe('lik',function(){
|
||||||
let testStringmap:lik.Stringmap;
|
describe('Stringmap',function(){
|
||||||
let testString1 = "testString1";
|
let testStringmap: lik.Stringmap
|
||||||
let testString2 = "testString2";
|
let testString1 = 'testString1'
|
||||||
let testString3 = "testString3";
|
let testString2 = 'testString2'
|
||||||
it("should create an instance of Stringmap",function(){
|
let testString3 = 'testString3'
|
||||||
testStringmap = new lik.Stringmap();
|
let testString4 = 'testString4'
|
||||||
testStringmap.should.be.instanceof(lik.Stringmap);
|
let testString5 = 'testString5'
|
||||||
});
|
let testString6 = 'testString6'
|
||||||
it("should return false for an string not in Stringmap",function(){
|
it('new lik.Objectmap() -> should create an instance of Stringmap',function(){
|
||||||
testStringmap.checkString(testString1).should.be.false();
|
testStringmap = new lik.Stringmap()
|
||||||
});
|
should(testStringmap).be.instanceof(lik.Stringmap)
|
||||||
it("should add an string to Stringmap",function(){
|
})
|
||||||
testStringmap.addString(testString1);
|
it('lik.Stringmap.checkString -> should return false for an string not in Stringmap',function(){
|
||||||
testStringmap.addString(testString2);
|
should(testStringmap.checkString(testString1)).be.false()
|
||||||
testStringmap.addString(testString3);
|
})
|
||||||
testStringmap.checkString(testString1).should.be.true();
|
it('lik.Stringmap.addString -> should add an string to Stringmap',function(){
|
||||||
testStringmap.checkString(testString2).should.be.true();
|
testStringmap.addString(testString1)
|
||||||
testStringmap.checkString(testString3).should.be.true();
|
testStringmap.addString(testString2)
|
||||||
testStringmap.checkMinimatch("*String1").should.be.true();
|
testStringmap.addString(testString3)
|
||||||
testStringmap.checkMinimatch("*String2").should.be.true();
|
should(testStringmap.checkString(testString1)).be.true()
|
||||||
testStringmap.checkMinimatch("*String4").should.be.false();
|
should(testStringmap.checkString(testString2)).be.true()
|
||||||
});
|
should(testStringmap.checkString(testString3)).be.true()
|
||||||
it("should remove a string from Stringmap",function(){
|
should(testStringmap.checkMinimatch('*String1')).be.true()
|
||||||
testStringmap.removeString(testString2);
|
should(testStringmap.checkMinimatch('*String2')).be.true()
|
||||||
testStringmap.checkString(testString2).should.be.false();
|
should(testStringmap.checkMinimatch('*String4')).be.false()
|
||||||
});
|
})
|
||||||
it("should register a function to trigger when empty",function(){
|
it('lik.Stringmap.addStringArray -> should add an array of strings',function(){
|
||||||
|
testStringmap.addStringArray([testString4,testString5,testString6])
|
||||||
|
should(testStringmap.checkMinimatch('*String4')).be.true()
|
||||||
|
})
|
||||||
|
it('lik.Stringmap.removeString -> should remove a string from Stringmap',function(){
|
||||||
|
testStringmap.removeString(testString2)
|
||||||
|
should(testStringmap.checkString(testString2)).be.false()
|
||||||
|
})
|
||||||
|
it('lik.Stringmap.getStringArray() -> should return a copy of stringArray',function(){
|
||||||
|
let clonedArray = testStringmap.getStringArray()
|
||||||
|
should(clonedArray[0] === 'testString1').be.true()
|
||||||
|
should(clonedArray[0] === testString1).be.true()
|
||||||
|
})
|
||||||
|
it('lik.Stringmap.checkIsEmpty() -> should register a function to trigger when empty',function(){
|
||||||
testStringmap.registerUntilTrue(
|
testStringmap.registerUntilTrue(
|
||||||
() => {return testStringmap.checkIsEmpty()},
|
() => { return testStringmap.checkIsEmpty() },
|
||||||
() => {console.log("Stringmap now is empty")}
|
() => { console.log('Stringmap now is empty') }
|
||||||
);
|
)
|
||||||
});
|
|
||||||
it("should remove wipe and then notify",function(){
|
|
||||||
testStringmap.wipe();
|
|
||||||
})
|
})
|
||||||
});
|
it('lik.Stringmap.empty() -> should remove wipe and then notify',function(){
|
||||||
describe("Objectmap",function(){
|
testStringmap.wipe()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('Objectmap',function(){
|
||||||
interface ITestObject {
|
interface ITestObject {
|
||||||
propOne:string;
|
propOne: string
|
||||||
propTwo:string;
|
propTwo: string
|
||||||
}
|
}
|
||||||
let testObjectmap:lik.Objectmap;
|
let testObjectmap: lik.Objectmap<ITestObject>
|
||||||
let testObject1:ITestObject = {
|
let testObject1: ITestObject = {
|
||||||
propOne: "hello",
|
propOne: 'hello',
|
||||||
propTwo: "hello2"
|
propTwo: 'hello2'
|
||||||
};
|
}
|
||||||
let testObject2:ITestObject = {
|
let testObject2: ITestObject = {
|
||||||
propOne: "hello",
|
propOne: 'hello',
|
||||||
propTwo: "hello2"
|
propTwo: 'hello2'
|
||||||
};
|
}
|
||||||
it("should correctly instantiate an Objectmap",function(){
|
it('new lik.Objectmap() -> should correctly instantiate an Objectmap',function(){
|
||||||
testObjectmap = new lik.Objectmap();
|
testObjectmap = new lik.Objectmap<ITestObject>()
|
||||||
testObjectmap.should.be.instanceof(lik.Objectmap);
|
should(testObjectmap).be.instanceof(lik.Objectmap)
|
||||||
});
|
})
|
||||||
it("should correctly add an object to Objectmap",function(){
|
it('lik.Objectmap.add() -> should correctly add an object to Objectmap',function(){
|
||||||
testObjectmap.add(testObject1);
|
testObjectmap.add(testObject1)
|
||||||
testObjectmap.checkForObject(testObject1).should.be.true;
|
should(testObjectmap.checkForObject(testObject1)).be.true
|
||||||
testObjectmap.checkForObject(testObject2).should.be.false;
|
should(testObjectmap.checkForObject(testObject2)).be.false
|
||||||
});
|
})
|
||||||
it("should correctly remove an object to Objectmap",function(){
|
it('lik.Objectmap.remove() -> should correctly remove an object to Objectmap',function(){
|
||||||
testObjectmap.add(testObject2);
|
testObjectmap.add(testObject2)
|
||||||
testObjectmap.remove(testObject1);
|
testObjectmap.remove(testObject1)
|
||||||
testObjectmap.checkForObject(testObject1).should.be.false;
|
should(testObjectmap.checkForObject(testObject1)).be.false
|
||||||
testObjectmap.checkForObject(testObject2).should.be.true;
|
should(testObjectmap.checkForObject(testObject2)).be.true
|
||||||
});
|
})
|
||||||
it("should correctly run a function forEach map object",function(){
|
it('Objectmap.forEach -> should correctly run a function forEach map object',function(){
|
||||||
testObjectmap.forEach(itemArg => {
|
testObjectmap.forEach(itemArg => {
|
||||||
itemArg.should.have.ownProperty("propOne");
|
should(itemArg).have.ownProperty('propOne')
|
||||||
})
|
})
|
||||||
});
|
|
||||||
it("should correctly find an object",function(){
|
|
||||||
let myObject = {item1: "hello",item2: "hello2"};
|
|
||||||
testObjectmap.add(myObject);
|
|
||||||
let referenceObject = testObjectmap.find((itemArg) => {return (itemArg.item1 == "hello")});
|
|
||||||
(myObject == referenceObject).should.be.true();
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
});
|
it('lik.Objectmap.find() -> should correctly find an object',function(){
|
||||||
|
let myObject = {propOne: 'helloThere', propTwo: 'helloAnyway'}
|
||||||
|
testObjectmap.add(myObject)
|
||||||
|
let referenceObject = testObjectmap.find((itemArg) => { return (itemArg.propOne === 'helloThere') })
|
||||||
|
should(myObject === referenceObject).be.true()
|
||||||
|
})
|
||||||
|
it('lik.Objectmap.getArray() -> should return a cloned array', function(){
|
||||||
|
let myObject = {propOne : 'test1', propTwo: 'wow, how awesome'}
|
||||||
|
testObjectmap.add(myObject)
|
||||||
|
let clonedArray = testObjectmap.getArray()
|
||||||
|
should(clonedArray[clonedArray.length - 1]).eql(myObject)
|
||||||
|
})
|
||||||
|
it('should get one object and then remove it', function() {
|
||||||
|
let originalLength = testObjectmap.getArray().length
|
||||||
|
let oneObject = testObjectmap.getOneAndRemove()
|
||||||
|
should(oneObject).not.be.null()
|
||||||
|
should(testObjectmap.getArray().length).equal(originalLength - 1)
|
||||||
|
should(testObjectmap.getArray()).not.containEql(oneObject)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('Observablemap',function(){
|
||||||
|
let testObservablemap: lik.Observablemap
|
||||||
|
let testObservable1: rx.Observable<any>
|
||||||
|
let testObservable2: rx.Observable<any>
|
||||||
|
let testObservable3: rx.Observable<any>
|
||||||
|
let testEmitter: events.EventEmitter
|
||||||
|
it('should create an instance',function(){
|
||||||
|
testObservablemap = new lik.Observablemap()
|
||||||
|
should(testObservablemap).be.instanceof(lik.Observablemap)
|
||||||
|
})
|
||||||
|
it('should accept a new emitter',function(done) {
|
||||||
|
testEmitter = new events.EventEmitter()
|
||||||
|
testObservable1 = testObservablemap.getObservableForEmitterEvent(testEmitter,'event1')
|
||||||
|
testObservable1.subscribe(x => {
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
testObservable2 = testObservablemap.getObservableForEmitterEvent(testEmitter,'event1')
|
||||||
|
testObservable3 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event2')
|
||||||
|
should(testObservable1 === testObservable2).be.true()
|
||||||
|
should(testObservable1 === testObservable3).be.false()
|
||||||
|
testEmitter.emit('event1')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as plugins from "./lik.plugins";
|
import * as plugins from './lik.plugins'
|
||||||
|
|
||||||
// import modules
|
// import modules
|
||||||
|
|
||||||
export * from "./lik.stringmap";
|
export * from './lik.stringmap'
|
||||||
export * from "./lik.objectmap";
|
export * from './lik.objectmap'
|
||||||
|
export * from './lik.observablemap'
|
||||||
|
@ -1,81 +1,110 @@
|
|||||||
import * as plugins from "./lik.plugins";
|
import * as plugins from './lik.plugins'
|
||||||
|
|
||||||
|
export interface IObjectmapForEachFunction<T> {
|
||||||
|
(itemArg: T): void
|
||||||
|
}
|
||||||
|
|
||||||
export interface IObjectmapForEachFunction {
|
export interface IObjectmapFindFunction<T> {
|
||||||
(itemArg:any):void
|
(itemArg: T): boolean
|
||||||
};
|
}
|
||||||
|
|
||||||
export interface IObjectmapFindFunction {
|
|
||||||
(itemArg:any):boolean
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* allows keeping track of objects
|
* allows keeping track of objects
|
||||||
*/
|
*/
|
||||||
export class Objectmap {
|
export class Objectmap<T> {
|
||||||
private objectArray = [];
|
private objectArray: T[] = []
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a new instance
|
* returns a new instance
|
||||||
*/
|
*/
|
||||||
constructor(){
|
constructor() {
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add object to Objectmap
|
* add object to Objectmap
|
||||||
*/
|
*/
|
||||||
add(objectArg){
|
add(objectArg: T) {
|
||||||
this.objectArray.push(objectArg);
|
this.objectArray.push(objectArg)
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove object from Objectmap
|
* like .add but adds an whole array of objects
|
||||||
*/
|
*/
|
||||||
remove(objectArg){
|
addArray(objectArrayArg: T[]) {
|
||||||
let replacmentArray = [];
|
for (let item of objectArrayArg) {
|
||||||
for(let item of this.objectArray){
|
this.add(item)
|
||||||
if(item !== objectArg){
|
}
|
||||||
replacmentArray.push(item);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
this.objectArray = replacmentArray;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if object is in Objectmap
|
* check if object is in Objectmap
|
||||||
*/
|
*/
|
||||||
checkForObject(objectArg){
|
checkForObject(objectArg: T) {
|
||||||
return this.objectArray.indexOf(objectArg !== -1)
|
return this.objectArray.indexOf(objectArg) !== -1
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find object
|
* find object
|
||||||
*/
|
*/
|
||||||
find(findFunction:IObjectmapFindFunction){
|
find(findFunction: IObjectmapFindFunction<T>) {
|
||||||
let resultArray = this.objectArray.filter(findFunction);
|
let resultArray = this.objectArray.filter(findFunction)
|
||||||
if (resultArray.length > 0){
|
if (resultArray.length > 0) {
|
||||||
return resultArray[0];
|
return resultArray[0]
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return null
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* run function for each item in Objectmap
|
* run function for each item in Objectmap
|
||||||
*/
|
*/
|
||||||
forEach(functionArg:IObjectmapForEachFunction){
|
forEach(functionArg: IObjectmapForEachFunction<T>) {
|
||||||
return this.objectArray.forEach(functionArg);
|
return this.objectArray.forEach(functionArg)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets an object in the Observablemap and removes it, so it can't be retrieved again
|
||||||
|
*/
|
||||||
|
getOneAndRemove(): T {
|
||||||
|
return this.objectArray.shift()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* finds a specific element and then removes it
|
||||||
|
*/
|
||||||
|
findOneAndRemove(findFunction): T {
|
||||||
|
let foundElement = this.find(findFunction)
|
||||||
|
if (foundElement) {
|
||||||
|
this.remove(foundElement)
|
||||||
|
}
|
||||||
|
return foundElement
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a cloned array of all the objects currently in the Objectmap
|
||||||
|
*/
|
||||||
|
getArray() {
|
||||||
|
return plugins.lodash.cloneDeep(this.objectArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove object from Objectmap
|
||||||
|
*/
|
||||||
|
remove(objectArg: T) {
|
||||||
|
let replacementArray = []
|
||||||
|
for (let item of this.objectArray) {
|
||||||
|
if (item !== objectArg) {
|
||||||
|
replacementArray.push(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.objectArray = replacementArray
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wipe Objectmap
|
* wipe Objectmap
|
||||||
*/
|
*/
|
||||||
wipe(){
|
wipe() {
|
||||||
this.objectArray = [];
|
this.objectArray = []
|
||||||
}
|
}
|
||||||
}
|
}
|
42
ts/lik.observablemap.ts
Normal file
42
ts/lik.observablemap.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import * as plugins from './lik.plugins'
|
||||||
|
import { Objectmap } from './lik.objectmap'
|
||||||
|
import { Stringmap } from './lik.stringmap'
|
||||||
|
import { Observable } from 'rxjs/Rx'
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bundles an observable with an emitter
|
||||||
|
*/
|
||||||
|
export interface ObservableEmitterBundle {
|
||||||
|
observable: plugins.rx.Observable<any>
|
||||||
|
emitter: plugins.events.EventEmitter
|
||||||
|
event: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* manages observables by making sure that only one observable is regsitered per event
|
||||||
|
*/
|
||||||
|
export class Observablemap {
|
||||||
|
ObservableEmitterBundleObjectmap = new Objectmap<ObservableEmitterBundle>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a new observable if not yet registered for the same event.
|
||||||
|
* In case event has been registered before the same observable is returned.
|
||||||
|
*/
|
||||||
|
getObservableForEmitterEvent(emitterArg: plugins.events.EventEmitter, eventArg: string) {
|
||||||
|
let existingBundle = this.ObservableEmitterBundleObjectmap.find((bundleArg) => {
|
||||||
|
return(bundleArg.emitter === emitterArg && bundleArg.event === eventArg)
|
||||||
|
})
|
||||||
|
if (existingBundle) {
|
||||||
|
return existingBundle.observable
|
||||||
|
} else {
|
||||||
|
let emitterObservable = plugins.rx.Observable.fromEvent(emitterArg, eventArg)
|
||||||
|
this.ObservableEmitterBundleObjectmap.add({
|
||||||
|
observable: emitterObservable,
|
||||||
|
emitter: emitterArg,
|
||||||
|
event: eventArg
|
||||||
|
})
|
||||||
|
return emitterObservable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,6 @@
|
|||||||
import "typings-global";
|
import 'typings-global'
|
||||||
export import q = require("q");
|
export import q = require('q')
|
||||||
export import minimatch = require("minimatch");
|
export import events = require('events')
|
||||||
|
export import lodash = require('lodash')
|
||||||
|
export import minimatch = require('minimatch')
|
||||||
|
export import rx = require('rxjs/Rx')
|
||||||
|
@ -1,99 +1,114 @@
|
|||||||
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 {
|
export interface ITriggerFunction {
|
||||||
():boolean;
|
(): boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Stringmap {
|
export class Stringmap {
|
||||||
private _stringArray:string[] = [];
|
private _stringArray: string[] = []
|
||||||
private _triggerUntilTrueFunctionArray:triggerFunction[] = [];
|
private _triggerUntilTrueFunctionArray: ITriggerFunction[] = []
|
||||||
constructor(){
|
constructor() {}
|
||||||
|
|
||||||
};
|
|
||||||
/**
|
/**
|
||||||
* add a string to the Stringmap
|
* add a string to the Stringmap
|
||||||
*/
|
*/
|
||||||
addString(stringArg:string){
|
addString(stringArg: string) {
|
||||||
this._stringArray.push(stringArg);
|
this._stringArray.push(stringArg)
|
||||||
this.notifyTrigger();
|
this.notifyTrigger()
|
||||||
};
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* like addString, but accepts an array of strings
|
||||||
|
*/
|
||||||
|
addStringArray(stringArrayArg: string[]) {
|
||||||
|
for (let stringItem of stringArrayArg){
|
||||||
|
this.addString(stringItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removes a string from Stringmap
|
* removes a string from Stringmap
|
||||||
*/
|
*/
|
||||||
removeString(stringArg:string){
|
removeString(stringArg: string) {
|
||||||
for (let keyArg in this._stringArray){
|
for (let keyArg in this._stringArray) {
|
||||||
if(this._stringArray[keyArg] === stringArg){
|
if (this._stringArray[keyArg] === stringArg) {
|
||||||
this._stringArray.splice(parseInt(keyArg),1);
|
this._stringArray.splice(parseInt(keyArg),1)
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
this.notifyTrigger();
|
this.notifyTrigger()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wipes the Stringmap
|
* wipes the Stringmap
|
||||||
*/
|
*/
|
||||||
wipe(){
|
wipe() {
|
||||||
this._stringArray = [];
|
this._stringArray = []
|
||||||
this.notifyTrigger();
|
this.notifyTrigger()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if string is in Stringmap
|
* check if string is in Stringmap
|
||||||
*/
|
*/
|
||||||
checkString(stringArg:string):boolean {
|
checkString(stringArg: string): boolean {
|
||||||
return this._stringArray.indexOf(stringArg) != -1;
|
return this._stringArray.indexOf(stringArg) !== -1
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks stringPresence with minimatch
|
* checks stringPresence with minimatch
|
||||||
*/
|
*/
|
||||||
checkMinimatch(miniMatchStringArg:string):boolean {
|
checkMinimatch(miniMatchStringArg: string): boolean {
|
||||||
let foundMatch:boolean = false;
|
let foundMatch: boolean = false
|
||||||
for(let stringItem of this._stringArray){
|
for (let stringItem of this._stringArray){
|
||||||
if(plugins.minimatch(stringItem,miniMatchStringArg)){
|
if (plugins.minimatch(stringItem,miniMatchStringArg)) {
|
||||||
foundMatch = true;
|
foundMatch = true
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
return foundMatch;
|
return foundMatch
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks if the Stringmap is empty
|
* checks if the Stringmap is empty
|
||||||
*/
|
*/
|
||||||
checkIsEmpty(){
|
checkIsEmpty() {
|
||||||
return (this._stringArray.length === 0);
|
return (this._stringArray.length === 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets a cloned copy of the current string Array
|
||||||
|
*/
|
||||||
|
getStringArray() {
|
||||||
|
return plugins.lodash.cloneDeep(this._stringArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
// trigger registering
|
// trigger registering
|
||||||
|
|
||||||
/**
|
|
||||||
* notifies triggers
|
|
||||||
*/
|
|
||||||
private notifyTrigger(){
|
|
||||||
let filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
|
|
||||||
return !functionArg();
|
|
||||||
});
|
|
||||||
this._triggerUntilTrueFunctionArray = filteredArray;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register a new trigger
|
* register a new trigger
|
||||||
*/
|
*/
|
||||||
registerUntilTrue(functionArg:triggerFunction,doFunctionArg){
|
registerUntilTrue(functionArg: ITriggerFunction,doFunctionArg) {
|
||||||
this._triggerUntilTrueFunctionArray.push(
|
this._triggerUntilTrueFunctionArray.push(
|
||||||
() => {
|
() => {
|
||||||
let result = functionArg();
|
let result = functionArg()
|
||||||
if(result === true){
|
if (result === true) {
|
||||||
doFunctionArg();
|
doFunctionArg()
|
||||||
}
|
}
|
||||||
return result;
|
return result
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
this.notifyTrigger();
|
this.notifyTrigger()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* notifies triggers
|
||||||
|
*/
|
||||||
|
private notifyTrigger() {
|
||||||
|
let filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
|
||||||
|
return !functionArg()
|
||||||
|
})
|
||||||
|
this._triggerUntilTrueFunctionArray = filteredArray
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "tslint-config-standard"
|
||||||
|
}
|
Reference in New Issue
Block a user