UNPKG

@typescript-package/data

Version:

A lightweight TypeScript library for basic data management.

72 lines (71 loc) 2.35 kB
import { DataCore } from '.'; /** * @deprecated In favor of `WeakStorage` in `typescript-package/storage`. * @description The `NamedWeakData` class is a concrete class that manages data in a static `Map` where data is associated with a specified name. * @export * @class NamedWeakData * @template [Type=any] * @template {string} [Name='default'] * @extends {DataCore<Type>} */ export declare class NamedWeakData<Type = any, Name extends string = 'default'> extends DataCore<Type> { #private; /** * @description Gets the data from another instance. * @public * @static * @template {string} Name * @template Type * @param {NamedWeakData<Name, Type>} instance Another instance from which to get the data. * @param {Name} name The name from which get the data. * @returns {Type} The value of the data stored in the given instance. */ static getFrom<Name extends string, Type>(instance: NamedWeakData<Type, Name>, name: Name): Type; /** * @description Returns the `string` tag representation of the `NamedWeakData` class when used in `Object.prototype.toString.call(instance)`. * @public * @readonly * @type {string} */ get [Symbol.toStringTag](): string; /** * @description * @public * @readonly * @type {Name} */ get name(): Name; /** * @description Returns the privately stored data value from the specified name of static `Map`. * @public * @readonly * @type {Type} */ get value(): Type; /** * Creates an instance of `NamedWeakData` child class. * @constructor * @param {Type} value Initial data value of `Type`. * @param {string} [name='default'] The name under which the value is stored, defaults to `default`. */ constructor(value: Type, name?: Name); /** * @description Clears the value in the `WeakMap`. * @public * @returns {this} Returns `this` current instance. */ clear(): this; /** * @description * @public * @returns {this} Returns `this` current instance. */ destroy(): this; /** * @description Sets the data value. * @public * @param {Type} value The data of `Type` to set. * @returns {this} Returns `this` current instance. */ set(value: Type): this; }