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
3.1.0
to
4.0.0
+4
-4
index.d.ts

@@ -7,3 +7,3 @@ declare const randomItem: {

```
import randomItem = require('random-item');
import randomItem from 'random-item';

@@ -23,3 +23,3 @@ randomItem(['🐴', '🦄', '🌈']);

```
import randomItem = require('random-item');
import randomItem from 'random-item';

@@ -31,4 +31,4 @@ randomItem.multiple(['🐴', '🦄', '🌈'], 2);

multiple<T>(input: readonly T[], count: number): T[];
}
};
export = randomItem;
export default randomItem;

@@ -1,4 +0,2 @@

'use strict';
module.exports = array => {
export default function randomItem(array) {
if (!Array.isArray(array)) {

@@ -9,5 +7,5 @@ throw new TypeError('Expected an array');

return array[Math.floor(Math.random() * array.length)];
};
}
module.exports.multiple = (array, count) => {
randomItem.multiple = (array, count) => {
if (!Number.isInteger(count) && count >= 0) {

@@ -17,3 +15,3 @@ throw new TypeError('Expected a non-negative integer');

return [...new Array(count)].map(() => module.exports(array));
return [...Array.from({length: count})].map(() => randomItem(array));
};
{
"name": "random-item",
"version": "3.1.0",
"version": "4.0.0",
"description": "Get a random item from an array",

@@ -13,4 +13,6 @@ "license": "MIT",

},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},

@@ -35,7 +37,7 @@ "scripts": {

"devDependencies": {
"ava": "^1.4.1",
"stable-fn": "^2.0.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"stable-fn": "^3.0.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}

@@ -1,2 +0,2 @@

# random-item [![Build Status](https://travis-ci.com/sindresorhus/random-item.svg?branch=master)](https://travis-ci.com/github/sindresorhus/random-item)
# random-item

@@ -14,3 +14,3 @@ > Get a random item from an array

```js
const randomItem = require('random-item');
import randomItem from 'random-item';

@@ -17,0 +17,0 @@ randomItem(['🐴', '🦄', '🌈']);