Skip to content

Commit

Permalink
chore: release version 1.10.0 with new features
Browse files Browse the repository at this point in the history
- add removeUndefinedValues helper function
- add options.minChunkDuration to chunkedDynamic
  • Loading branch information
ogroppo committed Nov 8, 2024
1 parent b7a1fe8 commit c9e2163
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# deverything

## 1.10.0

### Minor Changes

- add removeUndefinedValues
- add options.minChunkDuration

## 1.9.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deverything",
"version": "1.9.0",
"version": "1.10.0",
"description": "Everything you need for Dev",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
9 changes: 9 additions & 0 deletions src/helpers/chunkedDynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { sleep } from "./sleep";
* @param fn - Function to run on each chunk
* @param options.idealChunkDuration - Ideal time to process each chunk, the chunk size will adjust to meet this duration
* @param options.maxChunkSize - Maximum chunk size (default 200)
* @param options.minChunkDuration - Minimum time to process each chunk (useful for rate limiting)
* @param options.minChunkSize - Minimum chunk size (default 1)
* @param options.sleepTimeMs - Time to sleep between each chunk
*/
Expand All @@ -18,11 +19,13 @@ export const chunkedDynamic = async <T>(
{
idealChunkDuration,
maxChunkSize,
minChunkDuration,
minChunkSize,
sleepTimeMs,
}: {
idealChunkDuration?: number;
maxChunkSize?: number;
minChunkDuration?: number;
minChunkSize?: number;
sleepTimeMs?: number;
} = {}
Expand Down Expand Up @@ -51,6 +54,12 @@ export const chunkedDynamic = async <T>(
max: maxChunkSize || 200,
});
}
if (minChunkDuration) {
const duration = performance.now() - start;
if (duration < minChunkDuration) {
await sleep(minChunkDuration - duration);
}
}
}

return chunkResults;
Expand Down
11 changes: 11 additions & 0 deletions src/helpers/removeUndefinedValues.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from "@jest/globals";
import { removeUndefinedValues } from "./removeUndefinedValues";

test("removeUndefinedValues", async () => {
expect(removeUndefinedValues({})).toEqual({});
expect(removeUndefinedValues({ a: undefined })).toEqual({});
expect(removeUndefinedValues({ b: 1, a: undefined, c: null })).toEqual({
b: 1,
c: null,
});
});
6 changes: 6 additions & 0 deletions src/helpers/removeUndefinedValues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PlainObject } from "../types/Object";

export const removeUndefinedValues = (obj: PlainObject) =>
Object.fromEntries(
Object.entries(obj).filter(([_, value]) => value !== undefined)
);
2 changes: 0 additions & 2 deletions src/types/Function.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export type VoidFn = () => void;

export type AsyncVoidFn = Awaited<VoidFn>;

export const noop: VoidFn = () => void 0;

0 comments on commit c9e2163

Please sign in to comment.