@typescript-package/set
Version:
A lightweight TypeScript library for enhanced `set` management.
1 lines • 11.7 kB
Source Map (JSON)
{"version":3,"file":"typescript-package-set.mjs","sources":["../../../package/set/src/lib/immutable-set.class.ts","../../../package/set/src/lib/set-on-hook.abstract.ts","../../../package/set/src/lib/core-set.abstract.ts","../../../package/set/src/lib/data-set.class.ts","../../../package/set/src/lib/index.ts","../../../package/set/src/public-api.ts","../../../package/set/src/typescript-package-set.ts"],"sourcesContent":["/**\n * @description Immutable version of `Set`.\n * @export\n * @class ImmutableSet\n * @template Type \n * @extends {Set<Readonly<Type>>}\n */\nexport class ImmutableSet<Type> extends Set<Readonly<Type>> {\n constructor(iterable?: Iterable<Type> | null) {\n super(iterable);\n this.add = (value: Type) => this;\n }\n public override delete(value: Type): boolean { return false; }\n public override clear(): this { return this;}\n}\n","// Abstract.\nimport { DataCore } from \"@typescript-package/data\";\n/**\n * @description\n * @export\n * @abstract\n * @class OnHook\n * @template Value \n * @template {DataCore<any>} DataType \n */\nexport abstract class SetOnHook<\n Value,\n DataType extends DataCore<any>\n> {\n /**\n * @description Hook called when a value is added.\n * @protected\n * @param {Value} value The added value.\n * @param {DataType} data The data holder.\n */\n protected onAdd(value: Value, data: DataType): void {}\n\n /**\n * @description Hook called when the `Set` is cleared.\n * @protected\n * @param {DataType} data The data holder.\n */\n protected onClear(data: DataType): void {}\n\n /**\n * @description Hook called when a value is deleted.\n * @protected\n * @param {Value} value The deleted value.\n * @param {boolean} success Whether the deletion was successful.\n * @param {DataType} data The data holder.\n */\n protected onDelete(value: Value, success: boolean, data: DataType): void {}\n}","// Class.\nimport { Data } from '@typescript-package/data';\nimport { ImmutableSet } from './immutable-set.class';\n// Abstract.\nimport { DataCore } from '@typescript-package/data';\nimport { SetOnHook } from './set-on-hook.abstract';\n// Interface.\nimport { SetTypeConstructor } from '@typescript-package/data';\n// Type.\nimport { DataConstructorInput } from '@typescript-package/data';\n// Constant: Symbol.\nimport { SymbolValue } from '@typescript-package/data';\n/**\n * @description The abstract core class for building customizable `Set` and `DataCore` related classes.\n * @export\n * @abstract\n * @class CoreSet\n * @template Type \n * @template {Set<Type>} [SetType=Set<Type>] \n * @template {DataCore<SetType>} [DataType=Data<SetType>] \n * @extends {SetOnHook<Type, DataType>}\n */\nexport abstract class CoreSet<\n Type,\n SetType extends Set<Type> = Set<Type>,\n DataType extends DataCore<SetType> = Data<SetType>\n> extends SetOnHook<Type, DataType> {\n /**\n * @description Returns the `string` tag representation of the `CoreSet` class when used in `Object.prototype.toString.call(instance)`.\n * @public\n * @readonly\n */\n public get [Symbol.toStringTag](): string {\n return CoreSet.name;\n }\n\n /**\n * @description The data instance used to hold the `Set` value, but omit direct access to it.\n * @public\n * @readonly\n * @type {Omit<DataType, 'value'>}\n */\n public get data(): Omit<DataType, 'value'> {\n return this.#data;\n }\n\n /**\n * @description Returns the readonly `ImmutableSet` of `Type`.\n * @public\n * @readonly\n * @type {ReadonlySet<Type>}\n */\n public get value(): ReadonlySet<Type> {\n return new ImmutableSet(this.#data.value);\n }\n\n /**\n * @inheritdoc\n * @public\n * @readonly\n * @type {number}\n */\n public get size() {\n return this.#data.value.size;\n }\n\n /**\n * @description The `Set` data holder of `DataCore` type.\n * @type {DataType}\n */\n #data: DataType;\n\n /**\n * Creates an instance of `CoreSet` child class.\n * @constructor\n * @param {?Iterable<Type>} [iterable] Initial value for `Set`.\n * @param {?SetTypeConstructor<Type, SetType>} [set] Custom `Set`.\n * @param {?DataConstructorInput<SetType, DataType>} [data] Custom data holder of generic type variable `DataType` to store the `Set`.\n */\n constructor(\n iterable?: Iterable<Type>,\n set?: SetTypeConstructor<Type, SetType>,\n data?: DataConstructorInput<Set<Type>, DataType>\n ) {\n super();\n this.#data = new (Array.isArray(data) ? data[0] : data ?? Data)(new (set || Set)(iterable) as SetType) as unknown as DataType;\n }\n\n /**\n * @description Access to the readonly set by using a symbol.\n * @public\n * @returns {Readonly<SetType>} \n */\n public [SymbolValue](): Readonly<SetType> {\n return this.#data.value;\n }\n\n /**\n * @description \"Appends a new element with a specified value to the end of the `Set`.\"\n * @public\n * @param {Type} value \n * @returns {this} \n */\n public add(value: Type): this {\n this.#data.value.add(value);\n this.onAdd(value, this.#data);\n return this;\n }\n \n /**\n * Clears all entries.\n * @inheritdoc\n * @public\n * @returns {this} \n */\n public clear(): this {\n this.#data.value.clear();\n this.onClear(this.#data);\n return this;\n }\n\n /**\n * \"Removes a specified value from the Set.\"\n * @public\n * @param {Type} value The value to delete.\n * @returns {boolean} \"Returns true if an element in the Set existed and has been removed, or false if the element does not exist.\"\n */\n public delete(value: Type): boolean {\n const result = this.#data.value.delete(value);\n return this.onDelete(value, result, this.#data), result;\n }\n\n /**\n * @description \"Returns an iterable of [v,v] pairs for every value v in the set.\"\n * @public\n * @returns {SetIterator<[Readonly<Type>, Readonly<Type>]>} \n */\n public entries(): SetIterator<[Readonly<Type>, Readonly<Type>]> {\n return this.#data.value.entries();\n }\n\n /**\n * @description\n * @public\n * @param {(value: Readonly<Type>, value2: Readonly<Type>, set: Set<Readonly<Type>>) => void} callbackfn \n * @param {?*} [thisArg] \n * @returns {this} \n */\n public forEach(callbackfn: (value: Readonly<Type>, value2: Readonly<Type>, set: Set<Readonly<Type>>) => void, thisArg?: any): this {\n this.#data.value.forEach(callbackfn, thisArg);\n return this;\n }\n\n /**\n * Checks if a value exists in the `Set`.\n * @inheritdoc\n * @public\n * @param {Type} value The value to check.\n * @returns {boolean} \"a boolean indicating whether an element with the specified value exists in the Set or not.\"\n */\n public has(value: Type): boolean {\n return this.#data.value.has(value);\n }\n\n /**\n * \"Despite its name, returns an iterable of the values in the set.\"\n * @inheritdoc\n * @public\n * @returns {SetIterator<Readonly<Type>>} \n */\n public keys(): SetIterator<Readonly<Type>> {\n return this.#data.value.keys();\n }\n\n /**\n * \"Returns an iterable of values in the set.\"\n * @inheritdoc\n * @public\n * @returns {SetIterator<Readonly<Type>>} \n */\n public values(): SetIterator<Readonly<Type>> {\n return this.#data.value.values();\n }\n}\n","// Class.\nimport { Data } from '@typescript-package/data';\n// Abstract.\nimport { CoreSet } from './core-set.abstract';\nimport { DataCore } from '@typescript-package/data';\n// Interface.\nimport { DataConstructorInput } from '@typescript-package/data';\n/**\n * @description The `DataSet` is a concrete class that extends `CoreSet` and encapsulates its data within a `DataCore` store, providing additional data management capabilities.\n * @export\n * @class DataSet\n * @template Type \n * @template {DataCore<Set<Type>>} [DataType=Data<Set<Type>>] \n * @extends {CoreSet<Type, Set<Type>, DataType>}\n */\nexport class DataSet<\n Type,\n DataType extends DataCore<Set<Type>> = Data<Set<Type>>\n> extends CoreSet<Type, Set<Type>, DataType> {\n /**\n * @description Returns the `string` tag representation of the `DataSet` class when used in `Object.prototype.toString.call(instance)`.\n * @public\n * @readonly\n */\n public override get [Symbol.toStringTag](): string {\n return DataSet.name;\n }\n\n /**\n * Creates an instance of `DataSet`.\n * @constructor\n * @param {?Iterable<Type>} [iterable] Initial value for `Set`.\n * @param {?DataConstructorInput<Set<Type>, DataType>} [data] Optional data instance of generic type variable `DataType` to store the `Set`.\n */\n constructor(\n iterable?: Iterable<Type>,\n data?: DataConstructorInput<Set<Type>, DataType>\n ) {\n super(iterable, Set, data);\n }\n}\n","// Abstract.\nexport { CoreSet } from './core-set.abstract';\nexport { SetOnHook } from './set-on-hook.abstract';\n// Class.\nexport { DataSet } from './data-set.class';\nexport { ImmutableSet } from './immutable-set.class';\n","/*\n * Public API Surface of set\n */\nexport {\n // Abstract.\n CoreSet,\n SetOnHook,\n\n // Class.\n DataSet,\n ImmutableSet,\n} from './lib';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;AAAA;;;;;;AAMG;AACG,MAAO,YAAmB,SAAQ,GAAmB,CAAA;AACzD,IAAA,WAAA,CAAY,QAAgC,EAAA;QAC1C,KAAK,CAAC,QAAQ,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,CAAC,KAAW,KAAK,IAAI;;AAElB,IAAA,MAAM,CAAC,KAAW,EAAA,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