UNPKG

@typescript-package/data

Version:

A lightweight TypeScript library for basic data management.

98 lines (97 loc) 3.21 kB
import { DataCore } from './data-core.abstract'; /** * @description The `WeakData` class is a concrete class that stores data in a static `WeakMap`. * @export * @class WeakData * @template Type * @extends {DataCore<Type>} */ export declare class WeakData<Type> extends DataCore<Type> { #private; /** * @description Returns a new `WeakData` instance with a given value. * @public * @static * @template Type * @param {Type} value The value of `Type`. * @returns {WeakData<Type>} Returns a new `WeakData` instance. */ static create<Type>(value: Type): WeakData<Type>; /** * @description Gets the data value from another instance. * @public * @static * @template Type * @param {WeakData<Type>} instance Another instance from which to get the data. * @returns {Type} The value of the data stored in the given instance. */ static get<Type>(instance: WeakData<Type>): Type; /** * @description Checks whether the instance exists in the data. * @public * @static * @template Type * @param {WeakData<Type>} instance The instance to check. * @returns {boolean} "a boolean indicating whether an element with the specified key exists or not." */ static has<Type>(instance: WeakData<Type>): boolean; /** * @description Returns the `string` tag representation of the `WeakData` class when used in `Object.prototype.toString.call(instance)`. * @public * @readonly * @type {string} */ get [Symbol.toStringTag](): string; /** * @description Returns the readonly value of `Type` from static `WeakMap`. * @public * @readonly * @type {Type} */ get value(): Readonly<Type>; /** * Creates an instance of `WeakData`. * @constructor * @param {Type} value Initial data value of `Type`. */ constructor(value: Type); /** * @description Clears the value to `null`. * @public * @returns {this} The `this` current instance. */ clear(): this; /** * @description Removes the data value in a static `WeakMap`. * @public * @returns {this} The `this` current instance. */ delete(): this; /** * @description Destroys the value in a static `WeakMap`. * @public * @returns {this} The `this` current instance. */ destroy(): this; /** * @description Sets the data value in a static `WeakMap`. * @public * @param {Type} value The data of `Type` to set. * @returns {this} The `this` current instance. */ set(value: Type): this; /** * @description Applies the callback to the current value and updates it. * @public * @param {(value: Type) => Type} callbackFn The callback to apply to the value. * @returns {this} The `this` current instance. */ update(callbackFn: (value: Type) => Type): this; /** * @description Creates a new instance with a new value of `Type`. * @public * @param {Type} value The value of `Type`. * @returns {WeakData<Type>} Returns a `WeakData` instance with value of `Type`. */ with(value: Type): WeakData<Type>; }