Skip to content
A tiny (247B) utility for check for deep equality
Branch: master
Clone or download
Latest commit 546da76 Mar 7, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test chore: import tests Mar 7, 2019
.editorconfig initial commit Mar 7, 2019
.gitignore initial commit Mar 7, 2019
.travis.yml
dequal.d.ts chore: add typings Mar 7, 2019
license
package.json 1.0.0 Mar 7, 2019
readme.md chore: typos Mar 7, 2019

readme.md

dequal Build Status

A tiny (247B) utility to check for deep equality

This module supports comparison of all types, including Function, RegExp, Date, null, undefined, and NaN values.
Objects and Arrays are traversed recursively.

Please note that key order within Objects does not matter.
However, the value order within Arrays does matter.

This module exposes three module definitions:

  • CommonJS: dist/dequal.js
  • ESModule: dist/dequal.mjs
  • UMD: dist/dequal.min.js

Install

$ npm install --save dequal

Usage

const dequal = require('dequal');

dequal(1, 1); //=> true
dequal({}, {}); //=> true
dequal('foo', 'foo'); //=> true
dequal([1, 2, 3], [1, 2, 3]); //=> true
dequal(dequal, dequal); //=> true
dequal(/foo/, /foo/); //=> true
dequal(null, null); //=> true
dequal(NaN, NaN); //=> true
dequal([], []); //=> true
dequal(
  [{ a:1 }, [{ b:{ c:[1] } }]],
  [{ a:1 }, [{ b:{ c:[1] } }]]
); //=> true

dequal(1, '1'); //=> false
dequal(null, undefined); //=> false
dequal({ a:1, b:[2,3] }, { a:1, b:[2,5] }); //=> false
dequal(/foo/i, /bar/g); //=> false

API

dequal(foo, bar)

Returns: Boolean

Both foo and bar can be of any type.
A Boolean is returned indicating if the two were deeply equal.

Benchmarks

Running Node v10.13.0

fast-deep-equal   x 214,365 ops/sec ±0.30% (93 runs sampled)
dequal            x 160,116 ops/sec ±0.29% (93 runs sampled)
lodash.isEqual    x  45,257 ops/sec ±0.26% (95 runs sampled)

Candidates operate identically to one another

License

MIT © Luke Edwards

You can’t perform that action at this time.