Skip to content

Commit

Permalink
if in strict mode, constructor must match
Browse files Browse the repository at this point in the history
  • Loading branch information
planttheidea committed Feb 26, 2023
1 parent c2815f1 commit a0d3e9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<img src="https://img.shields.io/badge/coverage-100%25-brightgreen.svg"/>
<img src="https://img.shields.io/badge/license-MIT-blue.svg"/>

Perform [blazing fast](#benchmarks) equality comparisons (either deep or shallow) on two objects passed. It has no dependencies, and is ~1.64kB when minified and gzipped.
Perform [blazing fast](#benchmarks) equality comparisons (either deep or shallow) on two objects passed. It has no dependencies, and is ~1.75kB when minified and gzipped.

Unlike most equality validation libraries, the following types are handled out-of-the-box:

Expand Down Expand Up @@ -162,6 +162,7 @@ console.log(circularShallowEqual(array, [array])); // false

Performs the same comparison as `deepEqual` but performs a strict comparison of the objects. In this includes:

- Checking constructors match
- Checking non-enumerable properties in object comparisons
- Checking full descriptor of properties on the object to match
- Checking non-index properties on arrays
Expand Down
4 changes: 4 additions & 0 deletions src/comparator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export function createComparator<Meta>({
return a !== a && b !== b;
}

if (state.strict && a.constructor !== b.constructor) {
return false;
}

// Checks are listed in order of commonality of use-case:
// 1. Common complex object types (plain object, array)
// 2. Common data values (date, regexp)
Expand Down

0 comments on commit a0d3e9c

Please sign in to comment.