UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

116 lines 5.09 kB
/** * Helper function to add all of the values in one set to another set. The first set passed will be * modified in place. * * This function is variadic, meaning that you can specify N sets to add to the first set. */ export declare function addSetsToSet<T>(mainSet: Set<T>, ...setsToAdd: ReadonlyArray<ReadonlySet<T>>): void; /** * Helper function to create a new set that is the composition of two or more sets. * * This function is variadic, meaning that you can specify N sets. */ export declare function combineSets<T>(...sets: ReadonlyArray<ReadonlySet<T>>): ReadonlySet<T>; /** Helper function to copy a set. (You can also use a Set constructor to accomplish this task.) */ export declare function copySet<T>(oldSet: ReadonlySet<T>): Set<T>; /** * Helper function to delete all of the values in one set from another set. The first set passed * will be modified in place. * * This function is variadic, meaning that you can specify N sets to remove from the first set. */ export declare function deleteSetsFromSet<T>(mainSet: Set<T>, ...setsToRemove: ReadonlyArray<ReadonlySet<T>>): void; /** * Helper function to get a random element from the provided set. * * If you want to get an unseeded element, you must explicitly pass `undefined` to the `seedOrRNG` * parameter. * * @param set The set to get an element from. * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the * `RNG.Next` method will be called. If `undefined` is provided, it will default to * a random seed. * @param exceptions Optional. An array of elements to skip over if selected. */ export declare function getRandomSetElement<T extends number | string>(set: ReadonlySet<T>, seedOrRNG: Seed | RNG | undefined, exceptions?: readonly T[]): T; /** * Helper function to get all possible combinations of the given set. This includes the combination * of an empty set. * * For example, if this function is provided a set containing 1, 2, and 3, then it will return an * array containing the following sets: * * - [] (if `includeEmptyArray` is set to true) * - [1] * - [2] * - [3] * - [1, 2] * - [1, 3] * - [2, 3] * - [1, 2, 3] * * @param set The set to get the combinations of. * @param includeEmptyArray Whether to include an empty array in the combinations. */ export declare function getSetCombinations<T extends number | string>(set: ReadonlySet<T>, includeEmptyArray: boolean): ReadonlyArray<ReadonlySet<T>>; /** * Helper function to get a sorted array based on the contents of a set. * * Normally, set values are returned in insertion order, so use this function when the ordering of * the contents is important. */ export declare function getSortedSetValues<T extends number | string>(set: ReadonlySet<T>): T[]; /** * Helper function to convert the keys of an object to a read-only set. * * Note that the set values will be inserted in a random order, due to how `pairs` works under the * hood. * * Also see the `objectKeysToSet` function. */ export declare function objectKeysToReadonlySet<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlySet<K>; /** * Helper function to convert the keys of an object to a set. * * Note that the set values will be inserted in a random order, due to how `pairs` works under the * hood. * * Also see the `objectKeysToReadonlySet` function. */ export declare function objectKeysToSet<K extends string | number | symbol, V>(object: Record<K, V>): Set<K>; /** * Helper function to convert the values of an object to a read-only set. * * Note that the set values will be inserted in a random order, due to how `pairs` works under the * hood. * * Also see the `objectValuesToSet` function. */ export declare function objectValuesToReadonlySet<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlySet<V>; /** * Helper function to convert the values of an object to a set. * * Note that the set values will be inserted in a random order, due to how `pairs` works under the * hood. * * Also see the `objectValuesToReadonlySet` function. */ export declare function objectValuesToSet<K extends string | number | symbol, V>(object: Record<K, V>): Set<V>; /** * Helper function to add one or more elements to a set at once without having to repeatedly call * the `Set.add` method. * * This function is variadic, meaning that you can pass as many things as you want to add. */ export declare function setAdd<T>(set: Set<T>, ...elements: readonly T[]): void; /** * Helper function to check for one or more elements in a set at once without having to repeatedly * call the `Set.has` method. * * This function is variadic, meaning that you can pass as many things as you want to check for. It * will return true if one or more elements are found. */ export declare function setHas<T>(set: ReadonlySet<T>, ...elements: readonly T[]): boolean; /** Helper function to sum every value in a set together. */ export declare function sumSet(set: ReadonlySet<number>): number; //# sourceMappingURL=set.d.ts.map