@augment-vir/common 31.59.3 → 31.61.0
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.
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type MaybePromise, type Tuple } from '@augment-vir/core';
|
|
2
|
+
/**
|
|
3
|
+
* Executes the given callback a given count of times.
|
|
4
|
+
*
|
|
5
|
+
* @category Function
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import {executeCount} from '@augment-vir/common';
|
|
11
|
+
*
|
|
12
|
+
* executeCount(5, (count) => console.log(count)); // will log: 1,2,3,4,5
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
16
|
+
*/
|
|
17
|
+
export declare function executeCount<N extends number, T = void | undefined>(count: N, callback: (currentCount: number, totalCount: number) => T): Extract<T, Promise<any>> extends never ? Tuple<T, N> : Exclude<T, Promise<any>> extends never ? Promise<Tuple<Awaited<T>, N>> : MaybePromise<Tuple<Awaited<T>, N>>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createArray } from '../array/create-array.js';
|
|
2
|
+
/**
|
|
3
|
+
* Executes the given callback a given count of times.
|
|
4
|
+
*
|
|
5
|
+
* @category Function
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import {executeCount} from '@augment-vir/common';
|
|
11
|
+
*
|
|
12
|
+
* executeCount(5, (count) => console.log(count)); // will log: 1,2,3,4,5
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
16
|
+
*/
|
|
17
|
+
export function executeCount(count, callback) {
|
|
18
|
+
return createArray(count, (index) => index + 1).reduce((accum, currentCount) => {
|
|
19
|
+
if (accum instanceof Promise) {
|
|
20
|
+
return accum.then(async (awaitedAccum) => {
|
|
21
|
+
const result = await callback(currentCount, count);
|
|
22
|
+
awaitedAccum.push(result);
|
|
23
|
+
return awaitedAccum;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const result = callback(currentCount, count);
|
|
28
|
+
if (result instanceof Promise) {
|
|
29
|
+
return result.then((awaitedResult) => {
|
|
30
|
+
accum.push(awaitedResult);
|
|
31
|
+
return accum;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
accum.push(result);
|
|
36
|
+
return accum;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
40
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export * from './augments/enum/enum-value-check.js';
|
|
|
19
19
|
export * from './augments/error/combine-errors.js';
|
|
20
20
|
export * from './augments/function/call-asynchronously.js';
|
|
21
21
|
export * from './augments/function/debounce.js';
|
|
22
|
+
export * from './augments/function/execute-count.js';
|
|
22
23
|
export * from './augments/function/execution-duration.js';
|
|
23
24
|
export * from './augments/function/if-truthy.js';
|
|
24
25
|
export * from './augments/function/retry.js';
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export * from './augments/enum/enum-value-check.js';
|
|
|
19
19
|
export * from './augments/error/combine-errors.js';
|
|
20
20
|
export * from './augments/function/call-asynchronously.js';
|
|
21
21
|
export * from './augments/function/debounce.js';
|
|
22
|
+
export * from './augments/function/execute-count.js';
|
|
22
23
|
export * from './augments/function/execution-duration.js';
|
|
23
24
|
export * from './augments/function/if-truthy.js';
|
|
24
25
|
export * from './augments/function/retry.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.61.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"test:web": "virmator --no-deps test web"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^31.
|
|
44
|
-
"@augment-vir/core": "^31.
|
|
43
|
+
"@augment-vir/assert": "^31.61.0",
|
|
44
|
+
"@augment-vir/core": "^31.61.0",
|
|
45
45
|
"@date-vir/duration": "^8.1.0",
|
|
46
46
|
"ansi-styles": "^6.2.3",
|
|
47
47
|
"deepcopy-esm": "^2.1.1",
|