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

@blazediff/object

v1.7.0

Published

Blazing-fast object comparison

Readme

@blazediff/object

npm bundle size NPM Downloads

Lightning-fast structural object comparison with detailed change tracking.

Features

  • High Performance: Optimized algorithm with intelligent key lookup strategies for large objects
  • Precise Tracking: Detailed path tracking for nested object modifications
  • Comprehensive Types: Handles primitives, objects, arrays, dates, regex, and circular references
  • Memory Efficient: Minimal overhead with consistent object shapes for V8 optimization
  • Cycle Detection: Built-in circular reference handling with configurable detection
  • Rich Output: Detailed difference objects with type, path, value, and oldValue information

Installation

npm install @blazediff/object

Quick Start

import diff from '@blazediff/object';

const oldObj = {
  name: "John",
  age: 30,
  city: "NYC",
  skills: ["JavaScript", "TypeScript"]
};

const newObj = {
  name: "John",
  age: 31,
  city: "San Francisco",
  skills: ["JavaScript", "TypeScript", "Go"],
  active: true
};

const changes = diff(oldObj, newObj);
console.log(changes);

Output:

[
  {
    "type": 2,
    "path": ["age"],
    "value": 31,
    "oldValue": 30
  },
  {
    "type": 2,
    "path": ["city"],
    "value": "San Francisco",
    "oldValue": "NYC"
  },
  {
    "type": 0,
    "path": ["skills", 2],
    "value": "Go",
    "oldValue": undefined
  },
  {
    "type": 0,
    "path": ["active"],
    "value": true,
    "oldValue": undefined
  }
]

API Reference

diff(oldObj, newObj, options?)

Compares two objects and returns an array of differences.

Parameters:

  • oldObj (any): The original object to compare from
  • newObj (any): The new object to compare to
  • options (object, optional): Configuration options
    • detectCycles (boolean): Enable circular reference detection (default: true)

Returns:

  • Difference[]: Array of difference objects

Difference Types

The diff function returns an array of difference objects with the following structure:

interface Difference {
  type: DifferenceType;
  path: (string | number)[];
  value: any;
  oldValue: any;
}

enum DifferenceType {
  CREATE = 0,  // Property or array element was added
  REMOVE = 1,  // Property or array element was deleted
  CHANGE = 2   // Property or array element value was modified
}

Difference Types:

  • 0 (CREATE) - Property or array element was added
  • 1 (REMOVE) - Property or array element was deleted
  • 2 (CHANGE) - Property or array element value was modified

All difference objects maintain consistent shape with type, path, value, and oldValue fields for optimal V8 performance.

Usage

import diff from '@blazediff/object';

// Simple property changes
const result = diff(
  { a: 1, b: 2, c: 3 },
  { a: 1, b: 20, d: 4 }
);
// Returns changes for modified 'b', removed 'c', and added 'd'

Nested Objects

// Deep nested changes
const oldData = {
  user: {
    profile: {
      settings: { theme: 'dark', notifications: true }
    }
  }
};

const newData = {
  user: {
    profile: {
      settings: { theme: 'light', notifications: true }
    }
  }
};

const changes = diff(oldData, newData);
// Returns: [{ type: 2, path: ['user', 'profile', 'settings', 'theme'], value: 'light', oldValue: 'dark' }]

Array Comparison

// Array modifications
const changes = diff(
  { items: ['a', 'b', 'c'] },
  { items: ['a', 'x', 'c', 'd'] }
);
// Detects element changes and additions