A 'swiss army knife' solution for working with JavaScript objects and arrays — deep merging, cloning, omitting keys/nullish values, and a set of dependency-free type guards, all in one small, fully-typed package.
merge— deep or shallow merging of objects/arrays, multiple sources, array merge strategies (append/unique), property-descriptor cloning, custom filters, and built-in prototype-pollution protection.clone/deepClone— copy objects and arrays (including class instances withdeepClone), with full support for top-level arrays as the value being cloned.omit/omitUndefined/omitNull/omitNullish— drop specific keys ornull/undefinedvalues, shallow or deep, from objects or arrays.- Type guards —
isObject,isPlainObject,isBuiltIn,isConstructor,isIterable,isAsyncIterable— none of them throw on unexpected input. updateErrorMessage— change anError's message and keep its stack trace header consistent, without losing the original stack frames.- Zero runtime dependencies, ESM-only, written in TypeScript.
import { merge, clone, deepClone, omit, omitUndefined } from '@jsopen/objects';
// Deep merge
merge({ a: 1 }, { b: 2 }, { deep: true });
// => { a: 1, b: 2 }
// Clone (objects or top-level arrays, deeply by default)
clone({ a: 1, b: { c: 2 } });
clone([1, 2, { x: 1 }]);
// Deep-clone including class instances
class Point { constructor(public x: number, public y: number) {} }
deepClone({ point: new Point(1, 2) });
// Exclude keys / nullish values
omit({ a: 1, b: 2, c: 3 }, ['b']); // => { a: 1, c: 3 }
omitUndefined({ a: 1, b: undefined }, true); // => { a: 1 }See the Full API Reference for every function, option, and edge case, or jump to a focused guide:
A powerful, flexible tool for merging objects, arrays, and their nested properties.
Easy ways to create shallow or deep copies of objects and arrays.
Easily exclude specific keys or nullish values from objects.
Update an Error object's message while correctly refreshing the stack trace.
Various utility functions for object and type checking.
$ npm install @jsopen/objects
- node
>= 16;