npm.io
2.2.0 • Published 8 months ago

oneof

Licence
MIT
Version
2.2.0
Deps
0
Size
35 kB
Vulns
0
Weekly
0

oneof

Select a random item from an array.

Installation

npm install oneof

Usage

import oneof from 'oneof';

oneof(['apple', 'banana', 'cherry']); // => 'banana' (random)
oneof([1, 2, 3, 4, 5]);               // => 3 (random)
oneof(['only']);                      // => 'only'
oneof([]);                            // => null
oneof();                              // => null

API

oneof(array)

Returns a random item from the array, or null if the array is empty or undefined.

Parameter Type Description
array Array The array to select from

Returns: A random item from the array, or null.

License

ISC

Keywords