radashi 12.3.2 → 12.3.4

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 CHANGED
@@ -521,17 +521,23 @@ async function parallel(options, array, func) {
521
521
  }
522
522
 
523
523
  // src/async/reduce.ts
524
- async function reduce(array, asyncReducer, initValue) {
525
- const initProvided = initValue !== void 0;
526
- if (!initProvided && (array == null ? void 0 : array.length) < 1) {
527
- throw new Error("Cannot reduce empty array with no init value");
524
+ async function reduce(array, reducer, initialValue) {
525
+ if (!array) {
526
+ array = [];
527
+ }
528
+ const indices = array.keys();
529
+ let acc = initialValue;
530
+ if (acc === void 0 && arguments.length < 3) {
531
+ if (!array.length) {
532
+ throw new TypeError("Reduce of empty array with no initial value");
533
+ }
534
+ acc = array[0];
535
+ indices.next();
528
536
  }
529
- const iter = initProvided ? array : array.slice(1);
530
- let value = initProvided ? initValue : array[0];
531
- for (const [i, item] of iter.entries()) {
532
- value = await asyncReducer(value, item, i);
537
+ for (const index of indices) {
538
+ acc = await reducer(acc, array[index], index);
533
539
  }
534
- return value;
540
+ return acc;
535
541
  }
536
542
 
537
543
  // src/async/retry.ts
@@ -677,7 +677,7 @@ declare function guard<TFunction extends () => any>(func: TFunction, shouldGuard
677
677
  * ```
678
678
  * @version 12.1.0
679
679
  */
680
- declare function map<T, K>(array: readonly T[], asyncMapFunc: (item: T, index: number) => Promise<K>): Promise<K[]>;
680
+ declare function map<T, K>(array: readonly T[], asyncMapFunc: (item: T, index: number) => PromiseLike<K>): Promise<K[]>;
681
681
 
682
682
  type AbortSignal$1 = {
683
683
  readonly aborted: boolean;
@@ -738,7 +738,8 @@ declare function parallel<T, K>(options: ParallelOptions | number, array: readon
738
738
  * ```
739
739
  * @version 12.1.0
740
740
  */
741
- declare function reduce<T, K>(array: readonly T[], asyncReducer: (acc: K, item: T, index: number) => Promise<K>, initValue?: K): Promise<K>;
741
+ declare function reduce<T, K>(array: readonly T[], reducer: (acc: K, item: T, index: number) => Promise<K>, initialValue: K): Promise<K>;
742
+ declare function reduce<T, K>(array: readonly T[], reducer: (acc: K, item: T, index: number) => Promise<K>): Promise<K>;
742
743
 
743
744
  type AbortSignal = {
744
745
  throwIfAborted(): void;
@@ -1468,7 +1469,7 @@ declare function range<T = number>(startOrLength: number, end?: number, valueOrM
1468
1469
  * @example
1469
1470
  * ```ts
1470
1471
  * round(123.456)
1471
- * // => 123.5
1472
+ * // => 123
1472
1473
  *
1473
1474
  * round(1234.56, -2)
1474
1475
  * // => 1200
package/dist/radashi.d.ts CHANGED
@@ -677,7 +677,7 @@ declare function guard<TFunction extends () => any>(func: TFunction, shouldGuard
677
677
  * ```
678
678
  * @version 12.1.0
679
679
  */
680
- declare function map<T, K>(array: readonly T[], asyncMapFunc: (item: T, index: number) => Promise<K>): Promise<K[]>;
680
+ declare function map<T, K>(array: readonly T[], asyncMapFunc: (item: T, index: number) => PromiseLike<K>): Promise<K[]>;
681
681
 
682
682
  type AbortSignal$1 = {
683
683
  readonly aborted: boolean;
@@ -738,7 +738,8 @@ declare function parallel<T, K>(options: ParallelOptions | number, array: readon
738
738
  * ```
739
739
  * @version 12.1.0
740
740
  */
741
- declare function reduce<T, K>(array: readonly T[], asyncReducer: (acc: K, item: T, index: number) => Promise<K>, initValue?: K): Promise<K>;
741
+ declare function reduce<T, K>(array: readonly T[], reducer: (acc: K, item: T, index: number) => Promise<K>, initialValue: K): Promise<K>;
742
+ declare function reduce<T, K>(array: readonly T[], reducer: (acc: K, item: T, index: number) => Promise<K>): Promise<K>;
742
743
 
743
744
  type AbortSignal = {
744
745
  throwIfAborted(): void;
@@ -1468,7 +1469,7 @@ declare function range<T = number>(startOrLength: number, end?: number, valueOrM
1468
1469
  * @example
1469
1470
  * ```ts
1470
1471
  * round(123.456)
1471
- * // => 123.5
1472
+ * // => 123
1472
1473
  *
1473
1474
  * round(1234.56, -2)
1474
1475
  * // => 1200
package/dist/radashi.js CHANGED
@@ -519,17 +519,23 @@ async function parallel(options, array, func) {
519
519
  }
520
520
 
521
521
  // src/async/reduce.ts
522
- async function reduce(array, asyncReducer, initValue) {
523
- const initProvided = initValue !== void 0;
524
- if (!initProvided && (array == null ? void 0 : array.length) < 1) {
525
- throw new Error("Cannot reduce empty array with no init value");
522
+ async function reduce(array, reducer, initialValue) {
523
+ if (!array) {
524
+ array = [];
525
+ }
526
+ const indices = array.keys();
527
+ let acc = initialValue;
528
+ if (acc === void 0 && arguments.length < 3) {
529
+ if (!array.length) {
530
+ throw new TypeError("Reduce of empty array with no initial value");
531
+ }
532
+ acc = array[0];
533
+ indices.next();
526
534
  }
527
- const iter = initProvided ? array : array.slice(1);
528
- let value = initProvided ? initValue : array[0];
529
- for (const [i, item] of iter.entries()) {
530
- value = await asyncReducer(value, item, i);
535
+ for (const index of indices) {
536
+ acc = await reducer(acc, array[index], index);
531
537
  }
532
- return value;
538
+ return acc;
533
539
  }
534
540
 
535
541
  // src/async/retry.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "radashi",
3
- "version": "12.3.2",
3
+ "version": "12.3.4",
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": {