is-equal
Version:
Are these two values conceptually equal?
63 lines (51 loc) • 2.3 kB
Markdown
5]][6]
[![dev dependency status][7]][8]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][11]][1]
Are these two values conceptually equal?
```js
var isEqual = require('is-equal');
var assert = require('assert');
var primitives = [true, false, undefined, 42, 'foo'];
primitives.forEach(function (primitive) {
assert.equal(isEqual(primitive, primitive), true);
});
assert.equal(isEqual(/a/g, /a/g), true);
assert.equal(isEqual(/a/g, new RegExp('a', 'g')), true);
assert.equal(isEqual({ a: 2 }, { a: 2 }), true);
assert.equal(isEqual([1, [2, 3], 4], [1, [2, 3], 4]), true);
var timestamp = Date.now();
assert.equal(isEqual(new Date(timestamp), new Date(timestamp)), true);
```
Will return an empty string if `isEqual` would return `true` - otherwise will return a non-empty string that hopefully explains the reasoning.
```
var whyNotEqual = require('is-equal/why');
assert.equal(whyNotEqual(1, 1), '');
assert.equal(
whyNotEqual({ a: 1 }, { a: 2 }),
'value at key "a" differs: numbers are different: 1 !== 2'
);
```
Simply clone the repo, `npm install`, and run `npm test`
[ ]: https://npmjs.org/package/is-equal
[ ]: https://versionbadg.es/inspect-js/is-equal.svg
[ ]: https://david-dm.org/inspect-js/is-equal.svg
[ ]: https://david-dm.org/inspect-js/is-equal
[ ]: https://david-dm.org/inspect-js/is-equal/dev-status.svg
[ ]: https://david-dm.org/inspect-js/is-equal#info=devDependencies
[ ]: https://nodei.co/npm/is-equal.png?downloads=true&stars=true
[ ]: https://img.shields.io/npm/l/is-equal.svg
[ ]: LICENSE
[ ]: https://img.shields.io/npm/dm/is-equal.svg
[ ]: https://npm-stat.com/charts.html?package=is-equal
[ ]: https://codecov.io/gh/inspect-js/is-equal/branch/main/graphs/badge.svg
[ ]: https://app.codecov.io/gh/inspect-js/is-equal/
[ ]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-equal
[ ]: https://github.com/inspect-js/is-equal/actions
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][