# deeper-merge

> A small tool used to recursively merge nested javascript objects. The primary function of this module is `merge(a,b)`. This function takes two objects, `a` and `b`, and returns a new object with merged properties from both parameters. This module was desi

Latest version **1.0.0** (published 2022-06-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install deeper-merge
pnpm add deeper-merge
yarn add deeper-merge
bun add deeper-merge
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-06-28 |
| First published | 2020-02-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | John L. Carveth |
| Maintainers | jlcarveth |

## Links

- npm: https://www.npmjs.com/package/deeper-merge
- Repository: https://github.com/jlcarveth/deep-merge
- Homepage: https://github.com/jlcarveth/deep-merge#readme
- Issues: https://github.com/jlcarveth/deep-merge/issues
- npm.io page: https://npm.io/package/deeper-merge

## Recent versions

- 1.0.0 (latest) — 2022-06-28
- 0.1.2 — 2020-02-04
- 0.1.1 — 2020-02-04
- 0.1.0 — 2020-02-04

## README

# deeper-merge

A small tool used to recursively merge nested javascript objects. The primary function of this module is `merge(a,b)`. This function takes two objects, `a` and `b`, and returns a new object with merged properties from both parameters. This module was designed to solve the problem of merging an existing user-modified configuration object with a base configuration object.   
  
The base object can have new properties added as the software is developped, and those new properties will be persisted to the existing user configuration. If there is a field that already exists in the user configuration, it is preserved.

# Installation
    
    npm install deeper-merge --save

# Example

    const deepmerge = require('deeper-merge')

    const baseObj   = {...}
    const secondObj = {...}

    const merged = deepmerge.merge(baseObj,secondObj)

An example merging two configuration files:

    const baseConfig = {
        "port" : 8080,
        "roles": {
            "admin": {"roles" : "*"},
            "user": {"roles" : "comment"}},
        "commentsPerPost" : 10
    }

    const userConfig = {
        "port" : 80,
        "roles": {
            "admin": {"roles" : "*"},
            "user": {"roles" : "comment"},
            "author" : {"roles" : "comment,writePost"}}
    }

    const expected = {
        "port" : 80,
        "roles": {
            "admin": {"roles" : "*"},
            "user": {"roles" : "comment"},
            "author" : {"roles" : "comment,writePost"}},
        "commentsPerPost" : 10
    }

In the above example, the properties that were modified by the user were preserved, and new properties introduced by the base configuration are also merged into the new object.

`deep-merge` also provides a recursive equality function, to test for the strcutural equality of nested Javascript objects.

| Function | Parameters | Description | Returns |
|---|---|---|---|
| equals   |  - a {Object} - b {Object}  | Validates if the two objects are structurally equal.                                   | Return true if a == b.                                 |
| merge    |  - a {Object} - b {Object}  | Performs a recursive deep merge on the two objects. All properties of b are preserved. | Returns an object with the properties of both a and b. |
|||||

---
_Source: https://npm.io/package/deeper-merge · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
