Repository URL to install this package:
|
Version:
1.0.10 ▾
|
/**
* @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046
*/
import { isObjPure } from 'exotic'
import { AnyObj, Without } from './typings'
/**
* Returns a new object with the key/value pairs from `obj`
* that are not in the array `omitKeys`.
*/
export const omit = <Obj = AnyObj, List = string[]>(
obj: Obj,
omitKeys: List
): Without<Obj, List> => {
const result = {}
// @todo should work on sets?
const keys = isObjPure(omitKeys) ? Object.keys(omitKeys) : omitKeys
Object.keys(obj).forEach(key => {
if ((keys as any[]).includes(key) === false) {
result[key] = obj[key]
}
})
return result as any
}