@push.rocks/lik
Version:
Provides a collection of lightweight helpers and utilities for Node.js projects.
116 lines (115 loc) • 3.18 kB
TypeScript
import * as plugins from './classes.plugins.js';
export declare const uni: (prefix?: string) => string;
export interface IObjectmapForEachFunction<T> {
(itemArg: T): void;
}
export interface IObjectmapFindFunctionSync<T> {
(itemArg: T): boolean;
}
export interface IObjectmapFindFunction<T> {
(itemArg: T): Promise<boolean>;
}
export interface IObjectMapEventData<T> {
operation: 'add' | 'remove';
payload: T;
}
/**
* allows keeping track of objects
*/
export declare class ObjectMap<T> {
private fastMap;
private reverseMap;
eventSubject: plugins.smartrx.rxjs.Subject<IObjectMapEventData<T>>;
/**
* returns a new instance
*/
constructor();
/**
* the number of objects in the map
*/
get length(): number;
/**
* adds an object mapped to a string
* the string must be unique
*/
addMappedUnique(uniqueKeyArg: string, objectArg: T): void;
/**
* fastest way to get an object from the map
* @param uniqueKey
*/
getMappedUnique(uniqueKeyArg: string): T;
/**
* remove key
* @param functionArg
*/
removeMappedUnique(uniqueKey: string): T;
/**
* add object to Objectmap
* returns the key for the object (existing or new)
*/
add(objectArg: T): string;
/**
* like .add but adds an whole array of objects
*/
addArray(objectArrayArg: T[]): void;
/**
* check if object is in Objectmap
*/
checkForObject(objectArg: T): boolean;
/**
* get key for object
*/
getKeyForObject(objectArg: T): string | null;
/**
* find object
*/
find(findFunction: IObjectmapFindFunction<T>): Promise<T>;
findSync(findFunction: IObjectmapFindFunctionSync<T>): T;
/**
* finds a specific element and then removes it
*/
findOneAndRemove(findFunction: IObjectmapFindFunction<T>): Promise<T>;
findOneAndRemoveSync(findFunction: IObjectmapFindFunctionSync<T>): T;
/**
* run function for each item in Objectmap
*/
forEach(functionArg: IObjectmapForEachFunction<T>): Promise<void>;
/**
* gets an object in the Observablemap and removes it, so it can't be retrieved again
*/
getOneAndRemove(): T;
/**
* returns a cloned array of all the objects currently in the Objectmap
*/
getArray(): T[];
/**
* check if Objectmap ist empty
*/
isEmpty(): boolean;
/**
* remove object from Objectmap
*/
remove(objectArg: T): T;
/**
* wipe Objectmap
*/
wipe(): void;
/**
* returns a new Objectmap that includes
*/
concat(objectMapArg: ObjectMap<T>): ObjectMap<T>;
/**
* tries to merge another Objectmap
* Note: uniqueKeyCollisions will cause overwrite
* @param objectMapArg
*/
addAllFromOther(objectMapArg: ObjectMap<T>): void;
map<U>(fn: (item: T) => U): U[];
filter(fn: (item: T) => boolean): T[];
reduce<U>(fn: (acc: U, item: T) => U, initial: U): U;
[Symbol.iterator](): Iterator<T>;
/**
* destroys the ObjectMap, completing the eventSubject and clearing all entries
*/
destroy(): void;
}