radashi 12.3.0 → 12.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/radashi.cjs +8 -5
- package/dist/radashi.d.cts +23 -2
- package/dist/radashi.d.ts +23 -2
- package/dist/radashi.js +8 -5
- package/package.json +2 -2
package/dist/radashi.cjs
CHANGED
|
@@ -464,6 +464,9 @@ async function map(array, asyncMapFunc) {
|
|
|
464
464
|
|
|
465
465
|
// src/async/parallel.ts
|
|
466
466
|
async function parallel(options, array, func) {
|
|
467
|
+
if (!array.length) {
|
|
468
|
+
return [];
|
|
469
|
+
}
|
|
467
470
|
const work = array.map((item, index) => ({
|
|
468
471
|
index,
|
|
469
472
|
item
|
|
@@ -1314,11 +1317,11 @@ function random(min2, max2) {
|
|
|
1314
1317
|
// src/random/shuffle.ts
|
|
1315
1318
|
function shuffle(array, random2 = random) {
|
|
1316
1319
|
const newArray = array.slice();
|
|
1317
|
-
for (let idx =
|
|
1318
|
-
randomIdx = random2(0,
|
|
1319
|
-
item = newArray[
|
|
1320
|
-
newArray[
|
|
1321
|
-
newArray[
|
|
1320
|
+
for (let idx = array.length - 1, randomIdx, item; idx > 0; idx--) {
|
|
1321
|
+
randomIdx = random2(0, idx);
|
|
1322
|
+
item = newArray[idx];
|
|
1323
|
+
newArray[idx] = newArray[randomIdx];
|
|
1324
|
+
newArray[randomIdx] = item;
|
|
1322
1325
|
}
|
|
1323
1326
|
return newArray;
|
|
1324
1327
|
}
|
package/dist/radashi.d.cts
CHANGED
|
@@ -2112,7 +2112,9 @@ declare function draw<const T extends readonly any[]>(array: T): T extends reado
|
|
|
2112
2112
|
declare function random(min: number, max: number): number;
|
|
2113
2113
|
|
|
2114
2114
|
/**
|
|
2115
|
-
*
|
|
2115
|
+
* Create a new array with the items of the given array but in a random order.
|
|
2116
|
+
* The randomization is done using the [Fisher-Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle),
|
|
2117
|
+
* which is mathematically proven to be unbiased (i.e. all permutations are equally likely).
|
|
2116
2118
|
*
|
|
2117
2119
|
* @see https://radashi.js.org/reference/random/shuffle
|
|
2118
2120
|
* @example
|
|
@@ -2125,7 +2127,26 @@ declare function random(min: number, max: number): number;
|
|
|
2125
2127
|
* ```
|
|
2126
2128
|
* @version 12.1.0
|
|
2127
2129
|
*/
|
|
2128
|
-
declare function shuffle<T>(
|
|
2130
|
+
declare function shuffle<T>(
|
|
2131
|
+
/**
|
|
2132
|
+
* The array to shuffle.
|
|
2133
|
+
*/
|
|
2134
|
+
array: readonly T[],
|
|
2135
|
+
/**
|
|
2136
|
+
* You can provide a custom random function to make the shuffle more or less
|
|
2137
|
+
* random. The custom random function takes minimum and maximum values and
|
|
2138
|
+
* returns a random number between them.
|
|
2139
|
+
*
|
|
2140
|
+
* @default _.random
|
|
2141
|
+
* @example
|
|
2142
|
+
*
|
|
2143
|
+
* ```ts
|
|
2144
|
+
* const array = [1, 2, 3, 4, 5]
|
|
2145
|
+
* const customRandom = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min
|
|
2146
|
+
* _.shuffle(array, customRandom)
|
|
2147
|
+
* ```
|
|
2148
|
+
*/
|
|
2149
|
+
random?: (min: number, max: number) => number): T[];
|
|
2129
2150
|
|
|
2130
2151
|
/**
|
|
2131
2152
|
* Generate a random string of a given length.
|
package/dist/radashi.d.ts
CHANGED
|
@@ -2112,7 +2112,9 @@ declare function draw<const T extends readonly any[]>(array: T): T extends reado
|
|
|
2112
2112
|
declare function random(min: number, max: number): number;
|
|
2113
2113
|
|
|
2114
2114
|
/**
|
|
2115
|
-
*
|
|
2115
|
+
* Create a new array with the items of the given array but in a random order.
|
|
2116
|
+
* The randomization is done using the [Fisher-Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle),
|
|
2117
|
+
* which is mathematically proven to be unbiased (i.e. all permutations are equally likely).
|
|
2116
2118
|
*
|
|
2117
2119
|
* @see https://radashi.js.org/reference/random/shuffle
|
|
2118
2120
|
* @example
|
|
@@ -2125,7 +2127,26 @@ declare function random(min: number, max: number): number;
|
|
|
2125
2127
|
* ```
|
|
2126
2128
|
* @version 12.1.0
|
|
2127
2129
|
*/
|
|
2128
|
-
declare function shuffle<T>(
|
|
2130
|
+
declare function shuffle<T>(
|
|
2131
|
+
/**
|
|
2132
|
+
* The array to shuffle.
|
|
2133
|
+
*/
|
|
2134
|
+
array: readonly T[],
|
|
2135
|
+
/**
|
|
2136
|
+
* You can provide a custom random function to make the shuffle more or less
|
|
2137
|
+
* random. The custom random function takes minimum and maximum values and
|
|
2138
|
+
* returns a random number between them.
|
|
2139
|
+
*
|
|
2140
|
+
* @default _.random
|
|
2141
|
+
* @example
|
|
2142
|
+
*
|
|
2143
|
+
* ```ts
|
|
2144
|
+
* const array = [1, 2, 3, 4, 5]
|
|
2145
|
+
* const customRandom = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min
|
|
2146
|
+
* _.shuffle(array, customRandom)
|
|
2147
|
+
* ```
|
|
2148
|
+
*/
|
|
2149
|
+
random?: (min: number, max: number) => number): T[];
|
|
2129
2150
|
|
|
2130
2151
|
/**
|
|
2131
2152
|
* Generate a random string of a given length.
|
package/dist/radashi.js
CHANGED
|
@@ -462,6 +462,9 @@ async function map(array, asyncMapFunc) {
|
|
|
462
462
|
|
|
463
463
|
// src/async/parallel.ts
|
|
464
464
|
async function parallel(options, array, func) {
|
|
465
|
+
if (!array.length) {
|
|
466
|
+
return [];
|
|
467
|
+
}
|
|
465
468
|
const work = array.map((item, index) => ({
|
|
466
469
|
index,
|
|
467
470
|
item
|
|
@@ -1312,11 +1315,11 @@ function random(min2, max2) {
|
|
|
1312
1315
|
// src/random/shuffle.ts
|
|
1313
1316
|
function shuffle(array, random2 = random) {
|
|
1314
1317
|
const newArray = array.slice();
|
|
1315
|
-
for (let idx =
|
|
1316
|
-
randomIdx = random2(0,
|
|
1317
|
-
item = newArray[
|
|
1318
|
-
newArray[
|
|
1319
|
-
newArray[
|
|
1318
|
+
for (let idx = array.length - 1, randomIdx, item; idx > 0; idx--) {
|
|
1319
|
+
randomIdx = random2(0, idx);
|
|
1320
|
+
item = newArray[idx];
|
|
1321
|
+
newArray[idx] = newArray[randomIdx];
|
|
1322
|
+
newArray[randomIdx] = item;
|
|
1320
1323
|
}
|
|
1321
1324
|
return newArray;
|
|
1322
1325
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "radashi",
|
|
3
|
-
"version": "12.3.
|
|
3
|
+
"version": "12.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The modern, community-first TypeScript toolkit with all of the fast, readable, and minimal utility functions you need. Type-safe, dependency-free, tree-shakeable, fully tested.",
|
|
6
6
|
"repository": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"Ray Epps"
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"packageManager": "pnpm@9.
|
|
15
|
+
"packageManager": "pnpm@9.15.0",
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=16.0.0"
|
|
18
18
|
},
|