mongocat
Version:
✨ Mongocat 😺 is easy to use, configuration based Denormalization mongoose plugin for read heavy applications. Mongocat reduces write complexity too.
22 lines (21 loc) • 565 B
text/typescript
export class ObjectBuilder {
static filterObject(
obj: Record<string, any>,
condition: (v: any, key: string) => boolean,
objCondition: (v: any) => any = Object
): Record<string, any> {
return Object.entries(obj)
.filter(([key, value]) => condition(value, key))
.reduce(
(acc, [key, value]) => ({
...acc,
[key]: Array.isArray(value)
? value
: value === objCondition(value)
? this.filterObject(value, condition)
: value,
}),
{}
);
}
}