From c9e216398bad113ffbf13b9ea2f97f0125eecb22 Mon Sep 17 00:00:00 2001 From: Orlando Date: Fri, 8 Nov 2024 18:35:02 +0000 Subject: [PATCH] chore: release version 1.10.0 with new features - add removeUndefinedValues helper function - add options.minChunkDuration to chunkedDynamic --- CHANGELOG.md | 7 +++++++ package.json | 2 +- src/helpers/chunkedDynamic.ts | 9 +++++++++ src/helpers/removeUndefinedValues.test.ts | 11 +++++++++++ src/helpers/removeUndefinedValues.ts | 6 ++++++ src/types/Function.ts | 2 -- 6 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/helpers/removeUndefinedValues.test.ts create mode 100644 src/helpers/removeUndefinedValues.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index d356b3a..b35e468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # deverything +## 1.10.0 + +### Minor Changes + +- add removeUndefinedValues +- add options.minChunkDuration + ## 1.9.0 ### Minor Changes diff --git a/package.json b/package.json index 8196b2d..251be5f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/helpers/chunkedDynamic.ts b/src/helpers/chunkedDynamic.ts index 730794e..8a21c1c 100644 --- a/src/helpers/chunkedDynamic.ts +++ b/src/helpers/chunkedDynamic.ts @@ -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 */ @@ -18,11 +19,13 @@ export const chunkedDynamic = async ( { idealChunkDuration, maxChunkSize, + minChunkDuration, minChunkSize, sleepTimeMs, }: { idealChunkDuration?: number; maxChunkSize?: number; + minChunkDuration?: number; minChunkSize?: number; sleepTimeMs?: number; } = {} @@ -51,6 +54,12 @@ export const chunkedDynamic = async ( max: maxChunkSize || 200, }); } + if (minChunkDuration) { + const duration = performance.now() - start; + if (duration < minChunkDuration) { + await sleep(minChunkDuration - duration); + } + } } return chunkResults; diff --git a/src/helpers/removeUndefinedValues.test.ts b/src/helpers/removeUndefinedValues.test.ts new file mode 100644 index 0000000..6d141ef --- /dev/null +++ b/src/helpers/removeUndefinedValues.test.ts @@ -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, + }); +}); diff --git a/src/helpers/removeUndefinedValues.ts b/src/helpers/removeUndefinedValues.ts new file mode 100644 index 0000000..9c71db4 --- /dev/null +++ b/src/helpers/removeUndefinedValues.ts @@ -0,0 +1,6 @@ +import { PlainObject } from "../types/Object"; + +export const removeUndefinedValues = (obj: PlainObject) => + Object.fromEntries( + Object.entries(obj).filter(([_, value]) => value !== undefined) + ); diff --git a/src/types/Function.ts b/src/types/Function.ts index 86e3c8f..52edd13 100644 --- a/src/types/Function.ts +++ b/src/types/Function.ts @@ -1,5 +1,3 @@ export type VoidFn = () => void; -export type AsyncVoidFn = Awaited; - export const noop: VoidFn = () => void 0;