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

o2diff

v5.1.0

Published

Returns the difference between two objects

Readme

Contents

Install

$ pnpm i o2diff

Usage

import { diff, diffPaths, diffValues } from 'o2diff'

const original = {
  firstName: 'John',
  lastName: 'Smith',
  email: '[email protected]',
  phones: [
    { type: 'home', value: '+12222' },
    { type: 'mobile', value: '+11111' }
  ]
}
const current = {
  firstName: 'Michael',
  age: 25,
  email: '[email protected]',
  phones: [
    { type: 'work', value: '+13333' },
    { type: 'mobile', value: '+11111' }
  ],
  address: {
    city: 'New York',
    location: {
      latitude: 40.730610,
      longitude: -73.935242
    }
  }
}

// objects diff
diff(original, current)
/*
{
  left: {
    firstName: 'John',
    lastName: 'Smith',
    email: '[email protected]',
    phones: [{ type: 'home', value: '+12222' }]
  },
  right: {
    firstName: 'Michael',
    age: 25,
    email: '[email protected]',
    phones: [{ type: 'work', value: '+13333' }],
    address: {
      city: 'New York',
      location: { latitude: 40.730610, longitude: -73.935242 }
    }
  }
}
*/

// values diff
diffValues(original, current)
/*
{
  changed: {
    firstName: 'Michael',
    email: '[email protected]',
    phones: [{ type: 'home', value: '+12222' }]
  },
  added: {
    age: 25,
    address: {
      city: 'New York',
      location: { latitude: 40.730610, longitude: -73.935242 }
    }
  },
  deleted: {
    lastName: 'Smith'
  }
}
*/

// paths diff
diffPaths(original, current)  
/*
{
  changed: [
    'firstName',
    'email',
    'phones[0].type',
    'phones[0].value'
  ],
  added: [
    'age',
    'address.city',
    'address.location.latitude',
    'address.location.longitude'
  ],
  deleted: [
    'lastName'
  ]
}
*/

API

function diff(original: Input, current: Input): DiffResult

Returns the difference between original and current.

  • original: Input - the original object.
  • current: Input - the current (actual) object.
  • returns { left, right }: DiffResult object.

function diffValues(original: Input, current: Input): DiffValuesResult

Returns added, changed and deleted values between original and current.

  • original: Input - the original object.
  • current: Input - the current (actual) object.
  • returns { changed, added, deleted }: DiffValuesResult object.

function diffPaths(original: Input, current: Input): DiffPathsResult

Returns added, changed and deleted paths between original and current.

  • original: Input - the original object.
  • current: Input - the current (actual) object.
  • returns { changed, added, deleted }: DiffPathsResult object.

function revert(dest: Input, src: Input, customizer: (d: unknown, s: unknown) => unknown): RecordUnknown | ArrayUnknown;

Reverts dest object to src, calls customizer for each dest.path.

  • dest: Input - the destination object.
  • src: Input - the source object.
  • customizer: (d: unknown, s: unknown) => unknown) - the function that is called for each dest.path.
  • returns a record or an array.

function getPaths(obj: Input): string[]

Returns all paths of the object.

  • obj: Input - the source object.
  • returns the list of paths.

function omitPaths(obj: Input, excludedPaths: string[]): RecordUnknown | ArrayUnknown

Returns the object without excludedPaths.

  • obj: Input - the source object.
  • excludedPaths - the array of paths to exclude. The path can be with mask: *.name or name.* to exclude only path started or ended with the name.
  • returns a record or an array.

License

Licensed under the MIT license.

Author

Alexander Mac