From 39ee3bde15dbaf42a63bf3e4ecd833065bf86b00 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() 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`. --- 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 4a6b06706fa9b9..fa874e916047d3 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 2653c01af1d4c9..5b296decf071ca 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)