Skip to Content
New: @blazediff/core-native now includes interpret — structured diff analysis to understand what changed. Read more →
Documentation@blazediff/object

@blazediff/object

Structural object comparison with path tracking, cycle detection, and CREATE/REMOVE/CHANGE types.

Installation

npm install @blazediff/object

Features

  • Path tracking for nested modifications
  • Handles primitives, objects, arrays, dates, regex, and circular references
  • Consistent shapes for V8 optimization (type, path, value, oldValue)

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