UNPKG

diginext-utils

Version:
28 lines 775 B
/** * Creates a new object excluding the specified keys from the source object. * * @template T - The type of the source object * @template K - The keys to omit * @param obj - The source object * @param keys - The keys to exclude from the new object * @returns A new object without the specified keys * * @example * ```ts * const obj = { a: 1, b: 2, c: 3, d: 4 }; * omit(obj, ['b', 'd']); // { a: 1, c: 3 } * ``` */ export function omit(obj, keys) { if (typeof obj !== "object" || obj === null) { return {}; } const keySet = new Set(keys); return Object.keys(obj).reduce((result, key) => { if (!keySet.has(key)) { result[key] = obj[key]; } return result; }, {}); } //# sourceMappingURL=omit.js.map