UNPKG

@charpeni/one-of

Version:

Type-safe utilities to return a random element from an array or random entry from an object

13 lines (11 loc) 395 B
import { oneElementOf } from "./oneElementOf.js"; import { oneEntryOf } from "./oneEntryOf.js"; import { isArray } from "./isArray.js"; //#region src/oneOf.ts function oneOf(input) { if (isArray(input)) return oneElementOf(input); if (typeof input === "object" && input !== null) return oneEntryOf(input); throw new TypeError("Expected an array or object"); } //#endregion export { oneOf };