Compare commits

..

36 Commits

Author SHA1 Message Date
42b59c109d 4.0.18 2020-11-24 18:47:46 +00:00
8f18faaf1c fix(core): update 2020-11-24 18:47:45 +00:00
ccd5b80d67 4.0.17 2020-07-14 10:55:49 +00:00
298904e17e fix(core): update 2020-07-14 10:55:48 +00:00
fa91e67aef 4.0.16 2020-07-14 08:58:30 +00:00
5e99066bee fix(core): update 2020-07-14 08:58:30 +00:00
a838f7eb80 4.0.15 2020-07-14 01:11:49 +00:00
979e93be27 fix(core): update 2020-07-14 01:11:48 +00:00
60587f052c 4.0.14 2020-07-12 00:44:51 +00:00
da5bd43a42 fix(core): update 2020-07-12 00:44:50 +00:00
24559d1582 4.0.13 2020-05-27 23:50:08 +00:00
d92657b130 fix(core): update 2020-05-27 23:50:07 +00:00
f8f34bf8a3 4.0.12 2020-05-27 20:22:46 +00:00
861d2c04b3 fix(core): update 2020-05-27 20:22:45 +00:00
5845d74160 4.0.11 2020-05-27 20:07:28 +00:00
9dd952e6b7 fix(core): update 2020-05-27 20:07:28 +00:00
742a711359 4.0.10 2020-05-27 18:54:07 +00:00
8878a0ef8b fix(core): update 2020-05-27 18:54:07 +00:00
6a52e81cdd 4.0.9 2020-05-27 18:41:22 +00:00
757e709f3f fix(core): update 2020-05-27 18:41:22 +00:00
e0d9c3a3e0 4.0.8 2020-05-27 18:22:40 +00:00
150953adaf fix(core): update 2020-05-27 18:22:40 +00:00
e0eba5d206 4.0.7 2020-05-27 18:15:14 +00:00
d9eb836f98 fix(core): update 2020-05-27 18:15:14 +00:00
6d29798660 4.0.6 2020-05-26 00:06:34 +00:00
f80a84086c fix(core): update 2020-05-26 00:06:34 +00:00
929a6eff07 4.0.5 2020-05-25 22:18:42 +00:00
87243881bb fix(core): update 2020-05-25 22:18:41 +00:00
5d51c14bd6 4.0.4 2020-05-25 22:04:22 +00:00
453c6d6ae8 fix(core): update 2020-05-25 22:04:21 +00:00
2e9fe308df 4.0.3 2020-05-25 18:10:10 +00:00
96a71638a0 fix(core): update 2020-05-25 18:10:10 +00:00
1c7582d328 4.0.2 2020-05-25 15:38:58 +00:00
ccff9b39be fix(core): update 2020-05-25 15:38:57 +00:00
749be9ac60 4.0.1 2020-05-25 13:18:53 +00:00
7c9ad26519 fix(core): update 2020-05-25 13:18:53 +00:00
20 changed files with 10451 additions and 861 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
dist_*/
# custom

View File

@ -24,13 +24,14 @@ mirror:
- docker
- notpriv
snyk:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
audit:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command snyk test
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
tags:
- lossless
- docker

11151
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
{
"name": "@pushrocks/lik",
"version": "4.0.0",
"version": "4.0.18",
"private": false,
"description": "light little helpers for node",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild)"
"build": "(tsbuild --web && tsbundle npm)"
},
"repository": {
"type": "git",
@ -20,33 +20,37 @@
},
"homepage": "https://gitlab.com/pushrocks/lik#README",
"devDependencies": {
"@gitzone/tsbuild": "^2.1.17",
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^13.7.0",
"tslint": "^6.0.0",
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsbundle": "^1.0.78",
"@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.14.9",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@pushrocks/smartdelay": "^2.0.6",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrx": "^2.0.5",
"@pushrocks/smarttime": "^3.0.12",
"@pushrocks/smartunique": "^3.0.1",
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartmatch": "^1.0.7",
"@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartrx": "^2.0.19",
"@pushrocks/smarttime": "^3.0.37",
"@types/minimatch": "^3.0.3",
"minimatch": "^3.0.4",
"symbol-tree": "^3.2.4"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_web/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

View File

@ -8,13 +8,20 @@ light little helpers for node
* [docs (typedoc)](https://pushrocks.gitlab.io/lik/)
## Status for master
[![pipeline status](https://gitlab.com/pushrocks/lik/badges/master/pipeline.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)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/lik/badge.svg)](https://snyk.io/test/npm/@pushrocks/lik)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/lik/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/lik/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/lik)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/lik)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/lik)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/lik)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/lik)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage
@ -35,7 +42,6 @@ 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.
Objectmap takes care of keeping track of objects for you.
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)

View File

@ -4,7 +4,7 @@ import * as lik from '../ts/index';
let testInterestmap: lik.InterestMap<number, number>;
tap.test('should create an interestmap', async () => {
testInterestmap = new lik.InterestMap(numberArg => {
testInterestmap = new lik.InterestMap((numberArg) => {
return numberArg.toString();
});
});

View File

@ -14,11 +14,11 @@ interface ITestObject {
let testObjectmap: lik.ObjectMap<ITestObject>;
let testObject1: ITestObject = {
propOne: 'hello',
propTwo: 'hello2'
propTwo: 'hello2',
};
let testObject2: ITestObject = {
propOne: 'hello',
propTwo: 'hello2'
propTwo: 'hello2',
};
tap.test('new lik.Objectmap() -> should correctly instantiate an Objectmap', async () => {
@ -44,7 +44,7 @@ tap.test('lik.Objectmap.remove() -> should correctly remove an object to Objectm
});
tap.test('Objectmap.forEach -> should correctly run a function forEach map object', async () => {
testObjectmap.forEach(itemArg => {
testObjectmap.forEach((itemArg) => {
expect(itemArg).to.have.property('propOne');
});
});
@ -52,7 +52,7 @@ tap.test('Objectmap.forEach -> should correctly run a function forEach map objec
tap.test('lik.Objectmap.find() -> should correctly find an object', async () => {
let myObject = { propOne: 'helloThere', propTwo: 'helloAnyway' };
testObjectmap.add(myObject);
let referenceObject = testObjectmap.find(itemArg => {
let referenceObject = testObjectmap.find((itemArg) => {
return itemArg.propOne === 'helloThere';
});
// tslint:disable-next-line:no-unused-expression

View File

@ -8,12 +8,12 @@ import * as lik from '../ts/index';
let testTimedAggregator: lik.TimedAggregtor<string>;
tap.test('should create a timed aggregaotor', async tools => {
tap.test('should create a timed aggregaotor', async (tools) => {
testTimedAggregator = new lik.TimedAggregtor<string>({
aggregationIntervalInMillis: 1000,
functionForAggregation: aggregation => {
functionForAggregation: (aggregation) => {
console.log(aggregation);
}
},
});
testTimedAggregator.add('This');
testTimedAggregator.add('is a whole sentence.');

View File

@ -1 +0,0 @@
import './test.objectmap';

View File

@ -1,5 +1,6 @@
export * from './lik.fastmap';
export * from './lik.interestmap';
export * from './lik.interestmap.interest';
export * from './lik.limitedarray';
export * from './lik.looptracker';
export * from './lik.objectmap';

View File

@ -60,7 +60,7 @@ export class FastMap<T> {
for (const key of fastMapArg.getKeys()) {
concatedFastmap.addToMap(key, fastMapArg.getByKey(key), {
force: true
force: true,
});
}
@ -75,7 +75,7 @@ export class FastMap<T> {
public addAllFromOther(fastMapArg: FastMap<T>) {
for (const key of fastMapArg.getKeys()) {
this.addToMap(key, fastMapArg.getByKey(key), {
force: true
force: true,
});
}
}

View File

@ -2,7 +2,14 @@ import * as plugins from './lik.plugins';
import { InterestMap, IInterestComparisonFunc } from './lik.interestmap';
export interface IInterestOptions<DTInterestFullfillment> {
markLostAfterDefault: number;
defaultFullfillment?: DTInterestFullfillment;
}
export class Interest<DTInterestId, DTInterestFullfillment> {
public options: IInterestOptions<DTInterestFullfillment>;
private interestMapRef: InterestMap<DTInterestId, DTInterestFullfillment>;
public originalInterest: DTInterestId;
public comparisonFunc: IInterestComparisonFunc<DTInterestId>;
@ -41,14 +48,20 @@ export class Interest<DTInterestId, DTInterestFullfillment> {
constructor(
interestMapArg: InterestMap<DTInterestId, DTInterestFullfillment>,
interestArg: DTInterestId,
comparisonFuncArg: IInterestComparisonFunc<DTInterestId>
comparisonFuncArg: IInterestComparisonFunc<DTInterestId>,
optionsArg?: IInterestOptions<DTInterestFullfillment>
) {
this.interestMapRef = interestMapArg;
this.originalInterest = interestArg;
this.comparisonFunc = comparisonFuncArg;
this.interestMapRef = interestMapArg;
this.options = optionsArg;
this.destructionTimer.completed.then(() => {
this.destroy();
});
if (this.options?.markLostAfterDefault) {
plugins.smartdelay.delayFor(this.options.markLostAfterDefault).then(this.markLost);
}
}
// ===============================
@ -60,6 +73,9 @@ export class Interest<DTInterestId, DTInterestFullfillment> {
*/
public destroy() {
this.interestMapRef.removeInterest(this);
if (!this.isFullfilled && this.options.defaultFullfillment) {
this.fullfillInterest(this.options.defaultFullfillment);
}
}
/**

View File

@ -7,7 +7,13 @@ import { Interest } from './lik.interestmap.interest';
export type IInterestComparisonFunc<T> = (objectArg: T) => string;
export interface IInterestMapOptions {
markLostAfterDefault?: number;
}
export class InterestMap<DTInterestId, DTInterestFullfillment> {
public options: IInterestMapOptions;
/**
* stores interests that are currently fullfilled by the cache
*/
@ -18,8 +24,9 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
*/
private comparisonFunc: IInterestComparisonFunc<DTInterestId>;
constructor(comparisonFuncArg: IInterestComparisonFunc<DTInterestId>) {
constructor(comparisonFuncArg: IInterestComparisonFunc<DTInterestId>, optionsArg: IInterestMapOptions = {}) {
this.comparisonFunc = comparisonFuncArg;
this.options = optionsArg;
}
/**
@ -27,17 +34,22 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
* @param objectArg
*/
public async addInterest(
objectArg: DTInterestId
objectArg: DTInterestId,
defaultFullfillmentArg?: DTInterestFullfillment
): Promise<Interest<DTInterestId, DTInterestFullfillment>> {
const comparisonString = this.comparisonFunc(objectArg);
let returnInterest: Interest<DTInterestId, DTInterestFullfillment>;
const newInterest = new Interest<DTInterestId, DTInterestFullfillment>(
this,
objectArg,
this.comparisonFunc
this.comparisonFunc,
{
markLostAfterDefault: this.options.markLostAfterDefault,
defaultFullfillment: defaultFullfillmentArg
}
);
let interestExists = false;
await this.interestObjectMap.forEach(interestArg => {
await this.interestObjectMap.forEach((interestArg) => {
if (!interestExists && interestArg.comparisonString === newInterest.comparisonString) {
console.log('info', `interest already exists for ${newInterest.comparisonString}`);
interestExists = true;
@ -61,7 +73,7 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
* @param objectArg removes an interest from the InterestMap
*/
public removeInterest(interestArg: Interest<DTInterestId, DTInterestFullfillment>) {
const interestToRemove = this.interestObjectMap.findOneAndRemove(interestArg2 => {
const interestToRemove = this.interestObjectMap.findOneAndRemove((interestArg2) => {
return interestArg.comparisonString === interestArg2.comparisonString;
});
}
@ -79,7 +91,7 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
* @param comparisonStringArg
*/
public checkInterestByString(comparisonStringArg: string): boolean {
const foundInterest = this.interestObjectMap.find(interest => {
const foundInterest = this.interestObjectMap.find((interest) => {
return interest.comparisonString === comparisonStringArg;
});
if (foundInterest) {
@ -106,7 +118,7 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
*/
public findInterest(objectArg: DTInterestId): Interest<DTInterestId, DTInterestFullfillment> {
const comparableString = this.comparisonFunc(objectArg);
const interest = this.interestObjectMap.find(interestArg => {
const interest = this.interestObjectMap.find((interestArg) => {
return interestArg.comparisonString === comparableString;
});
return interest; // if an interest is found, the interest is returned, otherwise interest is null

View File

@ -1,6 +1,14 @@
import * as plugins from './lik.plugins';
import { FastMap } from './lik.fastmap';
export const uni = (prefix: string = 'uni') => {
return `${prefix}xxxxxxxxxxx`.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
};
export interface IObjectmapForEachFunction<T> {
(itemArg: T): void;
}
@ -49,6 +57,8 @@ export class ObjectMap<T> {
const object = this.getMappedUnique(uniqueKey);
}
public addSubject = new plugins.smartrx.rxjs.Subject<T>();
/**
* add object to Objectmap
* returns false if the object is already in the map
@ -64,8 +74,9 @@ export class ObjectMap<T> {
}
// otherwise lets create it
const uniqueKey = plugins.smartunique.shortId();
const uniqueKey = uni('key');
this.addMappedUnique(uniqueKey, objectArg);
this.addSubject.next(objectArg);
return uniqueKey;
}

View File

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

View File

@ -4,13 +4,11 @@ import * as plugins from './lik.plugins';
* allows you to easily keep track of a bunch of strings
*/
export interface ITriggerFunction {
(): boolean;
}
export type TTriggerFunction = (stringArray?: string[]) => boolean;
export class Stringmap {
private _stringArray: string[] = [];
private _triggerUntilTrueFunctionArray: ITriggerFunction[] = [];
private _triggerUntilTrueFunctionArray: TTriggerFunction[] = [];
constructor() {}
/**
* add a string to the Stringmap
@ -60,9 +58,10 @@ export class Stringmap {
* checks stringPresence with minimatch
*/
public checkMinimatch(miniMatchStringArg: string): boolean {
const smartMatchInstance = new plugins.smartmatch.SmartMatch(miniMatchStringArg);
let foundMatch: boolean = false;
for (const stringItem of this._stringArray) {
if (plugins.minimatch(stringItem, miniMatchStringArg)) {
if (smartMatchInstance.match(stringItem)) {
foundMatch = true;
}
}
@ -92,22 +91,27 @@ export class Stringmap {
/**
* register a new trigger
*/
public registerUntilTrue(functionArg: ITriggerFunction, doFunctionArg) {
public registerUntilTrue(functionArg: TTriggerFunction, callbackArg?: () => any) {
const trueDeferred = plugins.smartpromise.defer();
this._triggerUntilTrueFunctionArray.push(() => {
const result = functionArg();
const result = functionArg(this.getStringArray());
if (result === true) {
doFunctionArg();
if (callbackArg) {
callbackArg();
}
trueDeferred.resolve();
}
return result;
});
this.notifyTrigger();
return trueDeferred.promise;
}
/**
* notifies triggers
*/
private notifyTrigger() {
const filteredArray = this._triggerUntilTrueFunctionArray.filter(functionArg => {
const filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
return !functionArg();
});
this._triggerUntilTrueFunctionArray = filteredArray;