Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 3x 5x 3x 1x 1x 1x 1x 1x 1x 1x | /**
* omit keys and reserve others in the object
*
* @param obj the destination object
* @param keys the keys to omit
* @returns object
*
* {@link https://lodash.com/docs#omit}
*/
export function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {
const result = { ...obj }
keys.forEach(key => delete result[key])
return result
}
Eif (import.meta.vitest) {
const { test, expect } = import.meta.vitest
test('pick', () => {
const obj = {
a: 1,
b: '2',
c: false,
d: null,
}
expect(omit(obj, ['a'])).toEqual({
b: '2',
c: false,
d: null,
})
expect(omit(obj, ['b', 'd'])).toEqual({
a: 1,
c: false,
})
expect(omit(obj, ['d', 'a'])).toEqual({
b: '2',
c: false,
})
})
}
|