# diff-upsert

> JSON object diff for upsert

Latest version **0.1.4** (published 2018-01-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install diff-upsert
pnpm add diff-upsert
yarn add diff-upsert
bun add diff-upsert
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2018-01-02 |
| First published | 2018-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Karl Lew |
| Maintainers | firepick |
| Keywords | JSON, diff, upsert |

## Links

- npm: https://www.npmjs.com/package/diff-upsert
- Repository: https://github.com/kinann/diff-upsert
- Issues: git+https://github.com/kinann/diff-upsert/issues
- npm.io page: https://npm.io/package/diff-upsert

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.4 (latest) — 2018-01-02
- 0.1.3 — 2018-01-02
- 0.1.2 — 2018-01-02
- 0.1.1 — 2018-01-02
- 0.1.0 — 2018-01-02

## README

# diff-upsert
`DiffUpsert` deep diffs a modified Javascript object with a base object using recursive matcher. 
`DiffUpsert` can also upsert a delta into a base object to bring it up-to-date.
This is helpful for managing changes to JSON configurations with deep trees.

NOTE: Contrast this behavior with the standard `Object.assign()` method, which only handles shallow deltas.

#### Base Object
```
var jbase = {
    color: 'red',
    sleeve: {
        length: 31,
    },
}
```

#### Updated Object
```
var jupdated = {
    color: 'red',
    sleeve: {
        length: 32, // updated property
    },
}
```

#### diff
```
var du = new DiffUpsert();
var delta = du.diff(jupdated, jbase);
//{
//    sleeve: {
//        length: 32, // updated property
//    },
//}
```

#### upsert
```
// jbase.sleeve.length === 31
du.upsert(jbase, delta); 
// jbase.sleeve.length === 32
```

#### excludeKeys
`DiffUpsert` can be configured to ignore selected keys:
```
var du = new DiffUpsert({
    excludeKeys: /^\$.*/,
});
```

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