@technobuddha > library > JSON > Data Structures
Class: JSONSet<T>
Defined in: json-set.ts:28
A Set-like collection for objects that can be serialized to JSON.
JSONSet stores objects by serializing them to JSON strings, allowing for deep equality comparison of objects rather than reference equality. This is useful for storing and comparing objects with the same structure and values, regardless of their references.
Example
const set = new JSONSet<{ a: number }>();
set.add({ a: 1 });
set.has({ a: 1 }); // true
set.has({ a: 2 }); // falseRemarks
- All objects are serialized using a
serializefunction and deserialized with adeserializefunction. - The set supports standard set operations such as union, intersection, difference, and symmetricDifference.
- Iteration yields deserialized objects.
See
Set
Type Parameters
| Type Parameter | Description |
|---|---|
T extends JsonObject | The type of objects stored in the set. Must extend JsonObject. |
Implements
Set<T>
Constructors
Constructor
new JSONSet<T>(values?:
| null
| Iterable<T, any, any>): JSONSet<T>;Defined in: src/json-set.ts:31
Parameters
| Parameter | Type |
|---|---|
values? | | null | Iterable<T, any, any> |
Returns
JSONSet<T>
Properties
| Property | Modifier | Type | Default value | Description | Defined in |
|---|---|---|---|---|---|
[toStringTag] | readonly | "JSONSet" | 'JSONSet' | The string tag used by Object.prototype.toString for this class. | src/json-set.ts:42 |
Accessors
size
Get Signature
get size(): number;Defined in: src/json-set.ts:52
Gets the number of elements in the set.
Returns
number
Implementation of
Set.sizeMethods
[iterator]()
iterator: SetIterator<T>;Defined in: src/json-set.ts:205
Returns an iterator over the values in the set.
Returns
SetIterator<T>
Implementation of
Set.[iterator]add()
add(value: T): this;Defined in: src/json-set.ts:59
Adds a serialized value to the set.
Parameters
| Parameter | Type |
|---|---|
value | T |
Returns
this
Implementation of
Set.addclear()
clear(): void;Defined in: src/json-set.ts:67
Removes all elements from the set.
Returns
void
Implementation of
Set.cleardelete()
delete(value: T): boolean;Defined in: src/json-set.ts:74
Removes the specified value from the set if it exists.
Parameters
| Parameter | Type |
|---|---|
value | T |
Returns
boolean
Implementation of
Set.deletedifference()
difference<U>(other: ReadonlySetLike<U>): Set<T>;Defined in: src/json-set.ts:81
Returns a new set containing elements present in this set but not in the other set.
Type Parameters
| Type Parameter |
|---|
U |
Parameters
| Parameter | Type |
|---|---|
other | ReadonlySetLike<U> |
Returns
Set<T>
Implementation of
Set.differenceentries()
entries(): SetIterator<[T, T]>;Defined in: src/json-set.ts:90
Returns an iterator over the set's values as [value, value] pairs.
Returns
SetIterator<[T, T]>
Implementation of
Set.entriesforEach()
forEach(callback: (value: T, key: T, set: Set<T>) => void, thisArg?: unknown): void;Defined in: src/json-set.ts:99
Executes a provided function once for each value in the set.
Parameters
| Parameter | Type |
|---|---|
callback | (value: T, key: T, set: Set<T>) => void |
thisArg? | unknown |
Returns
void
Implementation of
Set.forEachhas()
has(value: T): boolean;Defined in: src/json-set.ts:108
Determines whether the specified value exists in the set.
Parameters
| Parameter | Type |
|---|---|
value | T |
Returns
boolean
Implementation of
Set.hasintersection()
intersection<U>(other: ReadonlySetLike<U>): Set<T & U>;Defined in: src/json-set.ts:115
Returns a new set containing only the elements present in both this set and the provided set.
Type Parameters
| Type Parameter |
|---|
U |
Parameters
| Parameter | Type |
|---|---|
other | ReadonlySetLike<U> |
Returns
Set<T & U>
Implementation of
Set.intersectionisDisjointFrom()
isDisjointFrom(other: ReadonlySetLike<unknown>): boolean;Defined in: src/json-set.ts:126
Determines whether this set and the specified set have no elements in common.
Parameters
| Parameter | Type |
|---|---|
other | ReadonlySetLike<unknown> |
Returns
boolean
Implementation of
Set.isDisjointFromisSubsetOf()
isSubsetOf(other: ReadonlySetLike<unknown>): boolean;Defined in: src/json-set.ts:138
Determines whether all elements of this set are contained in another set.
Parameters
| Parameter | Type |
|---|---|
other | ReadonlySetLike<unknown> |
Returns
boolean
Implementation of
Set.isSubsetOfisSupersetOf()
isSupersetOf(other: ReadonlySetLike<unknown>): boolean;Defined in: src/json-set.ts:150
Determines whether this set contains all elements of the specified set.
Parameters
| Parameter | Type |
|---|---|
other | ReadonlySetLike<unknown> |
Returns
boolean
Implementation of
Set.isSupersetOfkeys()
keys(): SetIterator<T>;Defined in: src/json-set.ts:162
Returns an iterator over the keys in the set.
Returns
SetIterator<T>
Implementation of
Set.keyssymmetricDifference()
symmetricDifference<U>(other: ReadonlySetLike<U>): Set<T | U>;Defined in: src/json-set.ts:169
Returns a new set containing elements that are in either this set or the other set, but not in both.
Type Parameters
| Type Parameter |
|---|
U |
Parameters
| Parameter | Type |
|---|---|
other | ReadonlySetLike<U> |
Returns
Set<T | U>
Implementation of
Set.symmetricDifferenceunion()
union<U>(other: ReadonlySetLike<U>): Set<T | U>;Defined in: src/json-set.ts:189
Returns a new set containing all unique elements from this set and another set.
Type Parameters
| Type Parameter |
|---|
U |
Parameters
| Parameter | Type |
|---|---|
other | ReadonlySetLike<U> |
Returns
Set<T | U>
Implementation of
Set.unionvalues()
values(): SetIterator<T>;Defined in: src/json-set.ts:196
Returns an iterator that yields each value in the set after deserialization.
Returns
SetIterator<T>
Implementation of
Set.values