Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

random-item

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-item - npm Package Compare versions

Comparing version
2.0.0
to
3.0.0
+2
-5
index.d.ts
/**
Get a random item from an [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol).
Get a random item from an array.

@@ -10,9 +10,6 @@ @example

//=> '🦄'
randomItem(new Set(['🐴', '🦄', '🌈']);
//=> '🌈'
```
*/
declare function randomItem<T>(input: Iterable<T>): T;
declare function randomItem<T>(input: readonly T[]): T;
export = randomItem;
'use strict';
module.exports = iterable => {
if (!Array.isArray(iterable) && typeof iterable[Symbol.iterator] !== 'function') {
throw new TypeError('Expected an array or an iterable');
module.exports = array => {
if (!Array.isArray(array)) {
throw new TypeError('Expected an array');
}
const array = Array.isArray(iterable) ? iterable : [...iterable];
return array[Math.floor(Math.random() * array.length)];
};
{
"name": "random-item",
"version": "2.0.0",
"description": "Get a random item from an Iterable",
"version": "3.0.0",
"description": "Get a random item from an array",
"license": "MIT",

@@ -27,3 +27,2 @@ "repository": "sindresorhus/random-item",

"array",
"iterable",
"item",

@@ -30,0 +29,0 @@ "element",

# random-item [![Build Status](https://travis-ci.org/sindresorhus/random-item.svg?branch=master)](https://travis-ci.org/sindresorhus/random-item)
> Get a random item from an [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol)
> Get a random item from an array

@@ -20,5 +20,2 @@

//=> '🦄'
randomItem(new Set(['🐴', '🦄', '🌈']);
//=> '🌈'
```

@@ -25,0 +22,0 @@