A generic collection class that extends Map to store objects with their IDs.

Type Parameters

  • T

    The type of objects stored in the collection.

Hierarchy

  • Map<string, T>
    • Collection

Constructors

Methods

Constructors

  • Constructs a new Collection object.

    Type Parameters

    • T

    Parameters

    • client: Client

      The client instance to be used for creating items.

    • obj: (new (client: Client, data: any) => T)

      The constructor function for items in the collection.

        • new (client, data): T
        • Parameters

          Returns T

    • Optionallimit: number

      The maximum number of items allowed in the collection.

    Returns Collection<T>

Methods

  • Adds an item to the collection.

    Parameters

    • id: string

      The ID of the item.

    • data: any

      The data of the item.

    Returns void

  • Clears all items from the collection.

    Returns void

  • Retrieves an item from the collection by its ID.

    Parameters

    • id: string

      The ID of the item.

    Returns T

    The item if found, otherwise undefined.

  • Checks if an item exists in the collection by its ID.

    Parameters

    • id: string

      The ID of the item.

    Returns boolean

    True if the item exists, otherwise false.

  • Removes an item from the collection by its ID.

    Parameters

    • id: string

      The ID of the item.

    Returns boolean

    True if the item was removed, otherwise false.

  • Returns an array of all items in the collection.

    Returns T[]

    An array of all items.