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 🙏

© 2026 – Pkg Stats / Ryan Hefner

deep-obj-diff

v1.0.1

Published

A zero-dependency, fully typed deep object diffing library with customizable output formats

Readme

deep-obj-diff

A zero-dependency, fully typed deep object diffing library for JavaScript and TypeScript.

Features

  • Zero runtime dependencies
  • Written in TypeScript with full type exports
  • Multiple output formats: list, flat, nested, JSON Patch, or custom
  • Convenience helpers: hasDiff, addedDiff, removedDiff, changedDiff
  • Path filtering, custom equality, depth limits, unordered arrays
  • Handles edge cases: NaN, ±0, Date, RegExp, null/undefined

Installation

npm install deep-obj-diff

Quick Start

import { diff } from 'deep-obj-diff';

const original = { a: 1, b: { c: 2 }, d: [1, 2, 3] };
const updated  = { a: 1, b: { c: 9 }, d: [1, 2], e: 'new' };

const changes = diff(original, updated);
// [
//   { kind: 'changed', path: 'b.c', lhs: 2, rhs: 9 },
//   { kind: 'removed', path: 'd[2]', lhs: 3 },
//   { kind: 'added',   path: 'e',    rhs: 'new' },
// ]

Common Use Cases

Compare configuration versions

const configV1 = {
  database: { host: 'localhost', port: 5432, ssl: false },
  cache: { ttl: 300 },
};

const configV2 = {
  database: { host: 'db.prod.com', port: 5432, ssl: true },
  cache: { ttl: 600 },
  logging: { level: 'info' },
};

diff(configV1, configV2);
// [
//   { kind: 'changed', path: 'database.host', lhs: 'localhost', rhs: 'db.prod.com' },
//   { kind: 'changed', path: 'database.ssl',  lhs: false, rhs: true },
//   { kind: 'changed', path: 'cache.ttl',     lhs: 300,   rhs: 600 },
//   { kind: 'added',   path: 'logging',       rhs: { level: 'info' } },
// ]

Quick boolean check

import { hasDiff } from 'deep-obj-diff';

if (hasDiff(savedForm, currentForm)) {
  showUnsavedChangesWarning();
}

Get only additions, removals, or modifications

import { addedDiff, removedDiff, changedDiff } from 'deep-obj-diff';

addedDiff(before, after);    // only new properties
removedDiff(before, after);  // only deleted properties
changedDiff(before, after);  // only modified values

Generate JSON Patch operations

const patches = diff(lhs, rhs, { format: 'patch' });
// [{ op: 'replace', path: '/b/c', value: 9, oldValue: 2 }, ...]

Flat object keyed by path

const flat = diff(lhs, rhs, { format: 'flat' });
// { 'b.c': { kind: 'changed', lhs: 2, rhs: 9 }, ... }

Custom formatter

const count = diff(lhs, rhs, {
  format: (changes) => changes.length,
});
// 3

Options

diff(lhs, rhs, {
  format: 'list',              // 'list' | 'flat' | 'nested' | 'patch' | custom function
  includeUnchanged: false,     // include unchanged entries in the output
  maxDepth: Infinity,          // limit recursion depth
  arrayOrderMatters: true,     // set to false to treat arrays as sets
  filter: (path) => boolean,   // include/exclude specific paths
  isEqual: (a, b) => boolean,  // custom equality for leaf values
  ignorePaths: ['meta.*'],     // glob patterns to ignore
  expandJsonStrings: false,    // parse JSON-stringified values before diffing
});

Path filtering

// Only diff the "settings" subtree
diff(lhs, rhs, {
  filter: (path) => path === '' || path.startsWith('settings'),
});

Custom equality (numeric tolerance)

diff(measurements1, measurements2, {
  isEqual: (a, b) => {
    if (typeof a === 'number' && typeof b === 'number')
      return Math.abs(a - b) < 0.001;
    return Object.is(a, b);
  },
});

Unordered array comparison

diff([3, 1, 2], [2, 3, 1], { arrayOrderMatters: false });
// [] — no differences

Types

All types are exported:

import type {
  DiffChange, DiffKind, DiffOptions, DiffResult,
  OutputFormat, FlatDiff, NestedDiff, NestedDiffNode,
  PatchOperation, PathFilter, EqualityFn, CustomFormatter,
} from 'deep-obj-diff';

License

MIT