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 property
const john = users.get('name', 'John');

// Map users to their names
const userNames = users.map(user => user.name);

Type Parameters

  • T

    The type of elements in the SuperSet

Hierarchy

  • Set<T>
    • SuperSet

Constructors

  • Type Parameters

    • T

    Parameters

    • Optionalvalues: null | readonly T[]

    Returns SuperSet<T>

  • Type Parameters

    • T

    Parameters

    • Optionaliterable: null | Iterable<T>

    Returns SuperSet<T>

Properties

"[toStringTag]": string
size: number

the number of (unique) elements in Set.

"[species]": SetConstructor

Methods

  • Iterates over values in the set.

    Returns IterableIterator<T>

  • Appends a new element with a specified value to the end of the Set.

    Parameters

    • value: T

    Returns this

  • Returns void

  • Removes a specified value from the Set.

    Parameters

    • value: T

    Returns boolean

    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.

    Returns IterableIterator<[T, T]>

  • Executes a provided function once per each value in the Set object, in insertion order.

    Parameters

    • callbackfn: (value: T, value2: T, set: Set<T>) => void
    • OptionalthisArg: any

    Returns void

  • Retrieves an item from the set based on a specific property and its value.

    Type Parameters

    • C extends string | number | symbol

      The key type of the property to search by

    Parameters

    • key: C

      The property key to search for

    • value: T[C]

      The value to match against the specified property

    Returns undefined | T

    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
  • Parameters

    • value: T

    Returns boolean

    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.

    Returns IterableIterator<T>

  • Transforms the set by applying a callback function to each item.

    Type Parameters

    • U

      The return type of the transformation

    Parameters

    • callback: (item: T) => U

      A function to transform each item

    Returns U[]

    An array of transformed items

    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.

    Returns T[]

    An array representation of the set's items

    const set = new SuperSet([1, 2, 3]);
    const jsonArray = set.toJSON(); // [1, 2, 3]
  • Returns an iterable of values in the set.

    Returns IterableIterator<T>