UNPKG

rjweb-server

Version:

Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS

108 lines (107 loc) 3.4 kB
import { RealAny } from "../types/internal"; export declare class BaseCollection<Key extends PropertyKey = PropertyKey, Value = any> { protected modifyFn: ((event: 'set' | 'delete' | 'clear', key: any, value: any) => any) | null; protected data: Map<Key, Value>; protected maxElements: number; protected allowModify: boolean; /** * Create a New Value Collection * @example * ``` * const collection = new ValueCollection() * * collection * .set('name', 'beta') * .set('key', 'value') * * collection.has('key') // true * collection.has('ms') // false * * collection.toJSON() // { name: 'beta', key: 'value' } * * collection.forEach((key, value) => { * console.log(key, value) * }) * * collection.clear(['key']) * * collection.toJSON() // { key: 'value' } * ``` * @since 2.5.0 */ constructor( /** JSON Data to Import */ data?: Record<Key, Value>, /** Function to Parse Values with */ parse?: (value: any) => Value, /** Whether to allow modifying the Values */ allowModify?: boolean, /** How many Elements to store at max, when hit clear */ maxElements?: number); /** * Check if a Key exists * @since 2.5.0 */ has( /** The Key to check */ key: Key): boolean; /** * Get a Key * @since 2.5.0 */ get<T extends Key, Fallback extends Value | undefined = undefined>( /** The Key to get */ key: T, /** The Fallback Value */ fallback?: Fallback): Value | Fallback; /** * Get all Objects as JSON * @since 2.5.0 */ toJSON( /** Excluded Keys */ excluded?: Key[]): Record<Key, Value>; /** * Get all Values as Array * @since 2.5.0 */ toArray( /** Excluded Keys */ excluded?: Key[]): Value[]; /** * Loop over all Keys * @since 2.5.0 */ forEach( /** Callback Function */ callback: (key: Key, value: Value, index: number) => RealAny, /** Excluded Keys */ excluded?: Key[]): this; /** * Object Iterator (similar to .forEach() but can be used in for ... of loops) * @since 7.7.0 */ [Symbol.iterator](): Iterator<[Key, Value]>; /** * Get the Entries of this Value Collection * @since 6.0.3 */ entries( /** Excluded Keys */ excluded?: Key[]): [Key, Value][]; /** * Map the Keys to a new Array * @since 5.3.1 */ map<Callback extends (key: Key, value: Value, index: number, data: this) => RealAny>( /** Callback Function */ callback: Callback, /** Excluded Keys */ excluded?: Key[]): ReturnType<Callback>[]; /** * The Amount of Stored Objects * @since 2.7.2 */ get objectCount(): number; } /** * A Key - Value Store with easy access functions * @example * ``` * const collection = new ValueCollection(...) * ``` * @since 2.5.0 */ export default class ValueCollection<Key extends PropertyKey = PropertyKey, Value = any, SetValue = Value> extends BaseCollection<Key, Value> { /** * Set a Key * @since 2.5.0 */ set( /** The Key to set */ key: Key, /** The new Value */ value: SetValue): this; /** * Delete a Key * @since 8.0.0 */ delete( /** The Key to delete */ key: Key): this; /** * Clear the Stored Objects * @since 3.0.0 */ clear( /** Excluded Keys */ excluded?: Key[]): number; }