Skip to main content

Objects

Plain-object helpers — pick, omit, deepMerge and a plain-object guard. pick and omit return shallow copies, and deepMerge recurses only into plain objects: arrays and class instances are replaced wholesale rather than merged.

deepClone was removed in 4.0; call the structuredClone global directly.

Example

import { deepMerge, omit, pick } from '@rtorcato/js-common/objects'

// Layer environment config over defaults.
deepMerge({ retries: 3, db: { host: 'localhost', port: 5432 } }, { db: { host: 'prod.db' } })
// { retries: 3, db: { host: 'prod.db', port: 5432 } }

omit(user, ['passwordHash']) // safe to serialise
pick(user, ['id', 'email']) // exactly what the client needs

deepMerge recurses into plain objects only: arrays and class instances are replaced wholesale, never concatenated.

Import

import { deepMerge, isPlainObject, omit } from '@rtorcato/js-common/objects'

Exports

NameSummary
deepMergeDeeply merges two objects.
isPlainObjectReturns true if the value is a plain object (not null, not array, not function).
omitReturns a shallow copy of an object with the given keys omitted.
pickReturns a shallow copy of an object with only the given keys.

See also

  • arrays — chunk, unique, groupBy and other array helpers
  • maps — merge, invert and convert Maps
  • json — safe parse/stringify and JSON deep clone