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

deep-diff-obj

v1.1.1

Published

## Why I another library to diff object

Downloads

178

Readme

Diff javascript Build Status

Why I another library to diff object

I knew there are already many libraries dealing with comparing two objects, like the below.

However, none of them support compare arrays with order insensitive, like [1, 2] and [2, 1] should be equal if we want to compare them with order insensitive.

Also this package support the following features other libraries didn't support like:

  • certain path level configuration
  • path level configuration with regex supported
  • support arrays with order insensitive
  • wrote in typescript

How to use it

Installation

npm i deep-diff-obj

Usage

type diff = (
  left: Value,
  right: Value,
  options?: Option[],
  currentPath?: string
) => DiffResult[]

type Option = {
  path: string | RegExp
  ignore?: boolean
  array?: ArrayOptions
}

type DiffResult =
  | {
      type: DiffResultTypeEnum.Added
      path: string
      right: Value
    }
  | { type: DiffResultTypeEnum.Deleted; path: string; left: Value }
  | {
      type: DiffResultTypeEnum.Editted
      path: string
      left: Value
      right: Value
    }

enum DiffResultTypeEnum {
  Editted = 'E',
  Added = 'A',
  Deleted = 'D'
}
  • compare two primitives
import { diff } from 'deep-diff-obj'
diff(1, 2) // [{ path: '', type: 'E', left: 1, right: 2 }]
  • compare two simple objects
import { diff } from 'deep-diff-obj'
diff({ a: 1 }, { a: 2 }) // [{ path: 'a', left: 1, right: 2, type: 'E' }]
  • compare two arrays (order sensitive)
diff([1, 2], [1, 2, 3]) // [ { path: '[2]', type: 'A', right: 3 } ]

-- compare two array (order insensitive)

diff([1, 2], [2, 1], [{ path: '', array: { orderSensitive: false } }]) // []
diff([1, 2], [2, 1, 3], [{ path: '', array: { orderSensitive: false } }]) // [{ path: '(3)', type: 'A', right: 3 }]

If diff array with order insensitive, the path is the key surrounded by ()

  • compare two object array: order insensitive, ignore undefined key (by default)
diff(
  [{ id: 1 }, { id: 2 }, { noid: 3 }],
  [{ id: 1 }, { id: 2 }],
  [
    {
      path: '',
      array: {
        getKey: x => (x.id ? x.id.toString() : undefined),
        orderSensitive: false
      }
    }
  ]
) // []
  • compare two object array: order insensitive, ignore undefined key
diff(
  [{ id: 1 }, { id: 2 }, { noid: 3 }],
  [{ id: 1 }, { id: 2 }],
  [
    {
      path: '',
      array: {
        getKey: x => (x.id ? x.id.toString() : undefined),
        orderSensitive: false,
        ignoreUndefinedKey: false
      }
    }
  ]
) // [{ path: '(undefined)', type: 'D', left: { noid: 3 } }]
  • ignore certain path
diff({ a: 1, b: 2 }, { a: 1, b: 3 }, [{ path: 'b', ignore: true }]) // []
  • ignore certain path by regex
diff({ a: 1, b1: 2, b2: 3 }, { a: 1, b1: 3, b2: 4 }, [
  { path: /^b/, ignore: true }
]) // []

See more examples in the unit tests

Plans

  • [x] setup project
    • [x] setup semantic-release
    • [x] setup npm package
    • [x] setup travis ci

Logs

  • 20/11 2h
  • 21/11 10m
  • 22/11 20m
  • 23/11 2h
  • 26/11 20h