npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

datum-merge

v0.9.5

Published

Simplified diff and merging for deeply nested objects.

Downloads

329

Readme

datum-merge

datum-merge is a modern typescript library that simplifies merge and diff operations for deeply nested objects.

Source Code : https://github.com/therohk/datum-merge

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


Sample Usage

Merge with default config:

import { merge, customMerge, UpdateCode } from "datum-merge";
const changed = merge(target, source, UpdateCode.I, UpdateCode.XM, UpdateCode.B);
//same as
const diff = customMerge(target, source, {
    scalar: UpdateCode.I,
    vector: UpdateCode.XM,
    nested: UpdateCode.B,
});

Exact nestable config that ignores all other fields:

import { detailMerge, UpdateCode } from "datum-merge";
const changed = detailMerge(target, source, {
    mykey: UpdateCode.I,
    myarr: UpdateCode.XM,
    anobj: UpdateCode.B,
    myobj: { myid: UpdateCode.I },
});

Deep merge with generic config patterns:

import { customMerge, MergeConfig, UpdateCode } from "datum-merge";
const conf: MergeConfig = {
    "*_id": UpdateCode.I,
    scalar: UpdateCode.B,
    field1: UpdateCode.D,
    "arr*": UpdateCode.XM,
    nested: UpdatedCode.N,
    obj1: {
        scalar: UpdateCode.B,
        vector: UpdateCode.XM,
    },
};
const diff = customMerge(target, source, conf);

Upcoming Features

  1. inline the unmaintained deep-diff library which contains serious bugs. (available)

  2. formalize config schema for deeply nested objects (for v1).

  3. option to ignore errors for datatype mismatch during merge.

  4. support merging for top level arrays or primitives.

  5. accept a subset of json-patch operations for merge.

Code contributions are welcome via issues and pull requests.


Merge Strategy

This string code describes how modifications to an attribute for a PUT/UPDATE operation should be handled. It decides whether a change to the value of the field is allowed during a merge between two entities.

Strategy Codes

The same field within a source and target object is represented by s and t respectively. Whether the strategy requires data to be present for the field, is shown by { 0=no, 1=yes, X=irrelavant }. The value is migrated from the source field to the target field only if the predicate passes.

| Code | Predicate | Meaning | |----|----|----| | C | n/a | always create new instance | | T | n/a | touch datum ; empty merge | | N | 0 | reject any change ; skip merge | | Y | sX & tX | accept any change ; bypass merge | | B | s1 & tX | insert or update, no delete | | H | s1 & t1 | update only if exists | | U | sX & t1 | update or delete only, no insert | | I | sX & t0 | insert only, no update or delete | | D | s0 & tX | delete only, no update or insert | | XR | sX & tX | full vector replacement | | XM | s ∪ t | set union, vector merge | | XD | t - s | set difference, delete given values | | XI | s ∩ t | set intersection, delete missing values | | XS | t + s | preserve order insert (allows dupes) | | XF | s + t | insert from start (allows dupes) |

Diff Codes

Applying the merge results in one of these transitions per primitive value in the target object.

| Patch Op | Meaning | Rev Code | Transitions | |----|----|----|----| | add | new / insert | I | null <-- non-null | | replace | edit / update | H | non-null <-- non-null | | remove | unset / delete | D | non-null <-- null | | test | noop / skip / ignore (tbd) | N | null <-- null or non-null == non-null |