Socket
Book a DemoInstallSign in
Socket

extend-objects-only

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extend-objects-only

Recursively merge objects but copy arrays

1.0.2
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

extend-objects-only

Performs a deep merge on objects but overwrites arrays

Install

Install with npm

npm install extend-objects-only

Usage

import { extendObjectsOnly } from 'extend-objects-only';

// merging objects deeply and overwrite arrays
const base = {
  num: 123,
  str: 'foobar',
  obj: { a: 1, b: 2 },
  arr: [1, 2, 3],
};
const add = {
  root: 'new-value',
  obj: { nested: true },
  arr: [4, 5],
};

extendObjectsOnly(base, add);
console.log(base);
// {
//   num: 123,
//   str: 'foobar',
//   obj: { a: 1, b: 2, nested: true },
//   arr: [4, 5],
//   root: 'new-value
// }

// to avoid modifying the target object, just pass an empty one?
const result = extendObjectsOnly({}, base, add);

Running tests

Install dev dependencies and execute the tests

npm install -d && npm test

Change log

1.0.2

  • Improve signature: accept undefined as parameters (and keep ignoring them)

1.0.1

  • Compare and copy DOM objects as direct values (no-deep)

1.0.0

  • First version

Keywords

deep

FAQs

Package last updated on 15 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.