https://github.com/fantasyui-com/oneof
Return a random item from a list. [Library, Algorithm, Standard Library]
https://github.com/fantasyui-com/oneof
library
Last synced: 4 days ago
JSON representation
Return a random item from a list. [Library, Algorithm, Standard Library]
- Host: GitHub
- URL: https://github.com/fantasyui-com/oneof
- Owner: fantasyui-com
- License: gpl-3.0
- Created: 2017-05-22T16:29:15.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2026-01-18T15:34:56.000Z (5 months ago)
- Last Synced: 2026-03-31T23:20:50.452Z (3 months ago)
- Topics: library
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# oneof
Select a random item from an array.
## Installation
```sh
npm install oneof
```
## Usage
```js
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