@philiprehberger/deep-equal
v0.1.3
Published
Fast deep equality comparison for JavaScript values with TypeScript type guards
Readme
@philiprehberger/deep-equal
Fast deep equality comparison for JavaScript values with TypeScript type guards.
Installation
npm install @philiprehberger/deep-equalUsage
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 }); // trueAPI
deepEqual(a: unknown, b: unknown, options?: DeepEqualOptions): boolean
Performs a deep equality comparison between two values.
Options:
| 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.
Development
npm install
npm run build
npm testSupport
If you find this project useful:
