@woosh/meep-engine 2.92.3 → 2.92.4

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.
@@ -101296,6 +101296,11 @@ function easeInOutQuad(t) {
101296
101296
  * @returns {boolean}
101297
101297
  */
101298
101298
  function objectDeepEquals(a, b) {
101299
+ if (a === b) {
101300
+ // identity shortcut
101301
+ return true;
101302
+ }
101303
+
101299
101304
  const tA = typeof a;
101300
101305
  const tB = typeof b;
101301
101306
 
@@ -101303,7 +101308,16 @@ function objectDeepEquals(a, b) {
101303
101308
  return false;
101304
101309
  }
101305
101310
 
101306
- if (tA === "object") {
101311
+ if (tA !== "object") {
101312
+ // primitive types, identity equality already checked
101313
+ return false;
101314
+ } else {
101315
+
101316
+ if (a === null || b === null) {
101317
+ // we know that A and B are not the same, so if one of them is a null - there is no possible equality
101318
+ return false;
101319
+ }
101320
+
101307
101321
  if (Array.isArray(a)) {
101308
101322
  // special fast path for arrays
101309
101323
  if (!Array.isArray(b)) {
@@ -101333,8 +101347,6 @@ function objectDeepEquals(a, b) {
101333
101347
 
101334
101348
  return true;
101335
101349
 
101336
- } else {
101337
- return a === b;
101338
101350
  }
101339
101351
  }
101340
101352
 
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.92.3",
8
+ "version": "2.92.4",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1 +1 @@
1
- {"version":3,"file":"objectDeepEquals.d.ts","sourceRoot":"","sources":["../../../../../src/core/model/object/objectDeepEquals.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,oDAFa,OAAO,CA2CnB"}
1
+ {"version":3,"file":"objectDeepEquals.d.ts","sourceRoot":"","sources":["../../../../../src/core/model/object/objectDeepEquals.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,oDAFa,OAAO,CAuDnB"}
@@ -1,5 +1,5 @@
1
- import { isArraysEqualWithComparator } from "../../collection/array/isArraysEqualWithComparator.js";
2
1
  import { isArrayEqualStrict } from "../../collection/array/isArrayEqualStrict.js";
2
+ import { isArraysEqualWithComparator } from "../../collection/array/isArraysEqualWithComparator.js";
3
3
 
4
4
  /**
5
5
  * @template A,B
@@ -8,6 +8,11 @@ import { isArrayEqualStrict } from "../../collection/array/isArrayEqualStrict.js
8
8
  * @returns {boolean}
9
9
  */
10
10
  export function objectDeepEquals(a, b) {
11
+ if (a === b) {
12
+ // identity shortcut
13
+ return true;
14
+ }
15
+
11
16
  const tA = typeof a;
12
17
  const tB = typeof b;
13
18
 
@@ -15,7 +20,16 @@ export function objectDeepEquals(a, b) {
15
20
  return false;
16
21
  }
17
22
 
18
- if (tA === "object") {
23
+ if (tA !== "object") {
24
+ // primitive types, identity equality already checked
25
+ return false;
26
+ } else {
27
+
28
+ if (a === null || b === null) {
29
+ // we know that A and B are not the same, so if one of them is a null - there is no possible equality
30
+ return false;
31
+ }
32
+
19
33
  if (Array.isArray(a)) {
20
34
  // special fast path for arrays
21
35
  if (!Array.isArray(b)) {
@@ -45,7 +59,5 @@ export function objectDeepEquals(a, b) {
45
59
 
46
60
  return true;
47
61
 
48
- } else {
49
- return a === b;
50
62
  }
51
63
  }
@@ -12,3 +12,43 @@ test('objectDeepEquals', () => {
12
12
 
13
13
  expect(objectDeepEquals({ a: 1 }, { a: 1, b: "cat" })).toBe(false);
14
14
  });
15
+
16
+ test("null values", () => {
17
+ expect(objectDeepEquals(null, null)).toBe(true);
18
+ expect(objectDeepEquals(null, {})).toBe(false);
19
+ expect(objectDeepEquals({}, null)).toBe(false);
20
+ });
21
+
22
+ test("same-type primitives", () => {
23
+ expect(objectDeepEquals(1, 1)).toBe(true);
24
+ expect(objectDeepEquals(-1, 1)).toBe(false);
25
+ expect(objectDeepEquals(-1, -1)).toBe(true);
26
+ expect(objectDeepEquals(-1, -3)).toBe(false);
27
+
28
+ expect(objectDeepEquals("cat", "cat")).toBe(true);
29
+ expect(objectDeepEquals("cat", "")).toBe(false);
30
+ expect(objectDeepEquals("", "cat")).toBe(false);
31
+ expect(objectDeepEquals("sat", "cat")).toBe(false);
32
+ expect(objectDeepEquals("cat", "sat")).toBe(false);
33
+
34
+ expect(objectDeepEquals(true, false)).toBe(false);
35
+ expect(objectDeepEquals(false, true)).toBe(false);
36
+ expect(objectDeepEquals(true, true)).toBe(true);
37
+ expect(objectDeepEquals(false, false)).toBe(true);
38
+
39
+ expect(objectDeepEquals(undefined, undefined)).toBe(true);
40
+ });
41
+
42
+ test("mixed primitives", () => {
43
+ expect(objectDeepEquals(1, undefined)).toBe(false);
44
+ expect(objectDeepEquals(undefined, 1)).toBe(false);
45
+
46
+ expect(objectDeepEquals("cat", 1)).toBe(false);
47
+ expect(objectDeepEquals(1, "cat")).toBe(false);
48
+
49
+ expect(objectDeepEquals(1, true)).toBe(false);
50
+ expect(objectDeepEquals(true, 1)).toBe(false);
51
+
52
+ expect(objectDeepEquals("cat", undefined)).toBe(false);
53
+ expect(objectDeepEquals(undefined, "cat")).toBe(false);
54
+ });