Socket
Socket
Sign inDemoInstall

@75lb/deep-merge

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @75lb/deep-merge

Deep-merge the values of one object structure into another


Version published
Weekly downloads
296K
decreased by-14.88%
Maintainers
1
Install size
61.7 kB
Created
Weekly downloads
 

Readme

Source

view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI Coverage Status js-standard-style

@75lb/deep-merge

Deep-merge the values of one object structure into another. Similar to Object.assign() except it processes the full depth of the object structure, not only the top level. Useful for merging config.

Synopsis

import deepMerge from '@75lb/deep-merge'

Simple

Typical example merging four objects. Input:

deepMerge(
  { port: 8000, data: { animal: 'cow' } },
  { stack: ['one'] },
  { stack: ['two'], help: true },
  { data: { animal: 'bat', metal: 'iron' } }
)

Result

{
  port: 8000,
  stack: ['two'],
  help: true,
  data: { animal: 'bat', metal: 'iron' }
}

Arrays

Empty arrays are ignored and not merged in. Input:

deepMerge(
  { stack: ['one'] },
  { stack: [] }
)

Result:

{ stack: ['one'] }

However, if the later array contains one or more values the later array will replace the original:

deepMerge(
  { stack: ['one'] },
  { stack: ['two'] }
)

Result:

{ stack: ['two'] }

Load anywhere

This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.

Within a Node.js ECMAScript Module:

import deepMerge from '@75lb/deep-merge'

Within an modern browser ECMAScript Module:

import deepMerge from './node_modules/@75lb/deep-merge/dist/index.mjs'

© 2021 Lloyd Brookes <75pound@gmail.com>.

Tested by test-runner. Documented by jsdoc-to-markdown.

Keywords

FAQs

Last updated on 05 Sep 2021

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc