Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
610a037879 | |||
2f681911ae | |||
3b04f81b68 | |||
0c05cf4f7b | |||
5451cceaf3 | |||
04dbc36525 | |||
a820e0d1b3 | |||
57c67a287a | |||
d73bfa8f00 | |||
e917c8b9f7 | |||
c0a5cb6e30 | |||
b85e79b07d | |||
ba714fe637 | |||
3dd4698ce8 | |||
9814e93dda | |||
5d06e6e78f | |||
f6c03275f4 | |||
d6ca9910e3 | |||
ac2267d910 | |||
49f0d7018d | |||
009a1181e5 | |||
3c09f048a2 | |||
1bdcae0524 | |||
62892fa1b8 | |||
fc96e1e2da | |||
fe552763fe | |||
c544fc8e3a | |||
9d856ad813 | |||
24b260c3da | |||
e3a811bffd | |||
95fe1f7937 | |||
e2aee98acc | |||
2705b17dde | |||
5c6728a671 | |||
6d22ee466f | |||
24df2fd54f | |||
db55a46d8e | |||
8020043657 |
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
|
||||||
@ -33,4 +34,16 @@ release:
|
|||||||
only:
|
only:
|
||||||
- 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
|
||||||
|
22
README.md
22
README.md
@ -1,12 +1,28 @@
|
|||||||
# 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://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 } from "lik";
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For a class overview, please read the docs
|
||||||
|
4
dist/index.d.ts
vendored
4
dist/index.d.ts
vendored
@ -1 +1,3 @@
|
|||||||
export * from "./lik.stringmap";
|
export * from './lik.stringmap';
|
||||||
|
export * from './lik.objectmap';
|
||||||
|
export * from './lik.observablemap';
|
||||||
|
4
dist/index.js
vendored
4
dist/index.js
vendored
@ -4,4 +4,6 @@ function __export(m) {
|
|||||||
}
|
}
|
||||||
// import modules
|
// import modules
|
||||||
__export(require("./lik.stringmap"));
|
__export(require("./lik.stringmap"));
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaUJBQWlCO0FBRWpCLGlCQUFjLGlCQUFpQixDQUFDLEVBQUEifQ==
|
__export(require("./lik.objectmap"));
|
||||||
|
__export(require("./lik.observablemap"));
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaUJBQWlCO0FBRWpCLHFDQUErQjtBQUMvQixxQ0FBK0I7QUFDL0IseUNBQW1DIn0=
|
44
dist/lik.objectmap.d.ts
vendored
Normal file
44
dist/lik.objectmap.d.ts
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
export interface IObjectmapForEachFunction<T> {
|
||||||
|
(itemArg: T): void;
|
||||||
|
}
|
||||||
|
export interface IObjectmapFindFunction<T> {
|
||||||
|
(itemArg: T): boolean;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* allows keeping track of objects
|
||||||
|
*/
|
||||||
|
export declare class Objectmap<T> {
|
||||||
|
private objectArray;
|
||||||
|
/**
|
||||||
|
* returns a new instance
|
||||||
|
*/
|
||||||
|
constructor();
|
||||||
|
/**
|
||||||
|
* add object to Objectmap
|
||||||
|
*/
|
||||||
|
add(objectArg: T): void;
|
||||||
|
/**
|
||||||
|
* like .add but adds an whole array of objects
|
||||||
|
*/
|
||||||
|
addArray(objectArrayArg: T[]): void;
|
||||||
|
/**
|
||||||
|
* remove object from Objectmap
|
||||||
|
*/
|
||||||
|
remove(objectArg: T): void;
|
||||||
|
/**
|
||||||
|
* check if object is in Objectmap
|
||||||
|
*/
|
||||||
|
checkForObject(objectArg: T): boolean;
|
||||||
|
/**
|
||||||
|
* find object
|
||||||
|
*/
|
||||||
|
find(findFunction: IObjectmapFindFunction<T>): T;
|
||||||
|
/**
|
||||||
|
* run function for each item in Objectmap
|
||||||
|
*/
|
||||||
|
forEach(functionArg: IObjectmapForEachFunction<T>): void;
|
||||||
|
/**
|
||||||
|
* wipe Objectmap
|
||||||
|
*/
|
||||||
|
wipe(): void;
|
||||||
|
}
|
70
dist/lik.objectmap.js
vendored
Normal file
70
dist/lik.objectmap.js
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
* allows keeping track of objects
|
||||||
|
*/
|
||||||
|
class Objectmap {
|
||||||
|
/**
|
||||||
|
* returns a new instance
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
this.objectArray = [];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* add object to Objectmap
|
||||||
|
*/
|
||||||
|
add(objectArg) {
|
||||||
|
this.objectArray.push(objectArg);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* like .add but adds an whole array of objects
|
||||||
|
*/
|
||||||
|
addArray(objectArrayArg) {
|
||||||
|
for (let item of objectArrayArg) {
|
||||||
|
this.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* remove object from Objectmap
|
||||||
|
*/
|
||||||
|
remove(objectArg) {
|
||||||
|
let replacmentArray = [];
|
||||||
|
for (let item of this.objectArray) {
|
||||||
|
if (item !== objectArg) {
|
||||||
|
replacmentArray.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.objectArray = replacmentArray;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* check if object is in Objectmap
|
||||||
|
*/
|
||||||
|
checkForObject(objectArg) {
|
||||||
|
return this.objectArray.indexOf(objectArg) !== -1;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* find object
|
||||||
|
*/
|
||||||
|
find(findFunction) {
|
||||||
|
let resultArray = this.objectArray.filter(findFunction);
|
||||||
|
if (resultArray.length > 0) {
|
||||||
|
return resultArray[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* run function for each item in Objectmap
|
||||||
|
*/
|
||||||
|
forEach(functionArg) {
|
||||||
|
return this.objectArray.forEach(functionArg);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* wipe Objectmap
|
||||||
|
*/
|
||||||
|
wipe() {
|
||||||
|
this.objectArray = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.Objectmap = Objectmap;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQVVBOztHQUVHO0FBQ0g7SUFHSTs7T0FFRztJQUNIO1FBTFEsZ0JBQVcsR0FBUSxFQUFFLENBQUE7SUFPN0IsQ0FBQztJQUVEOztPQUVHO0lBQ0gsR0FBRyxDQUFDLFNBQVk7UUFDWixJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUNwQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxRQUFRLENBQUMsY0FBbUI7UUFDeEIsR0FBRyxDQUFDLENBQUMsSUFBSSxJQUFJLElBQUksY0FBYyxDQUFDLENBQUMsQ0FBQztZQUM5QixJQUFJLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxDQUFBO1FBQ2xCLENBQUM7SUFDTCxDQUFDO0lBRUQ7O09BRUc7SUFDSCxNQUFNLENBQUMsU0FBWTtRQUNmLElBQUksZUFBZSxHQUFHLEVBQUUsQ0FBQTtRQUN4QixHQUFHLENBQUMsQ0FBQyxJQUFJLElBQUksSUFBSSxJQUFJLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQztZQUNoQyxFQUFFLENBQU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,16 @@
|
|||||||
|
/// <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;
|
||||||
|
}
|
||||||
|
export declare class Observablemap {
|
||||||
|
ObservableEmitterBundleObjectmap: Objectmap<ObservableEmitterBundle>;
|
||||||
|
getObservableForEmitterEvent(emitterArg: plugins.events.EventEmitter, eventArg: string): Observable<any>;
|
||||||
|
}
|
27
dist/lik.observablemap.js
vendored
Normal file
27
dist/lik.observablemap.js
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
"use strict";
|
||||||
|
const plugins = require("./lik.plugins");
|
||||||
|
const lik_objectmap_1 = require("./lik.objectmap");
|
||||||
|
class Observablemap {
|
||||||
|
constructor() {
|
||||||
|
this.ObservableEmitterBundleObjectmap = new lik_objectmap_1.Objectmap();
|
||||||
|
}
|
||||||
|
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,eyJ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RCxzQ0FtQkMifQ==
|
8
dist/lik.plugins.d.ts
vendored
8
dist/lik.plugins.d.ts
vendored
@ -1,2 +1,6 @@
|
|||||||
import "typings-global";
|
import 'typings-global';
|
||||||
export import q = require("q");
|
export import q = require('q');
|
||||||
|
export import events = require('events');
|
||||||
|
export import lodash = require('lodash');
|
||||||
|
export import minimatch = require('minimatch');
|
||||||
|
export import rx = require('rxjs/Rx');
|
||||||
|
6
dist/lik.plugins.js
vendored
6
dist/lik.plugins.js
vendored
@ -1,4 +1,8 @@
|
|||||||
"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.events = require("events");
|
||||||
|
exports.lodash = require("lodash");
|
||||||
|
exports.minimatch = require("minimatch");
|
||||||
|
exports.rx = require("rxjs/Rx");
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9saWsucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHlCQUE4QjtBQUM5QixtQ0FBd0M7QUFDeEMsbUNBQXdDO0FBQ3hDLHlDQUE4QztBQUM5QyxnQ0FBcUMifQ==
|
34
dist/lik.stringmap.d.ts
vendored
34
dist/lik.stringmap.d.ts
vendored
@ -1,19 +1,51 @@
|
|||||||
/**
|
/**
|
||||||
* allows you to easily keep track of a bunch of strings;
|
* allows you to easily keep track of a bunch of strings
|
||||||
*/
|
*/
|
||||||
|
export interface ITriggerFunction {
|
||||||
|
(): 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
|
||||||
*/
|
*/
|
||||||
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
|
||||||
*/
|
*/
|
||||||
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
|
||||||
*/
|
*/
|
||||||
checkString(stringArg: string): boolean;
|
checkString(stringArg: string): boolean;
|
||||||
|
/**
|
||||||
|
* checks stringPresence with minimatch
|
||||||
|
*/
|
||||||
|
checkMinimatch(miniMatchStringArg: string): boolean;
|
||||||
|
/**
|
||||||
|
* checks if the Stringmap is empty
|
||||||
|
*/
|
||||||
|
checkIsEmpty(): boolean;
|
||||||
|
/**
|
||||||
|
* gets a cloned copy of the current string Array
|
||||||
|
*/
|
||||||
|
getStringArray(): string[];
|
||||||
|
/**
|
||||||
|
* register a new trigger
|
||||||
|
*/
|
||||||
|
registerUntilTrue(functionArg: ITriggerFunction, doFunctionArg: any): void;
|
||||||
|
/**
|
||||||
|
* notifies triggers
|
||||||
|
*/
|
||||||
|
private notifyTrigger();
|
||||||
}
|
}
|
||||||
|
78
dist/lik.stringmap.js
vendored
78
dist/lik.stringmap.js
vendored
@ -1,36 +1,96 @@
|
|||||||
"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 = [];
|
||||||
}
|
}
|
||||||
;
|
|
||||||
/**
|
/**
|
||||||
* add a string to the Stringmap
|
* add a string to the Stringmap
|
||||||
*/
|
*/
|
||||||
addString(stringArg) {
|
addString(stringArg) {
|
||||||
this._stringArray.push(stringArg);
|
this._stringArray.push(stringArg);
|
||||||
|
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
|
||||||
*/
|
*/
|
||||||
removeString(stringArg) {
|
removeString(stringArg) {
|
||||||
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();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* wipes the Stringmap
|
||||||
|
*/
|
||||||
|
wipe() {
|
||||||
|
this._stringArray = [];
|
||||||
|
this.notifyTrigger();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
if (result === true) {
|
||||||
|
doFunctionArg();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLnN0cmluZ21hcC5qcyIsInNv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0sS0FBSyxJQUFJLENBQUMsQ0FBQyxDQUFDO2dCQUNsQixhQUFhLEVBQUUsQ0FBQTtZQUNuQixDQUFDO1lBQ0QsTUFBTSxDQUFDLE1BQU0sQ0FBQTtRQUNqQixDQUFDLENBQ0osQ0FBQTtRQUNELElBQUksQ0FBQyxhQUFhLEVBQUUsQ0FBQTtJQUN4QixDQUFDO0lBRUQ7O09BRUc7SUFDSyxhQUFhO1FBQ2pCLElBQUksYUFBYSxHQUFHLElBQUksQ0FBQyw4QkFBOEIsQ0FBQyxNQUFNLENBQUMsQ0FBQyxXQUFXO1lBQ3ZFLE1BQU0sQ0FBQyxDQUFDLFdBQVcsRUFBRSxDQUFBO1FBQ3pCLENBQUMsQ0FBQyxDQUFBO1FBQ0YsSUFBSSxDQUFDLDhCQUE4QixHQUFHLGFBQWEsQ0FBQTtJQUN2RCxDQUFDO0NBRUo7QUF2R0QsOEJBdUdDIn0=
|
18
package.json
18
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lik",
|
"name": "lik",
|
||||||
"version": "1.0.1",
|
"version": "1.0.20",
|
||||||
"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,12 +18,18 @@
|
|||||||
},
|
},
|
||||||
"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/q": "^0.0.27",
|
"@types/lodash": "^4.14.35",
|
||||||
"q": "^1.4.1"
|
"@types/minimatch": "2.x.x",
|
||||||
|
"@types/q": "0.x.x",
|
||||||
|
"lodash": "^4.16.1",
|
||||||
|
"minimatch": "^3.0.3",
|
||||||
|
"q": "^1.4.1",
|
||||||
|
"rxjs": "^5.0.0-beta.12"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
test/test.d.ts
vendored
3
test/test.d.ts
vendored
@ -1,2 +1 @@
|
|||||||
import "typings-test";
|
import 'typings-test';
|
||||||
import "should";
|
|
||||||
|
116
test/test.js
116
test/test.js
File diff suppressed because one or more lines are too long
148
test/test.ts
148
test/test.ts
@ -1,31 +1,121 @@
|
|||||||
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('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('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('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.addString(testString3)
|
||||||
it("should remove a string from Stringmap",function(){
|
should(testStringmap.checkString(testString1)).be.true()
|
||||||
testStringmap.removeString(testString2);
|
should(testStringmap.checkString(testString2)).be.true()
|
||||||
testStringmap.checkString(testString2).should.be.false();
|
should(testStringmap.checkString(testString3)).be.true()
|
||||||
});
|
should(testStringmap.checkMinimatch('*String1')).be.true()
|
||||||
|
should(testStringmap.checkMinimatch('*String2')).be.true()
|
||||||
|
should(testStringmap.checkMinimatch('*String4')).be.false()
|
||||||
|
})
|
||||||
|
it('should add an array of strings',function(){
|
||||||
|
testStringmap.addStringArray([testString4,testString5,testString6])
|
||||||
|
should(testStringmap.checkMinimatch('*String4')).be.true()
|
||||||
|
})
|
||||||
|
it('should remove a string from Stringmap',function(){
|
||||||
|
testStringmap.removeString(testString2)
|
||||||
|
should(testStringmap.checkString(testString2)).be.false()
|
||||||
|
})
|
||||||
|
it('should return a copy of stringArray',function(){
|
||||||
|
let clonedArray = testStringmap.getStringArray()
|
||||||
|
should(clonedArray[0] === 'testString1').be.true()
|
||||||
|
should(clonedArray[0] === testString1).be.true()
|
||||||
|
})
|
||||||
|
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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
});
|
describe('Objectmap',function(){
|
||||||
|
interface ITestObject {
|
||||||
|
propOne: string
|
||||||
|
propTwo: string
|
||||||
|
}
|
||||||
|
let testObjectmap: lik.Objectmap<ITestObject>
|
||||||
|
let testObject1: ITestObject = {
|
||||||
|
propOne: 'hello',
|
||||||
|
propTwo: 'hello2'
|
||||||
|
}
|
||||||
|
let testObject2: ITestObject = {
|
||||||
|
propOne: 'hello',
|
||||||
|
propTwo: 'hello2'
|
||||||
|
}
|
||||||
|
it('should correctly instantiate an Objectmap',function(){
|
||||||
|
testObjectmap = new lik.Objectmap<ITestObject>()
|
||||||
|
should(testObjectmap).be.instanceof(lik.Objectmap)
|
||||||
|
})
|
||||||
|
it('should correctly add an object to Objectmap',function(){
|
||||||
|
testObjectmap.add(testObject1)
|
||||||
|
should(testObjectmap.checkForObject(testObject1)).be.true
|
||||||
|
should(testObjectmap.checkForObject(testObject2)).be.false
|
||||||
|
})
|
||||||
|
it('should correctly remove an object to Objectmap',function(){
|
||||||
|
testObjectmap.add(testObject2)
|
||||||
|
testObjectmap.remove(testObject1)
|
||||||
|
should(testObjectmap.checkForObject(testObject1)).be.false
|
||||||
|
should(testObjectmap.checkForObject(testObject2)).be.true
|
||||||
|
})
|
||||||
|
it('should correctly run a function forEach map object',function(){
|
||||||
|
testObjectmap.forEach(itemArg => {
|
||||||
|
should(itemArg).have.ownProperty('propOne')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
it('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()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
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,5 +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.observablemap'
|
||||||
|
85
ts/lik.objectmap.ts
Normal file
85
ts/lik.objectmap.ts
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
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[] = []
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a new instance
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add object to Objectmap
|
||||||
|
*/
|
||||||
|
add(objectArg: T) {
|
||||||
|
this.objectArray.push(objectArg)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* like .add but adds an whole array of objects
|
||||||
|
*/
|
||||||
|
addArray(objectArrayArg: T[]) {
|
||||||
|
for (let item of objectArrayArg) {
|
||||||
|
this.add(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove object from Objectmap
|
||||||
|
*/
|
||||||
|
remove(objectArg: T) {
|
||||||
|
let replacmentArray = []
|
||||||
|
for (let item of this.objectArray) {
|
||||||
|
if (item !== objectArg) {
|
||||||
|
replacmentArray.push(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.objectArray = replacmentArray
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if object is in Objectmap
|
||||||
|
*/
|
||||||
|
checkForObject(objectArg: T) {
|
||||||
|
return this.objectArray.indexOf(objectArg) !== -1
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find object
|
||||||
|
*/
|
||||||
|
find(findFunction: IObjectmapFindFunction<T>) {
|
||||||
|
let resultArray = this.objectArray.filter(findFunction)
|
||||||
|
if (resultArray.length > 0) {
|
||||||
|
return resultArray[0]
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* run function for each item in Objectmap
|
||||||
|
*/
|
||||||
|
forEach(functionArg: IObjectmapForEachFunction<T>) {
|
||||||
|
return this.objectArray.forEach(functionArg)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wipe Objectmap
|
||||||
|
*/
|
||||||
|
wipe() {
|
||||||
|
this.objectArray = []
|
||||||
|
}
|
||||||
|
}
|
35
ts/lik.observablemap.ts
Normal file
35
ts/lik.observablemap.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Observablemap {
|
||||||
|
ObservableEmitterBundleObjectmap = new Objectmap<ObservableEmitterBundle>()
|
||||||
|
|
||||||
|
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,2 +1,6 @@
|
|||||||
import "typings-global";
|
import 'typings-global'
|
||||||
export import q = require("q");
|
export import q = require('q')
|
||||||
|
export import events = require('events')
|
||||||
|
export import lodash = require('lodash')
|
||||||
|
export import minimatch = require('minimatch')
|
||||||
|
export import rx = require('rxjs/Rx')
|
||||||
|
@ -1,35 +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 class Stringmap {
|
|
||||||
private _stringArray:string[] = [];
|
|
||||||
constructor(){
|
|
||||||
|
|
||||||
};
|
export interface ITriggerFunction {
|
||||||
|
(): boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Stringmap {
|
||||||
|
private _stringArray: string[] = []
|
||||||
|
private _triggerUntilTrueFunctionArray: ITriggerFunction[] = []
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wipes the Stringmap
|
||||||
|
*/
|
||||||
|
wipe() {
|
||||||
|
this._stringArray = []
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets a cloned copy of the current string Array
|
||||||
|
*/
|
||||||
|
getStringArray() {
|
||||||
|
return plugins.lodash.cloneDeep(this._stringArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
// trigger registering
|
||||||
|
|
||||||
|
/**
|
||||||
|
* register a new trigger
|
||||||
|
*/
|
||||||
|
registerUntilTrue(functionArg: ITriggerFunction,doFunctionArg) {
|
||||||
|
this._triggerUntilTrueFunctionArray.push(
|
||||||
|
() => {
|
||||||
|
let result = functionArg()
|
||||||
|
if (result === true) {
|
||||||
|
doFunctionArg()
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
)
|
||||||
|
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