Object.isEqual() - Comprehensive Documentation

Version 5.1.0TC39 Stage 0MIT License

1. API Reference

Object.isEqual(value1, value2[, options])

Compares two values and returns true if they are structurally equal.

Options

PropertyTypeDefaultDescription
strictbooleanfalseIf true, uses Object.is for primitives (0 differs from -0)
customComparatorsobject{}Functions (a,b)=>boolean indexed by key or Symbol.for('*') for global
maxDepthnumber1000Maximum recursion depth
maxSizenumber10000Maximum elements in collections (Array, Map, Set)
safebooleantrueIf true, silences exceptions from getters and returns false

2. Supported Types

TypeBehavior
Primitives (number, string, boolean, null, undefined, symbol, bigint)Comparison via SameValueZero (default) or Object.is (strict mode)
Number / Boolean / String wrappersCompares primitive value via valueOf()
DateCompares getTime() (includes invalid NaN dates)
RegExpCompares source and flags
ArrayCompares length and enumerable properties
MapCompares entries by deep structural equality of keys and values
SetVerifies each element has a structural equivalent in the other set
TypedArrays (all)Compares length and elements with SameValueZero
ArrayBuffer / DataViewCompares bytes
ErrorCompares name and message
WeakMap / WeakSet / PromiseReferential equality only (always false for different instances)
FunctionsTwo different functions are never equal; ignored when both values are functions

3. Usage Examples

Basic

Object.isEqual({a:1,b:{c:2}},{a:1,b:{c:2}}); // true

Strict mode

Object.isEqual(0,-0,{strict:true}); // false

Custom comparator

Object.isEqual({id:1,ts:100},{id:1,ts:200},{customComparators:{ts:()=>true}}); // true

Safe mode

var obj={get x(){throw new Error('no')},y:1};
Object.isEqual(obj,obj,{safe:true}); // false (error captured)

4. Security

ThreatMitigation
Type spoofing via Symbol.toStringTagOwn-property check before native shortcuts
Overridden instance methodsNative methods captured at load time
Cross-realm objectsType detection via Object.prototype.toString
Hostile gettersSafe mode captures exceptions
DoS (deep recursion/large collections)Configurable maxDepth and maxSize

5. Installation

npm install object-is-equal
require('object-is-equal');
console.log(Object.isEqual({a:1},{a:1})); // true

Or include directly in browser:

<script src="object-isEqual.js"></script>