Skip to content

Commit

Permalink
✨ feat(core): add omitKeysWithDelete utility for extra choice
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan-Zayne committed Dec 1, 2024
1 parent d31f324 commit f674f70
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/toolkit/src/core/omitKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,23 @@ export const omitKeysWithFilter = <

return updatedObject as OmitKeys<TOmitArray[number], TObject>;
};

export const omitKeysWithDelete = <
TObject extends AnyObject,
const TOmitArray extends Array<keyof TObject>,
>(
initialObject: TObject,
keysToOmit: TOmitArray
) => {
const keysToOmitSet = new Set(keysToOmit);

const updatedObject = { ...initialObject };

for (const key of Object.keys(updatedObject)) {
if (keysToOmitSet.has(key)) {
Reflect.deleteProperty(updatedObject, key);
}
}

return updatedObject as OmitKeys<TOmitArray[number], TObject>;
};

0 comments on commit f674f70

Please sign in to comment.