@8ms/helpers 2.2.23 → 2.2.25

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.
Binary file
@@ -0,0 +1 @@
1
+ export declare const getPercent: (numerator: any, divisor: any, dp?: number) => number;
@@ -0,0 +1,11 @@
1
+ import { getSafeDivide } from "./getSafeDivide";
2
+ export const getPercent = (numerator, divisor, dp) => {
3
+ const finalNumerator = Number(numerator);
4
+ const finalDivisor = Number(divisor);
5
+ const finalDp = Number(dp || 1);
6
+ return Number((getSafeDivide({
7
+ defaultValue: 0,
8
+ numerator: finalNumerator,
9
+ divisor: finalDivisor,
10
+ }) * 100).toFixed(finalDp));
11
+ };
package/number/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export * from "./format";
2
2
  export * from "./formatCurrency";
3
3
  export * from "./getDecimal";
4
4
  export * from "./getSafeDivide";
5
+ export * from "./getPercent";
5
6
  export * from "./getNumber";
6
7
  export * from "./getPercentIncrease";
package/number/index.js CHANGED
@@ -2,5 +2,6 @@ export * from "./format";
2
2
  export * from "./formatCurrency";
3
3
  export * from "./getDecimal";
4
4
  export * from "./getSafeDivide";
5
+ export * from "./getPercent";
5
6
  export * from "./getNumber";
6
7
  export * from "./getPercentIncrease";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.2.23",
4
+ "version": "2.2.25",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -2,4 +2,4 @@
2
2
  * Chunk a queue of promises into controlled chunks to prevent overloading.
3
3
  * https://stackoverflow.com/a/53964407
4
4
  */
5
- export declare const promiseChunks: (promises: Promise<any>[], size: number, sleepSeconds?: number) => Promise<any[]>;
5
+ export declare const promiseChunks: (promises: Promise<any>[], size: number, sleepSeconds?: number, callbackFunction?: Function) => Promise<any[]>;
@@ -4,13 +4,17 @@ import { sleep } from "./sleep";
4
4
  * Chunk a queue of promises into controlled chunks to prevent overloading.
5
5
  * https://stackoverflow.com/a/53964407
6
6
  */
7
- export const promiseChunks = async (promises, size, sleepSeconds = 0) => {
7
+ export const promiseChunks = async (promises, size, sleepSeconds = 0, callbackFunction) => {
8
8
  const batches = chunk(promises, size);
9
9
  let results = [];
10
10
  while (batches.length) {
11
11
  const batch = batches.shift();
12
12
  const result = await Promise.all(batch);
13
13
  results.push(result);
14
+ // If there is a process to do with each chunk
15
+ if (callbackFunction) {
16
+ await callbackFunction(result);
17
+ }
14
18
  await sleep(sleepSeconds);
15
19
  }
16
20
  return flatten(results);