unique-random-array
Advanced tools
Comparing version 3.0.0 to 4.0.0
@@ -0,1 +1,4 @@ | ||
type EmptyArray = readonly never[] & {length: 0}; | ||
type NonEmptyArray<T> = readonly [T, ...T[]] | readonly [...T[], T] | readonly [T, ...T[], T]; | ||
/** | ||
@@ -16,2 +19,4 @@ Get consecutively unique elements from an array. | ||
*/ | ||
export default function uniqueRandomArray<T>(array: readonly T[]): () => T; | ||
export default function uniqueRandomArray<T>(array: EmptyArray): () => undefined; | ||
export default function uniqueRandomArray<T>(array: NonEmptyArray<T>): () => T; | ||
export default function uniqueRandomArray<T>(array: readonly T[]): () => T | undefined; |
@@ -1,6 +0,6 @@ | ||
import uniqueRandom from 'unique-random'; | ||
import {consecutiveUniqueRandom} from 'unique-random'; | ||
export default function uniqueRandomArray(array) { | ||
const random = uniqueRandom(0, array.length - 1); | ||
const random = consecutiveUniqueRandom(0, array.length - 1); | ||
return () => array[random()]; | ||
} |
{ | ||
"name": "unique-random-array", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Get consecutively unique elements from an array", | ||
@@ -14,5 +14,9 @@ "license": "MIT", | ||
"type": "module", | ||
"exports": "./index.js", | ||
"exports": { | ||
"types": "./index.d.ts", | ||
"default": "./index.js" | ||
}, | ||
"sideEffects": false, | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=18" | ||
}, | ||
@@ -38,9 +42,9 @@ "scripts": { | ||
"dependencies": { | ||
"unique-random": "^3.0.0" | ||
"unique-random": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^3.15.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
"ava": "^6.1.3", | ||
"tsd": "^0.31.0", | ||
"xo": "^0.58.0" | ||
} | ||
} |
@@ -9,5 +9,5 @@ # unique-random-array | ||
```sh | ||
npm install unique-random-array | ||
``` | ||
$ npm install unique-random-array | ||
``` | ||
@@ -29,3 +29,3 @@ ## Usage | ||
Returns a function, that when called, will return a random element that's never the same as the previous. | ||
Returns a function, that when called, will return a random element that's never the same as the previous, or `undefined` if the array is empty. | ||
@@ -32,0 +32,0 @@ #### array |
4312
21
+ Addedunique-random@4.0.0(transitive)
- Removedunique-random@3.0.0(transitive)
Updatedunique-random@^4.0.0