Compare commits

..

21 Commits

Author SHA1 Message Date
52b65d7dc3 3.0.9 2019-08-02 16:48:30 +02:00
1135b418cb 3.0.8 2019-08-02 16:38:09 +02:00
2eb1dbd0b3 fix(core): update 2019-08-02 16:38:08 +02:00
8ec54c17a1 3.0.7 2019-08-02 16:33:46 +02:00
500a291b2a fix(core): update 2019-08-02 16:33:45 +02:00
256a14fcb0 3.0.6 2019-08-02 16:32:52 +02:00
7aa0f05bae fix(core): update 2019-08-02 16:32:52 +02:00
6208cab36a 3.0.5 2019-03-15 23:50:40 +01:00
50a9697baf fix(objectmap): getArray() now has correct return type 2019-03-15 23:50:39 +01:00
7956cf6ace 3.0.4 2018-12-11 01:41:05 +01:00
d8956d4e32 fix(ci): remove old build dependencies 2018-12-11 01:41:05 +01:00
c93a67c351 3.0.3 2018-12-11 01:36:15 +01:00
fafd9867ad fix(core): update 2018-12-11 01:36:14 +01:00
2dfa96bbc5 3.0.2 2018-11-23 20:33:45 +01:00
a7484e791a fix(core): update 2018-11-23 20:33:44 +01:00
2dba68df8c Merge branch 'master' into 'master'
implement JSON methods for tree

See merge request pushrocks/lik!1
2018-09-01 14:38:56 +00:00
6aff4c9031 implement JSON methods for tree 2018-08-31 17:24:35 +02:00
e81e0ebd41 3.0.1 2018-07-15 16:08:21 +02:00
18866b9a05 fix(ci): fix build tool packagename 2018-07-15 16:08:20 +02:00
71b12b2d9c 3.0.0 2018-07-15 16:06:08 +02:00
0669fc3779 2.0.7 2018-07-15 16:05:42 +02:00
22 changed files with 1751 additions and 458 deletions

25
.gitignore vendored
View File

@ -1,5 +1,22 @@
node_modules/
pages/
public/
coverage/
.nogit/ .nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,5 +1,5 @@
# gitzone standard # gitzone ci_default
image: hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
@ -26,6 +26,7 @@ mirror:
snyk: snyk:
stage: security stage: security
script: script:
- npmci npm prepare
- npmci command npm install -g snyk - npmci command npm install -g snyk
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command snyk test - npmci command snyk test
@ -36,21 +37,11 @@ snyk:
# ==================== # ====================
# test stage # test stage
# ==================== # ====================
testLEGACY:
stage: test
script:
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
allow_failure: true
testLTS: testLTS:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install lts - npmci node install lts
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
@ -59,12 +50,13 @@ testLTS:
- docker - docker
- notpriv - notpriv
testSTABLE: testBuild:
stage: test stage: test
script: script:
- npmci node install stable - npmci npm prepare
- npmci node install lts
- npmci npm install - npmci npm install
- npmci npm test - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
@ -73,7 +65,7 @@ testSTABLE:
release: release:
stage: release stage: release
script: script:
- npmci node install stable - npmci node install lts
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
@ -86,19 +78,11 @@ release:
# ==================== # ====================
codequality: codequality:
stage: metadata stage: metadata
image: docker:stable
allow_failure: true allow_failure: true
services:
- docker:stable-dind
script: script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') - npmci command npm install -g tslint typescript
- docker run - npmci npm install
--env SOURCE_CODE="$PWD" - npmci command "tslint -c tslint.json ./ts/**/*.ts"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
tags: tags:
- docker - docker
- priv - priv
@ -114,11 +98,15 @@ trigger:
- notpriv - notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-dbase:npmci
services:
- docker:18-dind
stage: metadata stage: metadata
script: script:
- npmci command npm install -g npmpage - npmci command npm install -g @gitzone/tsdoc
- npmci command npmpage - npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags: tags:
- docker - docker
- notpriv - notpriv
@ -129,13 +117,3 @@ pages:
paths: paths:
- public - public
allow_failure: true allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"workbench.colorCustomizations": {}
}

View File

@ -1,26 +1,20 @@
# lik # @pushrocks/lik
light little helpers for node light little helpers for node
## Availabililty ## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/lik)
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/lik) * [gitlab.com (source)](https://gitlab.com/pushrocks/lik)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/lik) * [github.com (source mirror)](https://github.com/pushrocks/lik)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/lik) * [docs (typedoc)](https://pushrocks.gitlab.io/lik/)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/lik/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/lik/badges/master/build.svg)](https://gitlab.com/pushrocks/lik/commits/master)
[![build status](https://GitLab.com/pushrocks/lik/badges/master/build.svg)](https://GitLab.com/pushrocks/lik/commits/master) [![coverage report](https://gitlab.com/pushrocks/lik/badges/master/coverage.svg)](https://gitlab.com/pushrocks/lik/commits/master)
[![coverage report](https://GitLab.com/pushrocks/lik/badges/master/coverage.svg)](https://GitLab.com/pushrocks/lik/commits/master) [![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/lik.svg)](https://www.npmjs.com/package/@pushrocks/lik)
[![npm downloads per month](https://img.shields.io/npm/dm/lik.svg)](https://www.npmjs.com/package/lik) [![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/lik/badge.svg)](https://snyk.io/test/npm/@pushrocks/lik)
[![Dependency Status](https://david-dm.org/pushrocks/lik.svg)](https://david-dm.org/pushrocks/lik) [![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/lik/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/lik/master/dependencies/npm) [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![bitHound Code](https://www.bithound.io/github/pushrocks/lik/badges/code.svg)](https://www.bithound.io/github/pushrocks/lik) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
[![Known Vulnerabilities](https://snyk.io/test/npm/lik/badge.svg)](https://snyk.io/test/npm/lik)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage ## Usage
@ -41,7 +35,9 @@ like when a certain string is removed or added to the map
Sometimes you need to keep track of objects, but implementing logic for removing, finding or updating is tedious. 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. Objectmap takes care of keeping track of objects for you.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) For further information read the linked docs at the top of this readme.
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)

View File

@ -1,14 +1,16 @@
{ {
"npmci": { "npmci": {
"npmGlobalTools": [ "npmGlobalTools": [],
"npmts"
],
"npmAccessLevel": "public" "npmAccessLevel": "public"
}, },
"npmts": { "gitzone": {
"coverageTreshold": 40, "module": {
"testConfig": { "githost": "gitlab.com",
"parallel": false "gitscope": "pushrocks",
"gitrepo": "lik",
"shortDescription": "light little helpers for node",
"npmPackagename": "@pushrocks/lik",
"license": "MIT"
} }
} }
} }

1589
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
{ {
"name": "@pushrocks/lik", "name": "@pushrocks/lik",
"version": "2.0.6", "version": "3.0.9",
"private": false, "private": false,
"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",
"scripts": { "scripts": {
"test": "tsrun test/test.ts", "test": "(tstest test/)",
"build": "(npmts)" "build": "(tsbuild)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -20,16 +20,32 @@
}, },
"homepage": "https://gitlab.com/pushrocks/lik#README", "homepage": "https://gitlab.com/pushrocks/lik#README",
"devDependencies": { "devDependencies": {
"@gitzone/tsrun": "^1.1.9", "@gitzone/tsbuild": "^2.1.11",
"@pushrocks/tapbundle": "^3.0.1", "@gitzone/tsrun": "^1.2.8",
"@types/node": "^10.5.2" "@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.11",
"@types/node": "^12.6.9",
"tslint": "^5.18.0",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartdelay": "^2.0.3",
"@types/lodash": "^4.14.112", "@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartrx": "^2.0.3",
"@pushrocks/smarttime": "^3.0.12",
"@types/minimatch": "^3.0.3", "@types/minimatch": "^3.0.3",
"lodash": "^4.17.10",
"minimatch": "^3.0.4", "minimatch": "^3.0.4",
"symbol-tree": "^3.2.2" "symbol-tree": "^3.2.4"
} },
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
} }

25
test/test.interestmap.ts Normal file
View File

@ -0,0 +1,25 @@
import { tap, expect } from '@pushrocks/tapbundle';
import * as lik from '../ts/index';
let testInterestmap: lik.InterestMap<number, number>;
tap.test('should create an interestmap', async () => {
testInterestmap = new lik.InterestMap(numberArg => {
return numberArg.toString();
});
});
tap.test('should create an interest', async () => {
testInterestmap.addInterest(3);
testInterestmap.addInterest(4);
});
tap.test('should return an already existing interest', async () => {
await testInterestmap.addInterest(3);
});
tap.test('should be able to inform about a lost interest', async () => {
testInterestmap.informLostInterest(3);
});
tap.start();

View File

@ -1,7 +1,7 @@
// import test framework // import test framework
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as events from 'events'; import * as events from 'events';
import * as smartq from 'smartq'; import * as smartpromise from '@pushrocks/smartpromise';
// import the module // import the module
import * as lik from '../ts/index'; import * as lik from '../ts/index';

View File

@ -1,7 +1,7 @@
// import test framework // import test framework
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as events from 'events'; import * as events from 'events';
import * as smartq from 'smartq'; import * as smartpromise from '@pushrocks/smartpromise';
// import the module // import the module
import * as lik from '../ts/index'; import * as lik from '../ts/index';

View File

@ -1,7 +1,7 @@
// import test framework // import test framework
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as events from 'events'; import * as events from 'events';
import * as smartq from 'smartq'; import * as smartpromise from '@pushrocks/smartpromise';
// import the module // import the module
import * as lik from '../ts/index'; import * as lik from '../ts/index';

View File

@ -0,0 +1,25 @@
// import test framework
import { expect, tap } from '@pushrocks/tapbundle';
import * as events from 'events';
import * as smartpromise from '@pushrocks/smartpromise';
// import the module
import * as lik from '../ts/index';
let testTimedAggregator: lik.TimedAggregtor<string>;
tap.test('should create a timed aggregaotor', async tools => {
testTimedAggregator = new lik.TimedAggregtor<string>({
aggregationIntervalInMillis: 1000,
functionForAggregation: aggregation => {
console.log(aggregation);
}
});
testTimedAggregator.add('This');
testTimedAggregator.add('is a whole sentence.');
await tools.delayFor(1001);
testTimedAggregator.add('This one is another.');
await tools.delayFor(2000);
});
tap.start();

View File

@ -1,14 +1,20 @@
import { tap, expect } from '@pushrocks/tapbundle'; import { tap, expect } from '@pushrocks/tapbundle';
import * as lik from '../ts/index'; import * as lik from '../ts/index';
let testTree = new lik.Tree<TestClass>();
class TestClass { class TestClass {
constructor(public hey: string) { constructor(public hey: string) {
// nothing here // nothing here
} }
} }
let testTree = new lik.Tree<TestClass>();
let testInstance = new TestClass('first'); let testInstance = new TestClass('first');
let testInstance2 = new TestClass('second');
let testInstance3 = new TestClass('third');
let testInstance4 = new TestClass('fourth');
let testInstance5 = new TestClass('fifth');
let testInstance6 = new TestClass('sixth');
tap.test('create a valid tree instance', async () => { tap.test('create a valid tree instance', async () => {
testTree = new lik.Tree(); testTree = new lik.Tree();
@ -21,4 +27,14 @@ tap.test('should insert an object', async () => {
expect(resultArray).to.contain(testInstance); expect(resultArray).to.contain(testInstance);
}); });
tap.test('should add other objects in a hierachy', async () => {
testTree.appendChild(testInstance, testInstance2);
testTree.appendChild(testInstance, testInstance3);
testTree.appendChild(testInstance, testInstance4);
});
tap.test("should create a JSON object that reflects a tree's hierachy", async () => {
const jsonTreet = testTree.toJsonWithHierachy(testInstance);
});
tap.start(); tap.start();

View File

@ -2,8 +2,10 @@ import * as plugins from './lik.plugins';
// import modules // import modules
export * from './lik.interestmap';
export * from './lik.limitedarray';
export * from './lik.looptracker'; export * from './lik.looptracker';
export * from './lik.objectmap'; export * from './lik.objectmap';
export * from './lik.stringmap'; export * from './lik.stringmap';
export * from './lik.limitedarray'; export * from './lik.timedaggregator';
export * from './lik.tree'; export * from './lik.tree';

View File

@ -0,0 +1,78 @@
import * as plugins from './lik.plugins';
import { InterestMap, IInterestComparisonFunc } from './lik.interestmap';
export class Interest<DTInterestId, DTInterestFullfillment> {
private interestMapRef: InterestMap<DTInterestId, DTInterestFullfillment>;
public originalInterest: DTInterestId;
public comparisonFunc: IInterestComparisonFunc<DTInterestId>;
public destructionTimer = new plugins.smarttime.Timer(10000);
public isFullfilled = false;
/**
* a generic store to store objects in that are needed for fullfillment;
*/
public fullfillmentStore: any[] = [];
/**
* quick access to a string that makes the interest comparable for checking for similar interests
*/
public get comparisonString() {
return this.comparisonFunc(this.originalInterest);
}
private interestDeferred: plugins.smartpromise.Deferred<
DTInterestFullfillment
> = new plugins.smartpromise.Deferred();
public interestFullfilled = this.interestDeferred.promise;
/**
* fullfill the interest
*/
public fullfillInterest(objectArg: DTInterestFullfillment) {
this.isFullfilled = true;
this.fullfillmentStore = [];
this.interestDeferred.resolve(objectArg);
}
/**
*
*/
constructor(
interestMapArg: InterestMap<DTInterestId, DTInterestFullfillment>,
interestArg: DTInterestId,
comparisonFuncArg: IInterestComparisonFunc<DTInterestId>
) {
this.originalInterest = interestArg;
this.comparisonFunc = comparisonFuncArg;
this.interestMapRef = interestMapArg;
this.destructionTimer.completed.then(() => {
this.destroy();
});
}
// ===============================
// LIFECYCLE MANAGEMENT
// ===============================
/**
* self destructs the interest
*/
public destroy() {
this.interestMapRef.removeInterest(this);
}
/**
* notifies the interest that the interest in it has been lost
*/
public markLost() {
this.destructionTimer.start();
}
/**
* notifies the interest that the interest in it has been restored
*/
public renew() {
this.destructionTimer.reset();
}
}

114
ts/lik.interestmap.ts Normal file
View File

@ -0,0 +1,114 @@
import * as plugins from './lik.plugins';
import { Objectmap } from './lik.objectmap';
import { Observable } from 'rxjs';
import { Interest } from './lik.interestmap.interest';
export type IInterestComparisonFunc<T> = (objectArg: T) => string;
export class InterestMap<DTInterestId, DTInterestFullfillment> {
/**
* stores interests that are currently fullfilled by the cache
*/
private interestObjectMap = new Objectmap<Interest<DTInterestId, DTInterestFullfillment>>();
/**
* a function to compare interests
*/
private comparisonFunc: IInterestComparisonFunc<DTInterestId>;
constructor(comparisonFuncArg: IInterestComparisonFunc<DTInterestId>) {
this.comparisonFunc = comparisonFuncArg;
}
/**
* adds an interest to the InterestMap
* @param objectArg
*/
public async addInterest(
objectArg: DTInterestId
): Promise<Interest<DTInterestId, DTInterestFullfillment>> {
const comparisonString = this.comparisonFunc(objectArg);
let returnInterest: Interest<DTInterestId, DTInterestFullfillment>;
const newInterest = new Interest<DTInterestId, DTInterestFullfillment>(
this,
objectArg,
this.comparisonFunc
);
let interestExists = false;
await this.interestObjectMap.forEach(interestArg => {
if (!interestExists && interestArg.comparisonString === newInterest.comparisonString) {
console.log('info', `interest already exists for ${newInterest.comparisonString}`);
interestExists = true;
returnInterest = interestArg;
returnInterest.renew();
}
});
if (!returnInterest) {
returnInterest = newInterest;
this.interestObjectMap.add(returnInterest);
}
this.interestObservable.push(returnInterest);
return returnInterest;
}
// tslint:disable-next-line:member-ordering
public interestObservable = new plugins.smartrx.ObservableIntake<Interest<DTInterestId, any>>();
/**
* removes an interest from the interest map
* @param objectArg removes an interest from the InterestMap
*/
public removeInterest(interestArg: Interest<DTInterestId, DTInterestFullfillment>) {
const interestToRemove = this.interestObjectMap.findOneAndRemove(interestArg2 => {
return interestArg.comparisonString === interestArg2.comparisonString;
});
}
/**
* check interest
*/
public checkInterest(objectArg: DTInterestId): boolean {
const comparisonString = this.comparisonFunc(objectArg);
return this.checkInterestByString(comparisonString);
}
/**
* checks an interest
* @param comparisonStringArg
*/
public checkInterestByString(comparisonStringArg: string): boolean {
const foundInterest = this.interestObjectMap.find(interest => {
return interest.comparisonString === comparisonStringArg;
});
if (foundInterest) {
return true;
} else {
return false;
}
}
/**
* inform lost interest
* @param interestId
*/
public informLostInterest(interestId: DTInterestId) {
const wantedInterest = this.findInterest(interestId);
if (wantedInterest) {
wantedInterest.markLost();
}
}
/**
* finds an interest
* @param objectArg
*/
public findInterest(objectArg: DTInterestId): Interest<DTInterestId, DTInterestFullfillment> {
const comparableString = this.comparisonFunc(objectArg);
const interest = this.interestObjectMap.find(interest => {
return interest.comparisonString === comparableString;
});
return interest; // if an interest is found, the interest is returned, otherwise interest is null
}
}

View File

@ -26,7 +26,7 @@ export class Objectmap<T> {
* returns false if the object is already in the map * returns false if the object is already in the map
* returns true if the object was added successfully * returns true if the object was added successfully
*/ */
add(objectArg: T): boolean { public add(objectArg: T): boolean {
if (this.checkForObject(objectArg)) { if (this.checkForObject(objectArg)) {
// the object is already in the objectmap // the object is already in the objectmap
return false; return false;
@ -40,7 +40,7 @@ export class Objectmap<T> {
/** /**
* like .add but adds an whole array of objects * like .add but adds an whole array of objects
*/ */
addArray(objectArrayArg: T[]) { public addArray(objectArrayArg: T[]) {
for (let item of objectArrayArg) { for (let item of objectArrayArg) {
this.add(item); this.add(item);
} }
@ -49,15 +49,15 @@ export class Objectmap<T> {
/** /**
* check if object is in Objectmap * check if object is in Objectmap
*/ */
checkForObject(objectArg: T) { public checkForObject(objectArg: T) {
return this.objectArray.indexOf(objectArg) !== -1; return this.objectArray.indexOf(objectArg) !== -1;
} }
/** /**
* find object * find object
*/ */
find(findFunction: IObjectmapFindFunction<T>) { public find(findFunction: IObjectmapFindFunction<T>) {
let resultArray = this.objectArray.filter(findFunction); const resultArray = this.objectArray.filter(findFunction);
if (resultArray.length > 0) { if (resultArray.length > 0) {
return resultArray[0]; return resultArray[0];
} else { } else {
@ -68,8 +68,8 @@ export class Objectmap<T> {
/** /**
* finds a specific element and then removes it * finds a specific element and then removes it
*/ */
findOneAndRemove(findFunction: IObjectmapFindFunction<T>): T { public findOneAndRemove(findFunction: IObjectmapFindFunction<T>): T {
let foundElement = this.find(findFunction); const foundElement = this.find(findFunction);
if (foundElement) { if (foundElement) {
this.remove(foundElement); this.remove(foundElement);
} }
@ -79,7 +79,7 @@ export class Objectmap<T> {
/** /**
* run function for each item in Objectmap * run function for each item in Objectmap
*/ */
async forEach(functionArg: IObjectmapForEachFunction<T>) { public async forEach(functionArg: IObjectmapForEachFunction<T>) {
for (let object of this.objectArray) { for (let object of this.objectArray) {
await functionArg(object); await functionArg(object);
} }
@ -88,21 +88,25 @@ export class Objectmap<T> {
/** /**
* gets an object in the Observablemap and removes it, so it can't be retrieved again * gets an object in the Observablemap and removes it, so it can't be retrieved again
*/ */
getOneAndRemove(): T { public getOneAndRemove(): T {
return this.objectArray.shift(); return this.objectArray.shift();
} }
/** /**
* returns a cloned array of all the objects currently in the Objectmap * returns a cloned array of all the objects currently in the Objectmap
*/ */
getArray() { public getArray(): T[] {
return plugins.lodash.cloneDeep(this.objectArray); const returnArray: any[] = [];
for (const objectItem of this.objectArray) {
returnArray.push(objectItem);
}
return returnArray;
} }
/** /**
* check if Objectmap ist empty * check if Objectmap ist empty
*/ */
isEmpty(): boolean { public isEmpty(): boolean {
if (this.objectArray.length === 0) { if (this.objectArray.length === 0) {
return true; return true;
} else { } else {
@ -113,7 +117,7 @@ export class Objectmap<T> {
/** /**
* remove object from Objectmap * remove object from Objectmap
*/ */
remove(objectArg: T) { public remove(objectArg: T) {
let replacementArray = []; let replacementArray = [];
for (let item of this.objectArray) { for (let item of this.objectArray) {
if (item !== objectArg) { if (item !== objectArg) {
@ -126,7 +130,7 @@ export class Objectmap<T> {
/** /**
* wipe Objectmap * wipe Objectmap
*/ */
wipe() { public wipe() {
this.objectArray = []; this.objectArray = [];
} }
} }

View File

@ -1,7 +1,25 @@
// ==============
// native
// ==============
import * as events from 'events'; import * as events from 'events';
import * as lodash from 'lodash';
import * as minimatch from 'minimatch'; export { events };
// ==============
// @pushrocks
// ==============
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrx from '@pushrocks/smartrx';
import * as smarttime from '@pushrocks/smarttime';
export { smartdelay, smartpromise, smartrx, smarttime };
// ==============
// third party
// ==============
import minimatch from 'minimatch';
const symbolTree = require('symbol-tree'); const symbolTree = require('symbol-tree');
export { events, lodash, minimatch, smartpromise, symbolTree }; export { minimatch, symbolTree };

View File

@ -52,14 +52,14 @@ export class Stringmap {
/** /**
* check if string is in Stringmap * check if string is in Stringmap
*/ */
checkString(stringArg: string): boolean { public 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 { public 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)) {
@ -72,15 +72,19 @@ export class Stringmap {
/** /**
* checks if the Stringmap is empty * checks if the Stringmap is empty
*/ */
checkIsEmpty() { public checkIsEmpty() {
return this._stringArray.length === 0; return this._stringArray.length === 0;
} }
/** /**
* gets a cloned copy of the current string Array * gets a cloned copy of the current string Array
*/ */
getStringArray() { public getStringArray() {
return plugins.lodash.cloneDeep(this._stringArray); const returnArray: string[] = [];
for (const stringItem of this._stringArray) {
returnArray.push(stringItem);
}
return returnArray;
} }
// trigger registering // trigger registering
@ -88,7 +92,7 @@ export class Stringmap {
/** /**
* register a new trigger * register a new trigger
*/ */
registerUntilTrue(functionArg: ITriggerFunction, doFunctionArg) { public registerUntilTrue(functionArg: ITriggerFunction, doFunctionArg) {
this._triggerUntilTrueFunctionArray.push(() => { this._triggerUntilTrueFunctionArray.push(() => {
let result = functionArg(); let result = functionArg();
if (result === true) { if (result === true) {

41
ts/lik.timedaggregator.ts Normal file
View File

@ -0,0 +1,41 @@
import * as plugins from './lik.plugins';
export interface ITimedAggregatorOptions<T> {
aggregationIntervalInMillis: number;
functionForAggregation: (input: T[]) => void;
}
export class TimedAggregtor<T> {
public options: ITimedAggregatorOptions<T>;
private storageArray: T[] = [];
constructor(optionsArg: ITimedAggregatorOptions<T>) {
this.options = optionsArg;
}
private aggregationTimer: plugins.smarttime.Timer;
private checkAggregationStatus() {
const addAggregationTimer = () => {
this.aggregationTimer = new plugins.smarttime.Timer(this.options.aggregationIntervalInMillis);
this.aggregationTimer.completed.then(() => {
const aggregateForProcessing = this.storageArray;
if (aggregateForProcessing.length === 0) {
this.aggregationTimer = null;
return;
}
this.storageArray = [];
addAggregationTimer();
this.options.functionForAggregation(aggregateForProcessing);
});
this.aggregationTimer.start();
};
if (!this.aggregationTimer) {
addAggregationTimer();
}
}
public add(aggregationArg: T) {
this.storageArray.push(aggregationArg);
this.checkAggregationStatus();
}
}

View File

@ -6,6 +6,10 @@ export class Tree<T> {
this.symbolTree = new plugins.symbolTree(); this.symbolTree = new plugins.symbolTree();
} }
// =======================================
// Functions that map to the functionality of symbol-tree
// =======================================
/** /**
* *
* @param objectArg * @param objectArg
@ -78,7 +82,7 @@ export class Tree<T> {
this.symbolTree.ancestorsIterator(); this.symbolTree.ancestorsIterator();
} }
treeIterator(rootArg: T, optionsArg): T { treeIterator(rootArg: T, optionsArg): Iterable<T> {
return this.symbolTree.treeIterator(rootArg); return this.symbolTree.treeIterator(rootArg);
} }
@ -113,4 +117,25 @@ export class Tree<T> {
appendChild(referenceObjectArg, newObjectArg) { appendChild(referenceObjectArg, newObjectArg) {
return this.symbolTree.appendChild(referenceObjectArg, newObjectArg); return this.symbolTree.appendChild(referenceObjectArg, newObjectArg);
} }
// ===========================================
// Functionionality that extends symbol-tree
// ===========================================
/**
* returns a branch of the tree as JSON
* can be user
*/
toJsonWithHierachy(rootElement) {
const treeIterable = this.treeIterator(rootElement, {});
for (const treeItem of treeIterable) {
console.log(treeItem);
}
}
/**
* builds a tree from a JSON with hierachy
* @param rootElement
*/
fromJsonWithHierachy(rootElement) {}
} }

View File

@ -1,3 +1,17 @@
{ {
"extends": "tslint-config-standard" "extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
} }