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

lo-diff

v1.0.5

Published

Utility to calculate the deep diff of two objects

Readme

lo-diff

Utility leveraging Lodash methods to calculate the deep diff of two objects

Returns an object that contains both the different and matching values of the reference and target objects.

The returned object will contain a 'diff' object whose keys are those that differ between the reference and target object, each key's value will be an object with the keys 'ref' and 'targ', whose values will be the value of the given key in each object.

The object will also contain a 'match' object whose keys and values are those that are the same in the reference and target objects.

Installation

Using npm:
$ npm install --save lo-diff
In Node.js:
// Load the just the diff function.
var diff = require('lo-diff').diff;
// Load the full module.
var lodiff = require('lo-diff');
Test:
$ npm test

Use

Example:
// Load the just the diff function.
var diff = require('lo-diff').diff;

var = objA = { // reference object
  name: 'cart',
  items: {
    apple: 2,
    carrots: 5,
    plums: 4
  }
};

var objB = {    // target object
  name: 'cart', // same name
  items: {      // same object 'items'
    apple: 5,   // same key 'apples', different quantity
    carrots: 5, // same key and quantity
                // missing key 'plums'
    pears: 6    // new key 'pears'
  }
};

// calculate diff
var result = diff(objA, objB);

// result
{
  diff: {
    'items.apple': { ref: 2, targ: 5 },
    'items.plums': { ref: 4, targ: undefined },
    'items.pears': { ref: undefined, targ: 6 }
  },
  match: {
    name: 'cart',
    'items.carrots': 5
  }
}
Output Format:
var results = {
  diff : {
    key1: {
      ref: val1,
      targ: val2
    },
    key2 : {
      ref: val1,
      targ: val2
    }
  },
  match ; {
    key1: val1,
    key2: val2
  }
};

API

diff(ref, targ)

Returns an object containing both the different and matching values of the reference and target objects.

/**
 * Returns an object containing both the different and matching values of the
 * reference and target objects.
 *
 * The object will contain a 'diff' object whose keys are those that differ
 * between the reference and target object, each key's value will be an
 * object with the keys 'ref' and 'targ', whose values will be the value of
 * the given key in each object.
 *
 * The object will also contain a 'match' object whose keys and values are
 * those that are the same in the reference and target objects.
 *
 * @param {Object} ref Reference object in diff
 * @param {Object) targ Target object in diff
 * @return (Object} results Object containing differing and
 *    matching obj values
 */
function diff(ref, targ)

oneWayDiff(x, y, k)

Determines the one-way difference between two objects and returns a String Array of Key Paths representing the differences.

/**
* Determines the one-way difference between two objects and returns a String
* Array of Key Paths representing the differences.
*
* Key Paths of object x are returned where the value for the same path in
* object y is different than object x or where the key path doesn't exist in
* object y
*
* @param {Object} x Reference object in diff
* @param {Object} y Target object in diff
* @param {String} k Optional String representing a Key. Will be used to
*     access sub-object of x and y for comparison (i.e., x[k] vs. y[k])
* @return {String[]} result String Array of Key Paths
*/
function oneWayDiff(x, y, k)

diffPaths(a, b)

Determines the difference between two objects and returns a String Array of Key Paths representing the differences.

/**
 * Determines the difference between two objects and returns a String Array
 * of Key Paths representing the differences.
 *
 * Key Paths of object a and b are returned where the value for the same path
 * in each object is different or where the key path doesn't exist in one of
 * the two objects
 *
 * @param {Object} a Reference object in diff
 * @param {Object} b Target object in diff
 * @return {String[]} result String Array of Key Paths
 */
function diffPaths(a, b)

getPaths(obj, pre)

Returns a String Array of dot-separated Key values representing the paths to each Value within the provided Object. Optionally, provide a prefix to be appended to the left side of each path

/**
 * Returns a String Array of dot-separated Key values representing the paths
 * to each Value within the provided Object. Optionally, provide a prefix to
 * be appended to the left side of each path.
 *
 * @param {Object} obj Object to generate paths for
 * @param {String} pre String to append to left side of each path
 * @return {String[]} paths String Array of paths for obj
 */
function getPaths(obj, pre)