Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

is-equal

inspect-js571.4kMIT1.7.0

Are these two values conceptually equal?

equal, is, compare, comparison, equality

readme

is-equal Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

Are these two values conceptually equal?

Example

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);

Want to know why two values are not equal?

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'
);

Tests

Simply clone the repo, npm install, and run npm test

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.7.0 - 2023-10-20

v1.6.5 - 2023-10-20

Commits

  • [New] compare .toString, .valueOf, and [Symbol.toPrimitive] completions fa8d0ae
  • [meta] use npmignore to autogenerate an npmignore file 919afcd
  • [Tests] increase coverage bbe8513
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, es-value-fixtures, foreach, object.assign, tape 157a4fe
  • [Refactor] use hasown instead of has 590f3f6
  • [Fix] improve error message when callability is mismatched dc0f577
  • [Deps] update functions-have-names, has-bigints, has-symbols, is-callable, is-number-object, object-inspect c066c94
  • [actions] update rebase action to use reusable workflow 34eeaf5
  • [Deps] update es-get-iterator, object-inspect, object.entries, object.getprototypeof 8ce483c
  • [Dev Deps] update @ljharb/eslint-config, aud, es6-shim, tape b140b08
  • [Tests] use for-each instead of foreach 8baba96
  • [Deps] update object-inspect 65f0b06
  • [Dev Deps] update tape dca5479

v1.6.4 - 2022-01-10

Commits

  • [actions] reuse common workflows c8e9a71
  • [Fix] still check own properties on Dates, RegExps, and Functions 3295149
  • [actions] update codecov uploader 3157da9
  • [Dev Deps] update eslint, @ljharb/eslint-config, safe-publish-latest, tape ee76f73
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape 0653181
  • [Deps] update is-bigint, object.entries, object.getprototypeof 282a4e6
  • [Deps] update object-inspect b084bdf

v1.6.3 - 2021-08-06

Commits

  • [Refactor] increase coverage; remove redundant branches c6b6672
  • [Deps] update is-bigint, is-boolean-object, is-callable, is-date-object, is-generator-function, is-number-object, is-regex, is-string, is-symbol, object-inspect, object.entries a3b5498
  • [Tests] tape v5.3 exposed a bug in corejs tests; use --require instead a1e004e
  • [Refactor] use has-symbols/shams and has-bigints to more robustly detect these things 4f3aee4
  • [Dev Deps] update auto-changelog, core-js, eslint, tape d6a7b8e
  • [readme] fix usage code sample 04ce4d0

v1.6.2 - 2021-05-08

Commits

  • [Tests] increase coverage 18f85ad
  • [Tests] migrate tests to Github Actions 61f82f7
  • [Tests] run core-js tests on v2 and v3 aaa111d
  • [actions] use node/install instead of node/run; use codecov action db83237
  • [meta] remove unused Makefile and associated utilities cb9cf3f
  • [Tests] run nyc on all tests 6a55013
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape, make-arrow-function, make-generator-function adf932c
  • [Refactor] use object.getprototypeof ed3445b
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, es6-shim abd29fa
  • [Deps] update es-get-iterator, functions-have-names, is-boolean-object, is-callable, is-date-object, is-number-object, is-regex, is-symbol, is-string, object.entries, which-collection fbdb778
  • [Fix] why: compare two numbers properly 297b810
  • [Deps] update is-boolean-object, is-date-object, is-generator-function, is-number-object, is-regex, is-string, object-inspect 60aef5e
  • [Deps] update es-get-iterator, is-bigint, is-callable, is-generator-function, is-regex, object-inspect, object.entries 25cc9cb
  • [patch] "arrow function" should not be capitalized; "Generator function" is the proper term 4fa31c7
  • [actions] add "Allow Edits" workflow 227f80e
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, has-symbols, tape 4bd6461
  • [Deps] update es-get-iterator, functions-have-names, is-boolean-object, is-callable, which-boxed-primitive b9bdb70
  • [readme] fix broken URLs 1d39cbf
  • [Deps] update is-bigint, is-date-object, is-regex, object-inspect 020835e
  • [readme] use https URLs fd35312
  • [Dev Deps] update eslint, @ljharb/eslint-config, has-bigints, tape 3a58efc
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape, aud 733f027
  • [readme] add actions and codecov badges a53d5e4
  • [Tests] exclude deprecated, unused files from coverage bdd471b
  • [actions] switch Automatic Rebase workflow to pull_request_target event 115392b
  • [Dev Deps] update aud, tape 5e6018c
  • [Dev Deps] update auto-changelog, tape c4fde3a
  • [meta] use prepublishOnly script for npm 7+ 143ba39
  • [readme] remove travis badge 0583b0f
  • [Dev Deps] update auto-changelog; add aud afb177b
  • [Dev Deps] unpin core-js v3 d44ccc0
  • [Dev Deps] pin core-js v3 to < v3.9 63fd454
  • [Deps] update object.entries e5adb39
  • [Tests] only audit prod deps 5e285d5
  • [actions] update workflows 7945708

v1.6.1 - 2019-11-28

Commits

  • [Refactor] use es-get-iterator internally 09dac2f
  • [Fix] getSymbolIterator: make sure it can handle core-js also d9d9198
  • [readme] fix repo URLs, remove testling 35e5e37
  • [actions] add automatic rebasing / merge commit blocking 6ddd2fc
  • [Dev Deps] update eslint, @ljharb/eslint-config, has-symbols 4a3bb24
  • [Deps] update is-symbol 083c8b6
  • docs: fix header syntax 8142a3b

v1.6.0 - 2019-11-11

Commits

  • [meta] add auto-changelog 968f3e5
  • [Tests] use shared travis-ci configs 600f4b3
  • [Dev Deps] remove jscs 23c2e2e
  • [New] add support for BigInts bf31461
  • [Tests] up to node v11.6, v10.15, v8.15, v6.16 6145b4e
  • [Tests] up to node v8.2, v7.10, v6.11, v4.8; newer npm breaks on older nodes 48cf16d
  • [Tests] up to node v10.1, v9.11, v8.11, v6.14, v4.9 94c2b86
  • [Dev Deps] update eslint, @ljharb/eslint-config; add safe-publish-latest 5809415
  • [Tests] up to node v9.2, v8.9, v6.12; use nvm install-latest-npm; pin included builds to LTS 7c6528d
  • [Tests] up to node v12.9, v11.15, v10.16, v8.16 2ea3e84
  • [Tests] up to node v11.13, v6.17 41b48e8
  • [Dev Deps] update @ljharb/eslint-config, eslint, nsp, semver, tape 4eacf82
  • [Dev Deps] update eslint, @ljharb/eslint-config, core-js, covert, es6-shim, replace, semver, tape e5a6848
  • [meta] create FUNDING.yml fbce9ee
  • [Dev Deps] update eslint, @ljharb/eslint-config, core-js, es6-shim, replace, semver 298d528
  • [Dev Deps] update replace, semver,tape,nsp,eslint,core-js,@ljharb/eslint-config[8ee88e7`](https://github.com/inspect-js/is-equal/commit/8ee88e78ebed836a78495418435950d2de7cd58e)
  • [Tests] use has-symbols da43e4d
  • [Dev Deps] update eslint, @ljharb/eslint-config, replace, semver, tape 0db9191
  • [Tests] use npm audit instead of nsp 3a93636
  • [Dev Deps] update eslint, @ljharb/eslint-config, semver f35a03a
  • [Dev Deps] update eslint, nsp, @ljharb/eslint-config, core-js 63967ba
  • [Tests] test on both core-js 3 and 2 9c4e491
  • [Tests] use npx aud instead of npm audit with hoops 494ba19
  • Only apps should have lockfiles 8dbdcc6
  • [meta] add funding field e350d2f
  • [Tests] fix linting f31ff12
  • [Deps] update is-callable, is-symbol 65c9e04
  • [Dev Deps] update core-js, tape 87e23ee
  • [Tests] fix linting errors 54f3476
  • [meta] remove unused nsp 826e6f2
  • [Deps] update object.entries fce1776
  • [Deps] update has a3443e1
  • [Deps] update is-generator-function d11429a
  • [Deps] update is-regex 9257a28

v1.5.5 - 2017-02-05

Fixed

  • [Fix] remove early failure for stringified arrays, to handle Symbols in arrays. #194

Commits

  • [Dev Deps] update eslint, @ljharb/eslint-config 35549f1

v1.5.4 - 2017-01-25

Fixed

  • Exclude html files, which were never intentionally added to the package. #34

Commits

  • [Tests] up to node v7.4, v4.7; improve test matrix 6f20b3d
  • [Tests] pass functions through Object to avoid function name inference in node 7. 99ba6de
  • [Tests] up to node v7.0, v6.9, v4.6; improve test matrix f834855
  • [Dev Deps] update tape, jscs, semver, eslint, @ljharb/eslint-config, nsp a53cc6f
  • [Dev Deps] update tape, eslint, @ljharb/eslint-config d42d423
  • [Dev Deps] update tape, jscs, semver, eslint, @ljharb/eslint-config, nsp, core-js c064e99
  • [Dev Deps] update eslint, @ljharb/eslint-config 5139dd8
  • [Dev Deps] update eslint e5e9d91
  • [Dev Deps] update eslint, @ljharb/eslint-config, es6-shim f6de73d
  • [Dev Deps] remove extra object.entries; update eslint, es6-shim fdcdbe5
  • [Deps] update object-entries, is-generator-function c1bc768
  • [Tests] up to node v7.2 90aa4ea
  • [Tests] on node v6.2, v5.12 3ee66c5

v1.5.3 - 2016-05-24

Fixed

  • [Fix] avoid false circular reference positives with falsy values in nested objects. #24

v1.5.2 - 2016-05-18

Commits

  • [Dev Deps] update tape, jscs, eslint, @ljharb/eslint-config, nsp, core-js ed25637
  • [Dev Deps] update jscs, eslint, nsp, core-js 043d51c
  • fix Object.prototype.toString() comparison ce2ca36
  • [Dev Deps] update jscs, eslint, @ljharb/eslint-config, nsp, es6-shim, core-js 6034d56
  • [Tests] use pretest/posttest for linting/security 82c3c9d
  • [Tests] up to node v5.9, v4.4 be477e9
  • [Dev Deps] update eslint, es6-shim, core-js ac1e3ac
  • [Tests] up to node v6.1 9cb7c69
  • [Tests] on node v5.10 c798cfe
  • [Deps] update is-callable 9b8e53b
  • [Tests] on node v5.7 01c52fa

v1.5.1 - 2016-02-22

Merged

  • [Fix] fix "why" message for circular reference inequality #12

Commits

  • [Refactor] Delete unreachable code. 8af4f70
  • Add tests for circular reference inequality. fd8bdfa
  • [Tests] fix assertion message (followup to #11) adc9c0a
  • Fix error message sense. b2faa62
  • Fix example d701069
  • Fix err msg for inequal circ ref (+second, -first). 6b9e478

v1.5.0 - 2016-02-15

Commits

  • [New] add “whyNotEqual” at require(‘is-equal/why’) to provide an inequality reason. fd7a11d
  • [Refactor] use whyNotEqual internally in isEqual 692f0a5
  • [Tests] add some more tests. 06f434f
  • [Dev Deps] update tape, jscs, eslint, @ljharb/eslint-config, core-js, es6-shim f0fc78c
  • [Tests] up to node v5.6, v4.3 087c8e6
  • [Dev Deps] update jscs, eslint, @ljharb/eslint-config 637fa7c
  • [Tests] use getSymbolIterator internal module. 8f47efa
  • [Dev Deps] update tape, nsp, core-js e246264
  • [Deps] update is-callable 2766a04
  • [Dev Deps] update es6-shim e6f5e76

v1.4.2 - 2015-12-16

Fixed

  • [Fix] avoid false positives when the first items in two arrays are not equal. #5

v1.4.1 - 2015-12-15

Merged

  • [Tests] add tests to ensure proper key ordering #3

Commits

v1.4.0 - 2015-12-10

Fixed

  • [New / Fix] Restore basic circular reference support. #2

Commits

  • [Deps] use has instead of relying on Function#call. 0eeda8f

v1.3.1 - 2015-12-10

Fixed

  • [Fix] Partially revert 2517c2151d57451f7f7009df065bf1601316ee46, since object key ordering shouldn't matter. #3
  • [Fix] handle Map/Set in Safari 8, which lacks Symbol.iterator. #3
  • [Tests] add tests for circular references. #2

Commits

  • [Refactor] don't attempt to run iterable comparisons when there's no Symbol.iterator. 8e34291
  • [Fix] ignore function name when comparing in engines that lack the "name" property (IE) d222ba0
  • [Tests] relocate native tests. 504a8cb
  • [Tests] Separate shimmed from native tests. 078e64a
  • [Fix] normalize function signature whitespace, for IE 9. 3e0df7b
  • [Tests] Only skip generic iterable tests when there's no Symbol.iterator. b8ef004

v1.3.0 - 2015-12-09

Fixed

  • [New] add support for comparing iterables, including native or es6-shimmed Map and Set. #1

Commits

  • [Dev Deps] update tape, jscs, semver, eslint, @ljharb/eslint-config, nsp 8bbacb7
  • [Refactor] Use object.entries to compare objects instead of for loops. 2517c21
  • [Dev Deps] update tape, jscs, eslint, @ljharb/eslint-config e4b11ef
  • [Tests] fix npm upgrades for older nodes cb98523
  • [Dev Deps] update jscs, eslint, nsp f1f2b1b
  • [Tests] up to node v5.1 2093e30
  • [Deps] update is-callable c3c0669
  • [Deps] update is-callable 241f8e5
  • [Tests] ensure node 0.8 doesn't fail. 6ac38fe

v1.2.4 - 2015-09-27

Commits

  • Update tape, jscs, semver. Add npm run eslint and npm run security. 539df80
  • Update eslint, tape, semver; use my personal shared eslint config. d20d796
  • Update eslint 114b87b
  • All grade A-supported node/iojs versions now ship with an npm that understands ^. da9eedf
  • Update tape, jscs, eslint, @ljharb/eslint-config 8a1b2b9
  • Update covert, jscs, eslint, semver 6ad9c2b
  • [Dev Deps] update tape, jscs, make-arrow-function, semver, eslint, @ljharb/eslint-config, nsp 2829e84
  • Update eslint, semver, nsp 00c1c6c
  • [Fix] Boxed Symbols should be coerced to primitives before testing for equality. 0ed5277
  • Use is-boolean-object. ba4dcee
  • Test on latest io.js e7ee752
  • [Tests] up to io.js v3.3, node v4.1 41489a0
  • [Dev Deps] update jscs 393bf3f
  • Test up to io.js v2.3 cdbc4e0
  • Test up to io.js v2.1 2a86466
  • [Deps] update is-arrow-function, is-date-object c598d44
  • [Dev Deps] Update tape, eslint 63da2af
  • Update make-generator-function, semver ff5ee98
  • Fix make release 4ac1349
  • [Dev Deps] update tape b9caa6b
  • Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG. 8f3fcaa
  • Test on io.js v2.5 3503609
  • Test on io.js v2.4 3b41559
  • Updating semver 52706a3
  • Test on io.js v3.0 2e14995

v1.2.3 - 2015-02-06

Commits

  • Update is-callable, is-number-object, is-regex, is-string 314891e
  • Run travis-ci tests on iojs and node v0.12; speed up builds; allow 0.8 failures. 6d78102
  • Update is-generator-function, tape, jscs 2fa7c6f

v1.2.2 - 2015-01-29

Commits

  • Update is-arrow-function, is-callable, is-number-object, is-string bf05888

v1.2.1 - 2015-01-29

Commits

  • Use is-string and is-callable modules. 0769199

v1.2.0 - 2015-01-28

Commits

  • make release c6186d4
  • Use is-regex/is-date-object/is-number-object to properly check RegExps/Dates/Numbers, despite @@toStringTag. c0be34d
  • Use try/catch for a more reliable isFunction check, even with ES6 @@toStringTag c7c47c1
  • Use try/catch for a more reliable isString check, even with ES6 @@toStringTag 2e64fe6
  • Use try/catch for a more reliable isBoolean check, even with ES6 @@toStringTag 612bf6b
  • Improve Array checks to avoid checking Object#toString when possible. 4617222
  • Remove [object Object] checking. bc96071
  • Add an early return for null/undefined f00381b

v1.1.1 - 2015-01-20

Commits

  • Fix generator functions in newer v8 / io.js. 9e907dd
  • Update is-generator-function, tape, jscs b1828a6
  • toString is a reserved word in older browsers. c9577e4
  • Update jscs aeb3ff8
  • Update is-arrow-function, is-generator-function 64676e4

v1.1.0 - 2014-12-15

Commits

  • Using my standard jscs.json file e180beb
  • Adding npm run lint 69d590e
  • Adding tests and support for comparing generators. fb03635
  • Adding tests and support for comparing arrow functions. 57c719d
  • Consider functions "equal" if type, name, arity, and body are equal. 6622d56
  • Add tests for Symbols. 5aea5b6
  • Adding license and downloads badges 815cdda
  • Adding forEach and copyFunction helpers for tests. f5d7190
  • Using consistent quotes e756817
  • Use SVG instead of PNG badges 8f7995f
  • Removing this unnecessary test line, and refactoring up hasSymbols. 95218d6
  • Update tape, jscs 3f254eb
  • Update tape, jscs 080a913
  • Run tests with --harmony. 5311996
  • Update tape 0f81bc4
  • Lock covert to v1.0.0. 39c0281
  • Updating tape d31472d
  • Update jscs aea1c63
  • Updating jscs 34fe2e3
  • Run linter as part of tests 4c7efb0
  • Updating covert cd6abb5

v1.0.0 - 2014-08-08

Commits

v0.1.0 - 2014-03-23

Commits

  • Adding support for boxed primitives a074e04
  • Use hasOwnProperty instead of "in". 909f259
  • Trying the parent/child disqualification again. 34aa425
  • proto may be a reserved word in ES3 ebe9113
  • Updating dependencies 675fc60
  • Oops, fixing mixed spaces and tabs 34f6860
  • Updating tape 5d52e87
  • Testing node 0.6 again 6feb16d
  • Faking the constructor. Yay JS inheritance! b899f88

v0.0.0 - 2014-01-19

Commits

  • Tests. a52f527
  • Implementation. 2669d7e
  • package.json 6608349
  • read me 6626f5d
  • Initial commit 16dea8f
  • Adding a getPrototypeOf shim 3c59ef9
  • Firefox <= 16 elides comments from a function's string representation. 35d22cf
  • Check function lengths as well for equality. e944591
  • Travis CI dd86cc1
  • Trying to return Object.prototype in IE when none is found 233aca3
  • Temporarily commenting out this test. a0d3efd
  • Trying to ensure later Opera versions are tested cc1ff14
  • Instead of relying on "this", check an empty object. fbf110a
  • Optimization for array comparison 0169b55