Passed
Push — task/update-profile-experience ( 897bfe...e35027 )
by Tristan
06:27
created

resources/assets/js/helpers/deepEquals.ts   A

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 41
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 28
mnd 2
bc 2
fnc 2
dl 0
loc 41
rs 10
bpm 1
cpm 2
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A deepEquals.ts ➔ deepEquals 0 3 1
A deepEquals.ts ➔ deepEqualsDebug 0 31 3
1
import isEqualWith from "lodash/isEqualWith";
2
import isEqual from "lodash/isEqual";
3
4
export function deepEquals(object: any, other: any): boolean {
5
  return isEqual(object, other);
6
}
7
8
/**
9
 * Logs to console any values which are not equal.
10
 * DO NOT USE IN PRODUCTION.
11
 */
12
function deepEqualsDebug(object: any, other: any): boolean {
13
  const debugCompare = (a, b, key) => {
14
    const equality = isEqual(a, b);
15
    if (!equality) {
16
      console.debug(`The values at key/index ${key} were not equal:`, a, b);
17
    }
18
    return equality;
19
  };
20
  if (
21
    typeof object === "object" &&
22
    typeof other === "object" &&
23
    object !== null &&
24
    other !== null
25
  ) {
26
    return (
27
      debugCompare(
28
        Object.keys(object).length,
29
        Object.keys(other).length,
30
        "length",
31
      ) &&
32
      Object.keys(object).every((key) =>
33
        debugCompare(object[key], other[key], key),
34
      )
35
    );
36
  }
37
  return isEqualWith(object, other, debugCompare);
38
}
39
40
export default deepEquals;
41