Skip to content

Instantly share code, notes, and snippets.

@bytemain
Created May 25, 2022 06:04
Show Gist options
  • Save bytemain/fd2e4268811976de9442217523c48810 to your computer and use it in GitHub Desktop.
Save bytemain/fd2e4268811976de9442217523c48810 to your computer and use it in GitHub Desktop.
omitDeep
function omitDeep(collection, excludeKeys) {
function omitFn(value) {
if (value && typeof value === 'object') {
excludeKeys.forEach((key) => {
delete value[key];
});
}
}
return _.cloneDeepWith(collection, omitFn);
}
import _ from "lodash";
export function omitDeep(
collection: Record<string, any>,
excludeKeys: string[],
cb: (k: string, v: any) => boolean
) {
function omitFn(value) {
if (value && typeof value === "object") {
excludeKeys.forEach((key) => {
if (cb(key, value[key])) {
delete value[key];
}
});
}
}
return _.cloneDeepWith(collection, omitFn);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment