UNPKG

@typescript-package/set

Version:

A lightweight TypeScript library for enhanced `set` management.

118 lines (117 loc) 4.16 kB
import { Data } from '@typescript-package/data'; import { DataCore } from '@typescript-package/data'; import { SetOnHook } from './set-on-hook.abstract'; import { SetTypeConstructor } from '@typescript-package/data'; import { DataConstructorInput } from '@typescript-package/data'; import { SymbolValue } from '@typescript-package/data'; /** * @description The abstract core class for building customizable `Set` and `DataCore` related classes. * @export * @abstract * @class CoreSet * @template Type * @template {Set<Type>} [SetType=Set<Type>] * @template {DataCore<SetType>} [DataType=Data<SetType>] * @extends {SetOnHook<Type, DataType>} */ export declare abstract class CoreSet<Type, SetType extends Set<Type> = Set<Type>, DataType extends DataCore<SetType> = Data<SetType>> extends SetOnHook<Type, DataType> { #private; /** * @description Returns the `string` tag representation of the `CoreSet` class when used in `Object.prototype.toString.call(instance)`. * @public * @readonly */ get [Symbol.toStringTag](): string; /** * @description The data instance used to hold the `Set` value, but omit direct access to it. * @public * @readonly * @type {Omit<DataType, 'value'>} */ get data(): Omit<DataType, 'value'>; /** * @description Returns the readonly `ImmutableSet` of `Type`. * @public * @readonly * @type {ReadonlySet<Type>} */ get value(): ReadonlySet<Type>; /** * @inheritdoc * @public * @readonly * @type {number} */ get size(): number; /** * Creates an instance of `CoreSet` child class. * @constructor * @param {?Iterable<Type>} [iterable] Initial value for `Set`. * @param {?SetTypeConstructor<Type, SetType>} [set] Custom `Set`. * @param {?DataConstructorInput<SetType, DataType>} [data] Custom data holder of generic type variable `DataType` to store the `Set`. */ constructor(iterable?: Iterable<Type>, set?: SetTypeConstructor<Type, SetType>, data?: DataConstructorInput<Set<Type>, DataType>); /** * @description Access to the readonly set by using a symbol. * @public * @returns {Readonly<SetType>} */ [SymbolValue](): Readonly<SetType>; /** * @description "Appends a new element with a specified value to the end of the `Set`." * @public * @param {Type} value * @returns {this} */ add(value: Type): this; /** * Clears all entries. * @inheritdoc * @public * @returns {this} */ clear(): this; /** * "Removes a specified value from the Set." * @public * @param {Type} value The value to delete. * @returns {boolean} "Returns true if an element in the Set existed and has been removed, or false if the element does not exist." */ delete(value: Type): boolean; /** * @description "Returns an iterable of [v,v] pairs for every value v in the set." * @public * @returns {SetIterator<[Readonly<Type>, Readonly<Type>]>} */ entries(): SetIterator<[Readonly<Type>, Readonly<Type>]>; /** * @description * @public * @param {(value: Readonly<Type>, value2: Readonly<Type>, set: Set<Readonly<Type>>) => void} callbackfn * @param {?*} [thisArg] * @returns {this} */ forEach(callbackfn: (value: Readonly<Type>, value2: Readonly<Type>, set: Set<Readonly<Type>>) => void, thisArg?: any): this; /** * Checks if a value exists in the `Set`. * @inheritdoc * @public * @param {Type} value The value to check. * @returns {boolean} "a boolean indicating whether an element with the specified value exists in the Set or not." */ has(value: Type): boolean; /** * "Despite its name, returns an iterable of the values in the set." * @inheritdoc * @public * @returns {SetIterator<Readonly<Type>>} */ keys(): SetIterator<Readonly<Type>>; /** * "Returns an iterable of values in the set." * @inheritdoc * @public * @returns {SetIterator<Readonly<Type>>} */ values(): SetIterator<Readonly<Type>>; }