Skip to content

Commit 3673208

Browse files
committed
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`. PR-URL: #16084 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent e3503ac commit 3673208

File tree

7 files changed

+1028
-504
lines changed

7 files changed

+1028
-504
lines changed

doc/api/assert.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ changes:
134134
* `expected` {any}
135135
* `message` {any}
136136

137-
Similar to `assert.deepEqual()` with the following exceptions:
137+
Identical to [`assert.deepEqual()`][] with the following exceptions:
138138

139139
1. Primitive values besides `NaN` are compared using the [Strict Equality
140140
Comparison][] ( `===` ). Set and Map values, Map keys and `NaN` are compared

doc/api/util.md

+16
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,21 @@ util.inspect.defaultOptions.maxArrayLength = null;
455455
console.log(arr); // logs the full array
456456
```
457457

458+
## util.isDeepStrictEqual(val1, val2)
459+
<!-- YAML
460+
added: REPLACEME
461+
-->
462+
463+
* `val1` {any}
464+
* `val2` {any}
465+
* Returns: {string}
466+
467+
Returns `true` if there is deep strict equality between `val` and `val2`.
468+
Otherwise, returns `false`.
469+
470+
See [`assert.deepStrictEqual()`][] for more information about deep strict
471+
equality.
472+
458473
## util.promisify(original)
459474
<!-- YAML
460475
added: v8.0.0
@@ -1187,6 +1202,7 @@ Deprecated predecessor of `console.log`.
11871202
[`Buffer.isBuffer()`]: buffer.html#buffer_class_method_buffer_isbuffer_obj
11881203
[`Error`]: errors.html#errors_class_error
11891204
[`Object.assign()`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
1205+
[`assert.deepStrictEqual()`]: assert.html#assert_assert_deepstrictequal_actual_expected_message
11901206
[`console.error()`]: console.html#console_console_error_data_args
11911207
[`console.log()`]: console.html#console_console_log_data_args
11921208
[`util.inspect()`]: #util_util_inspect_object_options

0 commit comments

Comments
 (0)