UNPKG

@grandom/shuffle

Version:

A configurable, flexible, seedable, and overall great random shuffler.

52 lines (51 loc) 2.09 kB
import { RandomGenerator, RandomEngine } from '@grandom/core'; export interface ShuffleObjectOptions<T = any> { /** * Filters the input object by entry. * * @param entry The specific entry to filter from the input object. * @returns Whether to keep the specific entry in the shuffle pool. */ filter?: (key: keyof T, value: T[keyof T]) => boolean; /** * Exclude one or multiple elements from the input array. */ exclude?: T; } export default class RandomObjectShuffle extends RandomGenerator { constructor(engine: RandomEngine); canBeParsed(arg1: any): boolean; parse(arg1: any, arg2: any, arg3: any): any; /** * Shuffles (mixes) the input object entries randomly and returns them * as a new object (the input object is not modified). * * @param object The object to use to shuffle. */ shuffle<T extends Record<string, any>>(object: T): T; /** * Shuffles (mixes) the input object entries randomly and returns them * as a new object (the input object is not modified). * * @param object The object to use to shuffle. * @param count The count (length) of the returned object. */ shuffle<T extends Record<string, any>>(object: T, count: number): T; /** * Shuffles (mixes) the input object entries randomly and returns them * as a new object (the input object is not modified). * * @param object The object to use to shuffle. * @param options Shuffle options (filtering and fallback). */ shuffle<T extends Record<string, any>>(object: T, options: ShuffleObjectOptions<T>): T; /** * Shuffles (mixes) the input object entries randomly and returns them * as a new object (the input object is not modified). * * @param object The object to use to shuffle. * @param count The count (length) of the returned object. * @param options Shuffle options (filtering and fallback). */ shuffle<T extends Record<string, any>>(object: T, count: number, options: ShuffleObjectOptions<T>): T; }