From 7ae082161ce57af1875c1e21ef0149249ca58a58 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 5 Oct 2017 21:27:46 -0700 Subject: [PATCH] util,assert: expose util.isDeepStrictEqual() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Provide `util.isDeepStrictEqual()` that works like `assert.deepStrictEqual()` but returns a boolean rather than throwing an error. Several userland modules have needed this functionality and implemented it independently. This functionality already exists in Node.js core, so this exposes it for use by modules. Modules that have needed this functionality include `lodash`, `concordance` (used by `ava`), and `qunit`. PR-URL: https://github.com/nodejs/node/pull/16084 Reviewed-By: James M Snell Reviewed-By: Evan Lucas Reviewed-By: Joyee Cheung Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig Reviewed-By: Michaƫl Zasso Reviewed-By: Jeremiah Senkpiel Reviewed-By: Ali Ijaz Sheikh Reviewed-By: Ruben Bridgewater --- doc/api/assert.md | 2 +- doc/api/util.md | 16 + lib/assert.js | 509 +----------------- lib/internal/util/comparisons.js | 516 +++++++++++++++++++ lib/util.js | 5 + node.gyp | 1 + test/parallel/test-util-isDeepStrictEqual.js | 483 +++++++++++++++++ 7 files changed, 1028 insertions(+), 504 deletions(-) create mode 100644 lib/internal/util/comparisons.js create mode 100644 test/parallel/test-util-isDeepStrictEqual.js diff --git a/doc/api/assert.md b/doc/api/assert.md index 6179caa27f..4da3e15125 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -134,7 +134,7 @@ changes: * `expected` {any} * `message` {any} -Similar to `assert.deepEqual()` with the following exceptions: +Identical to [`assert.deepEqual()`][] with the following exceptions: 1. Primitive values besides `NaN` are compared using the [Strict Equality Comparison][] ( `===` ). Set and Map values, Map keys and `NaN` are compared diff --git a/doc/api/util.md b/doc/api/util.md index 6619ee2ad6..b13d02a8c0 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -455,6 +455,21 @@ util.inspect.defaultOptions.maxArrayLength = null; console.log(arr); // logs the full array ``` +## util.isDeepStrictEqual(val1, val2) + + +* `val1` {any} +* `val2` {any} +* Returns: {string} + +Returns `true` if there is deep strict equality between `val` and `val2`. +Otherwise, returns `false`. + +See [`assert.deepStrictEqual()`][] for more information about deep strict +equality. + ## util.promisify(original)