Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

merge-deep

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merge-deep

Recursively merge values in a javascript object.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1M
decreased by-16.15%
Maintainers
1
Weekly downloads
 
Created

What is merge-deep?

The merge-deep npm package is a utility for deeply merging objects in JavaScript. It is useful for combining configurations, options, or states in a way that nested properties are not lost but instead merged together.

What are merge-deep's main functionalities?

Deep merging of objects

This feature allows you to deeply merge multiple objects into one. It recursively merges own and inherited enumerable properties of source objects into the destination object, skipping source properties that resolve to `undefined`.

{"const mergeDeep = require('merge-deep');\nconst object1 = { a: { b: 1 } };\nconst object2 = { a: { c: 2 }, d: 3 };\nconst result = mergeDeep(object1, object2);\nconsole.log(result); // Output: { a: { b: 1, c: 2 }, d: 3 }"}

Merging with array concatenation

Merge-deep can also merge arrays by concatenating them. This is useful when you want to combine arrays from different objects without losing any elements.

{"const mergeDeep = require('merge-deep');\nconst object1 = { a: [1, 2], b: 'one' };\nconst object2 = { a: [3, 4], b: 'two' };\nconst result = mergeDeep(object1, object2);\nconsole.log(result); // Output: { a: [1, 2, 3, 4], b: 'two' }"}

Customizing merge behavior

Users can define a custom merge function to control how merging is done. This is particularly useful when the default behavior of merge-deep does not suit the specific needs of your application.

{"const mergeDeep = require('merge-deep');\nfunction customMerge(a, b) {\n  return Array.isArray(a) ? a.concat(b) : undefined;\n}\nconst object1 = { a: [1], b: [2] };\nconst object2 = { a: [3], b: [4] };\nconst result = mergeDeep({ customMerge }, object1, object2);\nconsole.log(result); // Output: { a: [1, 3], b: [2, 4] }"}

Other packages similar to merge-deep

Keywords

FAQs

Package last updated on 25 Feb 2015

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

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc