@bybrave/fast-deep-equal2 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Evgeny Poberezkin
4
+ Copyright (c) 2026 bybrave (maintained fork @bybrave/fast-deep-equal2)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # @bybrave/fast-deep-equal2
2
+
3
+ Maintained, drop-in fork of [`fast-deep-equal`](https://github.com/epoberezkin/fast-deep-equal) — the fastest deep-equality check for JavaScript.
4
+
5
+ The original has had no release since 2020 (`3.1.3`) while still pulling ~710M downloads/month. This fork fixes the null-prototype crash, adds a circular-safe variant, folds Map/Set/TypedArray support into the default function, and ships ESM plus improved bundled types.
6
+
7
+ ```sh
8
+ npm install @bybrave/fast-deep-equal2
9
+ ```
10
+
11
+ ```js
12
+ const equal = require('@bybrave/fast-deep-equal2'); // CommonJS
13
+ import equal from '@bybrave/fast-deep-equal2'; // ESM
14
+ import { equal, react, circular } from '@bybrave/fast-deep-equal2';
15
+
16
+ equal({ a: 1, b: [2, 3] }, { a: 1, b: [2, 3] }); // true
17
+ ```
18
+
19
+ The default `equal(a, b)` is the same fast function as upstream, and remains a TypeScript type guard (`a is T`). Map, Set, TypedArray and BigInt are compared out of the box — no separate `es6` entry needed.
20
+
21
+ ## What's fixed
22
+
23
+ | Issue | Problem | Fix |
24
+ |---|---|---|
25
+ | [#49](https://github.com/epoberezkin/fast-deep-equal/issues/49) / [#111](https://github.com/epoberezkin/fast-deep-equal/issues/111) | Comparing objects created with `Object.create(null)` threw `a.valueOf is not a function` (21+ 👍). | `valueOf`/`toString` are only called when the object actually overrides them and they're callable — null-prototype objects compare by their own keys instead. |
26
+ | [#17](https://github.com/epoberezkin/fast-deep-equal/issues/17) | Circular references caused a `RangeError` (stack overflow). | New `circular` export tracks visited pairs and handles cycles. The default `equal` stays allocation-free and fast. |
27
+ | [#81](https://github.com/epoberezkin/fast-deep-equal/issues/81) | Type fixes weren't shipped. | Bundled, improved types (default + `react` + `circular`), verified with `tsc --strict`. |
28
+ | — | Map/Set/TypedArray lived in a separate `es6` entry. | Folded into the default function (Node 18+ has them). |
29
+
30
+ ## Exports
31
+
32
+ - **`equal(a, b)`** (default) — fast deep equality, Map/Set/TypedArray/BigInt aware, null-prototype safe. Throws on circular references (use `circular` for those).
33
+ - **`circular(a, b)`** — same, but safe against circular references (tracks visited object pairs; slightly slower).
34
+ - **`react(a, b)`** — ignores React elements' circular `_owner`. Also available as the subpath `@bybrave/fast-deep-equal2/react` for drop-in parity with `fast-deep-equal/react`.
35
+
36
+ ## Migration from `fast-deep-equal`
37
+
38
+ Replace the dependency and the import. `equal` behaves the same, except comparing `Object.create(null)` objects now works instead of throwing. If you imported `fast-deep-equal/es6`, just use the default — Map/Set/TypedArray are built in. `fast-deep-equal/react` → `@bybrave/fast-deep-equal2/react`.
39
+
40
+ ## Support
41
+
42
+ If this package saves you time, you can support maintenance:
43
+
44
+ [![Ko-fi](https://img.shields.io/badge/Ko--fi-buy%20me%20a%20coffee-FF5E5B?logo=kofi&logoColor=white)](https://ko-fi.com/bybrave)
45
+ [![Bitcoin](https://img.shields.io/badge/Bitcoin-BTC-F7931A?logo=bitcoin&logoColor=white)](#support)
46
+
47
+ Bitcoin (BTC): `bc1q37557q5jpeaxqydzwvf3jgj7zhnfpn2td3q40q`
48
+
49
+ ## Credits & license
50
+
51
+ MIT, same as the original — see [LICENSE](./LICENSE).
52
+ Based on [fast-deep-equal](https://github.com/epoberezkin/fast-deep-equal) by Evgeny Poberezkin.
package/dist/index.cjs ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // index.js
21
+ var fast_deep_equal2_exports = {};
22
+ __export(fast_deep_equal2_exports, {
23
+ circular: () => circular,
24
+ default: () => fast_deep_equal2_default,
25
+ equal: () => equal,
26
+ react: () => react
27
+ });
28
+ module.exports = __toCommonJS(fast_deep_equal2_exports);
29
+ function build(react2, cycles) {
30
+ return function equal2(a, b, seen) {
31
+ if (a === b) return true;
32
+ if (a && b && typeof a == "object" && typeof b == "object") {
33
+ if (a.constructor !== b.constructor) return false;
34
+ var length, i, keys;
35
+ if (cycles) {
36
+ if (!seen) seen = /* @__PURE__ */ new WeakMap();
37
+ var seenB = seen.get(a);
38
+ if (seenB) {
39
+ if (seenB.has(b)) return true;
40
+ seenB.add(b);
41
+ } else {
42
+ seenB = /* @__PURE__ */ new WeakSet();
43
+ seenB.add(b);
44
+ seen.set(a, seenB);
45
+ }
46
+ }
47
+ if (Array.isArray(a)) {
48
+ length = a.length;
49
+ if (length != b.length) return false;
50
+ for (i = length; i-- !== 0; )
51
+ if (!equal2(a[i], b[i], seen)) return false;
52
+ return true;
53
+ }
54
+ if (a instanceof Map && b instanceof Map) {
55
+ if (a.size !== b.size) return false;
56
+ for (i of a.entries())
57
+ if (!b.has(i[0])) return false;
58
+ for (i of a.entries())
59
+ if (!equal2(i[1], b.get(i[0]), seen)) return false;
60
+ return true;
61
+ }
62
+ if (a instanceof Set && b instanceof Set) {
63
+ if (a.size !== b.size) return false;
64
+ for (i of a.entries())
65
+ if (!b.has(i[0])) return false;
66
+ return true;
67
+ }
68
+ if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
69
+ length = a.length;
70
+ if (length != b.length) return false;
71
+ for (i = length; i-- !== 0; )
72
+ if (a[i] !== b[i]) return false;
73
+ return true;
74
+ }
75
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
76
+ if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf === "function")
77
+ return a.valueOf() === b.valueOf();
78
+ if (a.toString !== Object.prototype.toString && typeof a.toString === "function")
79
+ return a.toString() === b.toString();
80
+ keys = Object.keys(a);
81
+ length = keys.length;
82
+ if (length !== Object.keys(b).length) return false;
83
+ for (i = length; i-- !== 0; )
84
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
85
+ for (i = length; i-- !== 0; ) {
86
+ var key = keys[i];
87
+ if (react2 && key === "_owner" && a.$$typeof) {
88
+ continue;
89
+ }
90
+ if (!equal2(a[key], b[key], seen)) return false;
91
+ }
92
+ return true;
93
+ }
94
+ return a !== a && b !== b;
95
+ };
96
+ }
97
+ var equal = build(false, false);
98
+ var react = build(true, false);
99
+ var circular = build(false, true);
100
+ var fast_deep_equal2_default = equal;
101
+ // Annotate the CommonJS export names for ESM import in node:
102
+ 0 && (module.exports = {
103
+ circular,
104
+ equal,
105
+ react
106
+ });
107
+ if(module.exports.default)module.exports=Object.assign(module.exports.default,module.exports);
package/dist/react.cjs ADDED
@@ -0,0 +1,106 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // react.js
20
+ var react_exports = {};
21
+ __export(react_exports, {
22
+ default: () => react_default,
23
+ react: () => react
24
+ });
25
+ module.exports = __toCommonJS(react_exports);
26
+
27
+ // index.js
28
+ function build(react2, cycles) {
29
+ return function equal2(a, b, seen) {
30
+ if (a === b) return true;
31
+ if (a && b && typeof a == "object" && typeof b == "object") {
32
+ if (a.constructor !== b.constructor) return false;
33
+ var length, i, keys;
34
+ if (cycles) {
35
+ if (!seen) seen = /* @__PURE__ */ new WeakMap();
36
+ var seenB = seen.get(a);
37
+ if (seenB) {
38
+ if (seenB.has(b)) return true;
39
+ seenB.add(b);
40
+ } else {
41
+ seenB = /* @__PURE__ */ new WeakSet();
42
+ seenB.add(b);
43
+ seen.set(a, seenB);
44
+ }
45
+ }
46
+ if (Array.isArray(a)) {
47
+ length = a.length;
48
+ if (length != b.length) return false;
49
+ for (i = length; i-- !== 0; )
50
+ if (!equal2(a[i], b[i], seen)) return false;
51
+ return true;
52
+ }
53
+ if (a instanceof Map && b instanceof Map) {
54
+ if (a.size !== b.size) return false;
55
+ for (i of a.entries())
56
+ if (!b.has(i[0])) return false;
57
+ for (i of a.entries())
58
+ if (!equal2(i[1], b.get(i[0]), seen)) return false;
59
+ return true;
60
+ }
61
+ if (a instanceof Set && b instanceof Set) {
62
+ if (a.size !== b.size) return false;
63
+ for (i of a.entries())
64
+ if (!b.has(i[0])) return false;
65
+ return true;
66
+ }
67
+ if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
68
+ length = a.length;
69
+ if (length != b.length) return false;
70
+ for (i = length; i-- !== 0; )
71
+ if (a[i] !== b[i]) return false;
72
+ return true;
73
+ }
74
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
75
+ if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf === "function")
76
+ return a.valueOf() === b.valueOf();
77
+ if (a.toString !== Object.prototype.toString && typeof a.toString === "function")
78
+ return a.toString() === b.toString();
79
+ keys = Object.keys(a);
80
+ length = keys.length;
81
+ if (length !== Object.keys(b).length) return false;
82
+ for (i = length; i-- !== 0; )
83
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
84
+ for (i = length; i-- !== 0; ) {
85
+ var key = keys[i];
86
+ if (react2 && key === "_owner" && a.$$typeof) {
87
+ continue;
88
+ }
89
+ if (!equal2(a[key], b[key], seen)) return false;
90
+ }
91
+ return true;
92
+ }
93
+ return a !== a && b !== b;
94
+ };
95
+ }
96
+ var equal = build(false, false);
97
+ var react = build(true, false);
98
+ var circular = build(false, true);
99
+
100
+ // react.js
101
+ var react_default = react;
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ react
105
+ });
106
+ if(module.exports.default)module.exports=Object.assign(module.exports.default,module.exports);
package/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ declare function equal<T>(a: any, b: T): a is T;
2
+
3
+ export default equal;
4
+ export {equal};
5
+
6
+ /**
7
+ * Deep equality that ignores React elements' circular `_owner` field.
8
+ */
9
+ export function react<T>(a: any, b: T): a is T;
10
+
11
+ /**
12
+ * Deep equality that is safe against circular references (tracks visited
13
+ * object pairs). Slightly slower than the default `equal`.
14
+ */
15
+ export function circular<T>(a: any, b: T): a is T;
package/index.js ADDED
@@ -0,0 +1,109 @@
1
+ 'use strict';
2
+
3
+ var envHasBigInt64Array = typeof BigInt64Array !== 'undefined';
4
+
5
+ // Build a deep-equality function with compile-time flags baked in, so the hot
6
+ // path carries no per-call option overhead. `react` skips React elements'
7
+ // circular `_owner`; `cycles` tracks visited object pairs to survive circular
8
+ // references (#17).
9
+ function build(react, cycles) {
10
+ return function equal(a, b, seen) {
11
+ if (a === b) return true;
12
+
13
+ if (a && b && typeof a == 'object' && typeof b == 'object') {
14
+ if (a.constructor !== b.constructor) return false;
15
+
16
+ var length, i, keys;
17
+
18
+ if (cycles) {
19
+ if (!seen) seen = new WeakMap();
20
+ var seenB = seen.get(a);
21
+ if (seenB) {
22
+ // If we've already started comparing this pair, assume equal to break
23
+ // the cycle; a real mismatch elsewhere will still surface.
24
+ if (seenB.has(b)) return true;
25
+ seenB.add(b);
26
+ } else {
27
+ seenB = new WeakSet();
28
+ seenB.add(b);
29
+ seen.set(a, seenB);
30
+ }
31
+ }
32
+
33
+ if (Array.isArray(a)) {
34
+ length = a.length;
35
+ if (length != b.length) return false;
36
+ for (i = length; i-- !== 0;)
37
+ if (!equal(a[i], b[i], seen)) return false;
38
+ return true;
39
+ }
40
+
41
+ if ((a instanceof Map) && (b instanceof Map)) {
42
+ if (a.size !== b.size) return false;
43
+ for (i of a.entries())
44
+ if (!b.has(i[0])) return false;
45
+ for (i of a.entries())
46
+ if (!equal(i[1], b.get(i[0]), seen)) return false;
47
+ return true;
48
+ }
49
+
50
+ if ((a instanceof Set) && (b instanceof Set)) {
51
+ if (a.size !== b.size) return false;
52
+ for (i of a.entries())
53
+ if (!b.has(i[0])) return false;
54
+ return true;
55
+ }
56
+
57
+ if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
58
+ length = a.length;
59
+ if (length != b.length) return false;
60
+ for (i = length; i-- !== 0;)
61
+ if (a[i] !== b[i]) return false;
62
+ return true;
63
+ }
64
+
65
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
66
+ // Only defer to valueOf/toString when the object actually overrides them
67
+ // AND they are callable — objects created with `Object.create(null)` have
68
+ // neither, and calling a missing valueOf used to throw (#49/#111).
69
+ if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf === 'function')
70
+ return a.valueOf() === b.valueOf();
71
+ if (a.toString !== Object.prototype.toString && typeof a.toString === 'function')
72
+ return a.toString() === b.toString();
73
+
74
+ keys = Object.keys(a);
75
+ length = keys.length;
76
+ if (length !== Object.keys(b).length) return false;
77
+
78
+ for (i = length; i-- !== 0;)
79
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
80
+
81
+ for (i = length; i-- !== 0;) {
82
+ var key = keys[i];
83
+
84
+ if (react && key === '_owner' && a.$$typeof) {
85
+ // React elements' _owner contains circular references and is not part
86
+ // of the element's identity.
87
+ continue;
88
+ }
89
+
90
+ if (!equal(a[key], b[key], seen)) return false;
91
+ }
92
+
93
+ return true;
94
+ }
95
+
96
+ // true if both NaN, false otherwise
97
+ return a !== a && b !== b;
98
+ };
99
+ }
100
+
101
+ // eslint keeps envHasBigInt64Array referenced for parity with upstream's es6 build.
102
+ void envHasBigInt64Array;
103
+
104
+ var equal = build(false, false);
105
+ var react = build(true, false);
106
+ var circular = build(false, true);
107
+
108
+ export default equal;
109
+ export {equal, react, circular};
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@bybrave/fast-deep-equal2",
3
+ "version": "4.0.0",
4
+ "description": "Maintained fork of fast-deep-equal — fast deep equality with the null-prototype crash fixed (#49), a circular-safe variant (#17), Map/Set/TypedArray support built in, ESM, and bundled types",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./index.js",
8
+ "types": "./index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "import": "./index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./react": {
16
+ "types": "./react.d.ts",
17
+ "import": "./react.js",
18
+ "require": "./dist/react.cjs"
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "files": ["index.js", "index.d.ts", "react.js", "react.d.ts", "dist/"],
23
+ "scripts": {
24
+ "build": "node build/build.js",
25
+ "test": "node --test test/*.test.js",
26
+ "test-types": "tsc --noEmit --strict test/type-declarations.ts",
27
+ "prepublishOnly": "npm run build"
28
+ },
29
+ "repository": {"type": "git", "url": "git+https://github.com/bybraveHQ/fast-deep-equal2.git"},
30
+ "bugs": {"url": "https://github.com/bybraveHQ/fast-deep-equal2/issues"},
31
+ "homepage": "https://github.com/bybraveHQ/fast-deep-equal2#readme",
32
+ "keywords": ["fast", "deep", "equal", "equality", "compare", "deepequal", "circular", "react", "esm", "typescript"],
33
+ "author": "bybrave (https://github.com/bybraveHQ)",
34
+ "contributors": ["Evgeny Poberezkin (author of the original fast-deep-equal)"],
35
+ "license": "MIT",
36
+ "funding": "https://ko-fi.com/bybrave",
37
+ "engines": {"node": ">=18"},
38
+ "devDependencies": {"@types/node": "^20.14.0", "esbuild": "^0.23.0", "typescript": "^5.5.0"}
39
+ }
package/react.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare function equalReact<T>(a: any, b: T): a is T;
2
+ export default equalReact;
3
+ export {equalReact as react};
package/react.js ADDED
@@ -0,0 +1,3 @@
1
+ import {react} from './index.js';
2
+ export default react;
3
+ export {react};