Skip to content

Commit

Permalink
release deep merge
Browse files Browse the repository at this point in the history
  • Loading branch information
therohk committed Aug 27, 2024
1 parent 6a1adac commit 7ddafac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

**NPM library** : https://www.npmjs.com/package/datum-merge

![](https://github.com/therohk/datum-merge/actions/workflows/build.yml/badge.svg)
![](https://github.com/therohk/datum-merge/actions/workflows/build.yml/badge.svg) ![](https://img.shields.io/github/v/release/therohk/datum-merge)

---

## Upcoming Features

1. inline entire [deep-diff](https://github.com/flitbit/diff) library which is unmaintained and contains serious bugs.
1. inline the unmaintained [deep-diff](https://github.com/flitbit/diff) library which contains serious bugs. (available)

2. support merging for top level arrays or primitives.

Expand All @@ -27,8 +27,18 @@ Code contributions are welcome via issues and pull requests.
## Sample Usage

```
import { merge, detailMerge, MergeConfig, UpdateCode } from "datum-merge";
const diff = merge(target, source, UpdateCode.B, UpdateCode.XM);
import { merge, detailMerge, UpdateCode } from "datum-merge";
//merges all fields
let diff = merge(target, source, UpdateCode.I, UpdateCode.XM, UpdateCode.B);
//merges only given fields
diff = detailMerge(target, source, {
mykey: UpdateCode.I,
myarr: UpdateCode.XM,
anobj: UpdateCode.B,
myobj: { myid: UpdateCode.I },
});
```

## Merge Strategy
Expand Down Expand Up @@ -64,10 +74,10 @@ Applying the merge results in one of these transitions per primitive value in th

| Code Value | Meaning | Transitions |
|----|----|----|
| Z | noop / ignore | `null <- null` or `non-null == non-null` |
| N | new / insert | `null <- non-null` |
| E | edit / update | `non-null <- non-null` |
| D | unset / delete | `non-null <- null` |
| Z | noop / ignore | `null <-- null` or `non-null == non-null` |
| N | new / insert | `null <-- non-null` |
| E | edit / update | `non-null <-- non-null` |
| D | unset / delete | `non-null <-- null` |
| AN | array size increase | `non-null > non-null` |
| AD | array size decrease | `non-null < non-null` |

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export { type DetailConfig, } from "./merge-conf";
export { detailMerge, immutableDetailMerge } from "./merge-conf";

//defaults
export { shallowMerge as merge } from "./merge-high";
export { deepMerge as merge } from "./merge-high";
export * from "./diff-lib/deep-diff";
export { deepDiffLow as deepDiff } from "./diff-high";

0 comments on commit 7ddafac

Please sign in to comment.