UNPKG

@typescript-package/map

Version:

A lightweight TypeScript library for enhanced `map` management.

107 lines (106 loc) 3.37 kB
import { DataCore, Data, SymbolValue, DataConstructorInput, MapTypeConstructor } from '@typescript-package/data'; import { MapOnHook } from './map-on-hook.abstract'; /** * @description The abstract core class for building customizable `Map` and `DataCore` related classes. * @export * @abstract * @class CoreMap * @template Key * @template Value * @template {Map<Key, Value>} [MapType=Map<Key, Value>] The type of `Map`. * @template {DataCore<MapType>} [DataType=Data<MapType>] The `Data` storage type of `Map` type. * @extends {MapOnHook<Key, Value, DataType>} */ export declare abstract class CoreMap<Key, Value, MapType extends Map<Key, Value> = Map<Key, Value>, DataType extends DataCore<MapType> = Data<MapType>> extends MapOnHook<Key, Value, DataType> { #private; /** * @description Returns the `string` tag representation of the `CoreMap` class when used in `Object.prototype.toString.call(instance)`. * @public * @readonly */ get [Symbol.toStringTag](): string; /** * @description Returns the privately stored data class. * @public * @readonly * @type {DataType} */ get data(): DataType; /** * @inheritdoc * @public * @readonly * @type {number} */ get size(): number; /** * Creates an instance of `CoreMap` child class. * @constructor * @param {?[Key, Value][]} [entries] Initial value for `Map`. * @param {?MapTypeConstructor<Key, Value, MapType>} [map] The map of generic type variable `MapType` for `Map` value. * @param {?DataConstructorInput<MapType, DataType>} [data] The data store of generic type variable `DataType` for `Map` value. */ constructor(entries?: [Key, Value][], map?: MapTypeConstructor<Key, Value, MapType>, data?: DataConstructorInput<MapType, DataType>); /** * @description Access to the readonly map by using a symbol. * @public * @returns {Readonly<MapType>} */ [SymbolValue](): Readonly<MapType>; /** * Clears all entries. * @inheritdoc * @public * @returns {this} */ clear(): this; /** * Deletes a value from the `key`. * @inheritdoc * @public * @param {Key} key The key to delete. * @returns {boolean} */ delete(key: Key): boolean; /** * @inheritdoc */ entries(): IterableIterator<[Key, Value]>; /** * @inheritdoc * @public * @param {(value: Value, key: Key, map: Map<Key, Value>) => void} callbackfn * @param {?*} [thisArg] * @returns {this} */ forEach(callbackfn: (value: Value, key: Key, map: Map<Key, Value>) => void, thisArg?: any): this; /** * @inheritdoc * @public * @param {Key} key The key to get the value. */ get(key: Key): Value | undefined; /** * @inheritdoc * @public * @param {Key} key The key to check. * @returns {boolean} */ has(key: Key): boolean; /** * @inheritdoc */ keys(): MapIterator<Key>; /** * @inheritdoc * @public * @param {Key} key The key under which the `value` set. * @param {Value} value The value of `Value` type. * @returns {this} The `this` current instance for chaining. */ set(key: Key, value: Value): this; /** * @inheritdoc */ values(): MapIterator<Value>; }