Compare commits

..

14 Commits

Author SHA1 Message Date
c2f366de7f 4.0.19 2020-11-24 18:53:28 +00:00
ae47276569 fix(core): update 2020-11-24 18:53:28 +00:00
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
20 changed files with 9189 additions and 952 deletions

View File

@ -19,23 +19,35 @@ mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
audit:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
- npmci command npm audit --audit-level=high --only=dev
tags:
- lossless
- docker
- notpriv
allow_failure: true
# ====================
# test stage
@ -50,9 +62,7 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@ -63,9 +73,7 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -85,6 +93,8 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}

9971
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.12",
"version": "4.0.19",
"private": false,
"description": "light little helpers for node",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild && tsbundle npm)"
"build": "(tsbuild --web && tsbundle npm)"
},
"repository": {
"type": "git",
@ -20,22 +20,21 @@
},
"homepage": "https://gitlab.com/pushrocks/lik#README",
"devDependencies": {
"@gitzone/tsbuild": "^2.1.24",
"@gitzone/tsbundle": "^1.0.69",
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.2.1",
"@types/node": "^14.0.5",
"tslint": "^6.1.2",
"@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.9",
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartmatch": "^1.0.7",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrx": "^2.0.15",
"@pushrocks/smarttime": "^3.0.18",
"@pushrocks/smartunique": "^3.0.3",
"@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartrx": "^2.0.19",
"@pushrocks/smarttime": "^3.0.37",
"@types/minimatch": "^3.0.3",
"symbol-tree": "^3.2.4"
},
@ -50,5 +49,8 @@
"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

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,12 @@ 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 +37,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 +76,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 +94,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 +121,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

@ -6,9 +6,8 @@ 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, smartmatch, smartpromise, smartrx, smarttime, smartunique };
export { smartdelay, smartmatch, smartpromise, smartrx, smarttime };
// ==============
// third party

View File

@ -4,7 +4,7 @@ import * as plugins from './lik.plugins';
* allows you to easily keep track of a bunch of strings
*/
export type TTriggerFunction = (stringArray?: string[]) => boolean;
export type TTriggerFunction = (stringArray?: string[]) => boolean;
export class Stringmap {
private _stringArray: string[] = [];
@ -111,7 +111,7 @@ export class Stringmap {
* notifies triggers
*/
private notifyTrigger() {
const filteredArray = this._triggerUntilTrueFunctionArray.filter(functionArg => {
const filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
return !functionArg();
});
this._triggerUntilTrueFunctionArray = filteredArray;