random-item
Advanced tools
+4
-4
@@ -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; |
+4
-6
@@ -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)); | ||
| }; |
+8
-6
| { | ||
| "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" | ||
| } | ||
| } |
+2
-2
@@ -1,2 +0,2 @@ | ||
| # random-item [](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(['🐴', '🦄', '🌈']); |
Yes
NaN3905
-2.45%36
-2.7%