Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ var hasArrayBuffer = typeof ArrayBuffer === 'function' && !!ArrayBuffer.isView;

// Note: We **don't** need `envHasBigInt64Array` in fde es6/index.js

/**
* @param {any} a
* @param {any} b
* @returns {boolean}
*/
function equal(a, b) {
// START: fast-deep-equal es6/index.js 3.1.3
if (a === b) return true;
Expand Down Expand Up @@ -61,7 +66,14 @@ function equal(a, b) {
}
// END: Modifications

if (hasArrayBuffer && ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
// Types: the casts stop `isView()` narrowing `a` and `b` to
// `ArrayBufferView`, which has no `length` or index signature (typed
// arrays have both, a `DataView` has neither).
if (
hasArrayBuffer &&
ArrayBuffer.isView(/** @type {unknown} */ (a)) &&
ArrayBuffer.isView(/** @type {unknown} */ (b))
) {
length = a.length;
if (length != b.length) return false;
for (i = length; i-- !== 0;) if (a[i] !== b[i]) return false;
Expand Down Expand Up @@ -130,10 +142,19 @@ function equal(a, b) {
}
// end fast-deep-equal

/**
* Deep equality check, tuned for React elements.
*
* @template [A=any]
* @template [B=any]
* @param {A} a
* @param {B} b
* @returns {boolean}
*/
module.exports = function isEqual(a, b) {
try {
return equal(a, b);
} catch (error) {
} catch (/** @type {any} */ error) {
if ((error.message || '').match(/stack|recursion/i)) {
// warn on circular references, don't crash
// browsers give this different errors name and messages:
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
"typings": "index.d.ts",
"scripts": {
"preversion": "pnpm check",
"check": "pnpm format && pnpm lint && pnpm test && pnpm pack:check",
"check": "pnpm format && pnpm lint && pnpm types:check && pnpm test && pnpm pack:check",
"benchmark": "node benchmark",
"format": "oxfmt --check",
"format:fix": "oxfmt",
"lint": "oxlint --report-unused-disable-directives-severity=error",
"lint:fix": "oxlint --report-unused-disable-directives-severity=error --fix",
"types:check": "node scripts/types-check.mjs",
"test-browser": "karma start test/browser/karma.conf.js",
"test-node": "mocha \"test/node/*.spec.js\"",
"test-node-cov": "nyc mocha \"test/node/*.spec.js\"",
"test-ts-usage": "tsc --esModuleInterop --jsx react --noEmit test/typescript/sample-react-redux-usage.tsx test/typescript/sample-usage.tsx",
"test-ts-defs": "tsc --target ES5 index.d.ts",
"test-ts-usage": "tsc --ignoreConfig --esModuleInterop --jsx react --noEmit test/typescript/sample-react-redux-usage.tsx test/typescript/sample-usage.tsx",
"test-ts-defs": "tsc --ignoreConfig --noEmit index.d.ts",
"test": "builder concurrent --buffer test-ts-usage test-ts-defs test-node-cov test-browser",
"compress": "terser --compress --mangle=\"toplevel:true\" -- index.js",
"size-min-gz": "pnpm -s compress | gzip -9 | wc -c",
Expand Down Expand Up @@ -86,7 +87,7 @@
"shallow-equal-fuzzy": "0.0.2",
"sinon": "^15.0.1",
"terser": "5.51.2",
"typescript": "^4.9.5",
"typescript": "7.0.2",
"webpack": "^5.76.0"
},
"nyc": {
Expand Down
219 changes: 210 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading