Fast deep equality comparison for JavaScript values with TypeScript type guards
npm install @philiprehberger/deep-equalFast deep equality comparison for JavaScript values with TypeScript type guards
npm install @philiprehberger/deep-equal
import { deepEqual } from '@philiprehberger/deep-equal';
deepEqual({ a: 1, b: [2, 3] }, { a: 1, b: [2, 3] }); // true
deepEqual(new Map([['x', 1]]), new Map([['x', 1]])); // true
deepEqual(new Set([1, 2]), new Set([1, 2])); // true
// Strict mode: Object.is semantics
deepEqual(NaN, NaN, { strict: true }); // true
deepEqual(-0, +0, { strict: true }); // false
// Circular reference support
const a: any = { x: 1 };
a.self = a;
const b: any = { x: 1 };
b.self = b;
deepEqual(a, b, { circular: true }); // true
import { deepEqualBy } from '@philiprehberger/deep-equal';
const a = { id: 1, ts: 'now', body: { x: 1 } };
const b = { id: 2, ts: 'later', body: { x: 1 } };
deepEqualBy(a, b, (r) => r.body); // true — ignores id/ts
| Method | Description |
|---|---|
deepEqual(a, b, options?) | Deep equality comparison |
deepEqualBy(a, b, selector, options?) | Compare two values projected through a selector |
DeepEqualOptions| Option | Type | Default | Description |
|---|---|---|---|
strict | boolean | false | Use Object.is semantics (NaN, -0/+0 handling) |
circular | boolean | false | Detect and handle circular references |
Supported types: primitives, plain objects, arrays, Date, RegExp, Map, Set, TypedArray, Error, BigInt.
npm install
npm run build
npm test
If you find this project useful: