Version 5.1.0 - Production-ReadyTC39 Stage 0MIT License
Object.isEqual is a deep structural equality polyfill for JavaScript, filling a critical gap in the ECMAScript standard library. It enables developers to compare any two values by their internal structure with a single, reliable, and secure function call. Currently, teams rely on third-party libraries (Lodash) or fragile workarounds like JSON.stringify, introducing dependencies and subtle bugs. This proposal eliminates that need with native-grade comparison and industrial-strength security.
The polyfill is self-contained, has zero dependencies, and has undergone exhaustive security audits. It is ready for immediate adoption in any ES6+ environment.
JavaScript lacks a built-in mechanism to compare two objects by value. The strict equality operator (===) compares references, not contents. Common workarounds fail with Date, RegExp, Map, Set, NaN, circular references, and property order. This forces developers to choose between fragility, bloat, or risk.
Object.isEqual(value1, value2[, options]) provides a standardized, dependency-free method for deep structural comparison. It handles all JavaScript types natively, supports customization, and includes built-in security protections against malicious input.
| Threat | Impact | Mitigation |
|---|---|---|
| Type spoofing via Symbol.toStringTag | DoS / code execution | Own-property check; fallback to generic comparison |
| Overridden instance methods | Code execution | Native methods captured at load time, invoked via .call() |
| Cross-realm objects (iframes) | False negatives | Type detection via Object.prototype.toString |
| Hostile getters throwing errors | DoS | Safe mode (default on) captures and returns false |
| Deep recursion / huge collections | Stack overflow | Configurable maxDepth and maxSize limits |
| Solution | Types | Cycles | Security | Standard | Deps |
|---|---|---|---|---|---|
| Object.isEqual | All native | Yes | Hardened | TC39 proposal | 0 |
| Lodash _.isEqual | Most | Yes | Partial | No | 1 (Lodash) |
| JSON.stringify | Basic | No | N/A | Yes (ES5) | 0 |
Object.isEqual is a mature, production-ready polyfill that solves a pervasive problem in JavaScript development. It is thoroughly tested, security-hardened, and aligned with the TC39 standardization path. The author recommends immediate adoption in projects that currently use Lodash _.isEqual or custom comparison utilities, and active promotion within the TC39 committee to advance the proposal.