Total Complexity | 4 |
Complexity/F | 2 |
Lines of Code | 41 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |