All files omit.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 3/3
100% Lines 8/8

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 428x                                                 8x 2x             2x 8x 8x 4x   8x      
import { purry } from './purry';
 
/**
 * Returns a partial copy of an object omitting the keys specified.
 * @param object the object
 * @param names the property names
 * @signature
 *    P.omit(obj, names);
 * @signature
 *    P.omit(names)(obj);
 * @example
 *    P.omit({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'd']) // => { b: 2, c: 3 }
 *
 *    P.pipe({ a: 1, b: 2, c: 3, d: 4 }, P.omit(['a', 'd'])) // => { b: 2, c: 3 }
 * @category Object, Pipe
 */
export function omit<T extends {}, K extends keyof T>(
  object: T,
  names: readonly K[]
): Omit<T, K>;
 
export function omit<T extends {}, K extends keyof T>(
  names: readonly K[]
): (object: T) => Omit<T, K>;
 
export function omit() {
  return purry(_omit, arguments);
}
 
function _omit<T extends {}, K extends keyof T>(
  object: T,
  names: K[]
): Omit<T, K> {
  const set = new Set(names as string[]);
  return Object.entries(object).reduce((acc, [name, value]) => {
    if (!set.has(name)) {
      acc[name] = value;
    }
    return acc;
  }, {} as any) as Omit<T, K>;
}