An extended Set class with additional utility methods.
SuperSet enhances the standard JavaScript Set with additional methods like retrieving items by property, mapping, and custom JSON serialization.
interface User { id: number; name: string; age: number;}const users = new SuperSet<User>();users.add({ id: 1, name: 'John', age: 30 });users.add({ id: 2, name: 'Jane', age: 25 });// Get a user by a specific propertyconst john = users.get('name', 'John');// Map users to their namesconst userNames = users.map(user => user.name); Copy
interface User { id: number; name: string; age: number;}const users = new SuperSet<User>();users.add({ id: 1, name: 'John', age: 30 });users.add({ id: 2, name: 'Jane', age: 25 });// Get a user by a specific propertyconst john = users.get('name', 'John');// Map users to their namesconst userNames = users.map(user => user.name);
The type of elements in the SuperSet
Optional
Readonly
the number of (unique) elements in Set.
Static
Iterates over values in the set.
Appends a new element with a specified value to the end of the Set.
Removes a specified value from the Set.
Returns true if an element in the Set existed and has been removed, or false if the element does not exist.
Returns an iterable of [v,v] pairs for every value v in the set.
v
Executes a provided function once per each value in the Set object, in insertion order.
Retrieves an item from the set based on a specific property and its value.
The key type of the property to search by
The property key to search for
The value to match against the specified property
The first item matching the criteria, or undefined if no match is found
const users = new SuperSet<User>();const user = users.get('id', 1); // Returns the user with id 1 Copy
const users = new SuperSet<User>();const user = users.get('id', 1); // Returns the user with id 1
a boolean indicating whether an element with the specified value exists in the Set or not.
Despite its name, returns an iterable of the values in the set.
Transforms the set by applying a callback function to each item.
The return type of the transformation
A function to transform each item
An array of transformed items
const numbers = new SuperSet([1, 2, 3]);const squared = numbers.map(x => x * x); // [1, 4, 9] Copy
const numbers = new SuperSet([1, 2, 3]);const squared = numbers.map(x => x * x); // [1, 4, 9]
Converts the SuperSet to a JSON-serializable array.
An array representation of the set's items
const set = new SuperSet([1, 2, 3]);const jsonArray = set.toJSON(); // [1, 2, 3] Copy
const set = new SuperSet([1, 2, 3]);const jsonArray = set.toJSON(); // [1, 2, 3]
Returns an iterable of values in the set.
An extended Set class with additional utility methods.
Remarks
SuperSet enhances the standard JavaScript Set with additional methods like retrieving items by property, mapping, and custom JSON serialization.
Example