@charpeni/one-of
Version:
Type-safe utilities to return a random element from an array or random entry from an object
20 lines (18 loc) • 694 B
text/typescript
import { oneElementOf } from "./oneElementOf.cjs";
import { oneEntryOf } from "./oneEntryOf.cjs";
//#region src/oneOf.d.ts
/**
* Returns one random element from the array or one random entry from the object.
*
* For more specific functions, see `oneElementOf` and `oneEntryOf`.
*
* @example
* ```ts
* oneOf([1, 2, 3]); // 2
* oneOf({ a: 1, b: 2, c: 3 }); // ['b', 2]
* ```
*/
declare function oneOf<const A>(input: Parameters<typeof oneElementOf<A>>[0]): ReturnType<typeof oneElementOf<A>>;
declare function oneOf<const O extends Record<string | number | symbol, unknown>>(input: Parameters<typeof oneEntryOf<O>>[0]): ReturnType<typeof oneEntryOf<O>>;
//#endregion
export { oneOf };