utilitish - v0.0.10
    Preparing search index...

    Interface Set<T>

    interface Set<T> {
        toList<T>(): T[];
        hasAny(...items: T[]): boolean;
        includes(...items: T[]): boolean;
        includes(items: Set<T>): boolean;
        union(...others: Set<T>[]): Set<T>;
        intersection(...others: Set<T>[]): Set<T>;
    }

    Type Parameters

    • T
    Index

    Methods

    • Converts the Set into an array, preserving insertion order.

      Type Parameters

      • T

        The type of elements in the Set

      Returns T[]

      An array containing all values in the Set in insertion order

      const set = new Set([1, 2, 3]);
      const arr = set.toList(); // [1, 2, 3]
      • Returns a new array instance each time; modifying it does not affect the Set
      • Empty sets return an empty array
    • Returns true if at least one of the given items is present in the Set.

      Parameters

      • ...items: T[]

        Variable number of items to check

      Returns boolean

      True if any item is in the Set, false if no items or Set is empty

      If arguments are not in array-like form

      const set = new Set(['a', 'b', 'c']);
      set.hasAny('d', 'a'); // true
      set.hasAny('d', 'e'); // false
      • Returns false if no items are provided (empty arguments)
      • Uses strict equality (===) to check for item presence
    • Returns true if all of the given items are present in the Set. Can accept items as separate arguments or as a single Set parameter.

      Parameters

      • ...items: T[]

      Returns boolean

      True if all items are in the Set, false otherwise

      If arguments are not in a valid format or not all Sets

      const set = new Set(['a', 'b', 'c']);
      set.includes('a', 'b'); // true
      set.includes('a', 'd'); // false
      set.includes(new Set(['a', 'b'])); // true
      • Returns true if no arguments are provided (like Array's every())
      • Can check against another Set by passing it as the single argument
      • Uses strict equality (===) for item comparison
    • Parameters

      Returns boolean

    • Returns a new Set that is the union (combination) of this Set and all given Sets.

      Parameters

      • ...others: Set<T>[]

        Sets to union with

      Returns Set<T>

      A new Set containing all unique elements from this Set and all given Sets

      If any argument is not a Set instance

      const set1 = new Set([1, 2, 3]);
      const set2 = new Set([3, 4, 5]);
      const result = set1.union(set2); // Set(5) { 1, 2, 3, 4, 5 }
      • Does not modify the original Set
      • Duplicate values across sets are automatically deduplicated (Set behavior)
      • Returns a new Set instance each time
    • Returns a new Set that is the intersection of this Set and all given Sets. Contains only elements that are present in all Sets (this + all given Sets).

      Parameters

      • ...others: Set<T>[]

        Sets to intersect with

      Returns Set<T>

      A new Set containing only elements that exist in all Sets

      If any argument is not a Set instance

      const set1 = new Set([1, 2, 3, 4]);
      const set2 = new Set([2, 3, 5]);
      const set3 = new Set([3, 6]);
      const result = set1.intersection(set2, set3); // Set(1) { 3 }
      • Does not modify the original Set
      • Returns an empty Set if no elements are common to all Sets
      • Returns a new Set instance each time