UNPKG

apphouse

Version:

Component library for React that uses observable state management and theme-able components.

25 lines (23 loc) 695 B
import { omit } from './omit'; /** * Recurse through an object and omit all keys specified in keysToOmit * @param obj object to omit keys from * @param keysToOmit the keys to omit * @returns a new object with all keys from the original object * except the ones specified in keysToOmit */ export function omitAll<T>(obj: T, keysToOmit: string[]) { let newObj = { ...obj }; for (const key in obj) { if (typeof obj[key] === 'object' && obj[key] !== null) { if (keysToOmit.includes(key)) { delete newObj[key]; continue; } newObj[key] = omitAll(newObj[key], keysToOmit); } else { newObj = omit(obj, keysToOmit); } } return newObj; }