Skip to Content
Documentation@blazediff/object

@blazediff/object

Lightning-fast structural object comparison with detailed change tracking. High-performance algorithm optimized for real-world data structures.

Installation

npm install @blazediff/object

Features

  • High Performance - Optimized algorithm with intelligent key lookup strategies
  • 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

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

ParameterTypeDescription
oldObjanyThe original object to compare from
newObjanyThe new object to compare to
optionsobjectConfiguration options (optional)

Options

OptionTypeDefaultDescription
detectCyclesbooleantrueEnable circular reference detection

Returns

Returns Difference[] - Array of difference objects with consistent structure:

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

Difference Types

Difference Types are represented as numbers for optimal performance:

TypeNameDescription
0CREATEProperty or array element was added
1REMOVEProperty or array element was deleted
2CHANGEProperty or array element was modified

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

Last updated on