File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -6,18 +6,22 @@ interface Difference {
6
6
interface Options {
7
7
cyclesFix : boolean ;
8
8
}
9
+
9
10
const t = true ;
10
11
const richTypes = { Date : t , RegExp : t , String : t , Number : t } ;
12
+
11
13
export default function diff (
12
14
obj : Record < string , any > | any [ ] ,
13
15
newObj : Record < string , any > | any [ ] ,
14
16
options : Partial < Options > = { cyclesFix : true } ,
15
17
_stack : Record < string , any > [ ] = [ ]
16
18
) : Difference [ ] {
17
19
let diffs : Difference [ ] = [ ] ;
20
+ const isObjArray = Array . isArray ( obj ) ;
21
+
18
22
for ( const key in obj ) {
19
23
const objKey = obj [ key ] ;
20
- const path = Array . isArray ( obj ) ? + key : key ;
24
+ const path = isObjArray ? + key : key ;
21
25
if ( ! ( key in newObj ) ) {
22
26
diffs . push ( {
23
27
type : "REMOVE" ,
@@ -64,11 +68,13 @@ export default function diff(
64
68
} ) ;
65
69
}
66
70
}
71
+
72
+ const isNewObjArray = Array . isArray ( newObj ) ;
67
73
for ( const key in newObj ) {
68
74
if ( ! ( key in obj ) ) {
69
75
diffs . push ( {
70
76
type : "CREATE" ,
71
- path : [ Array . isArray ( newObj ) ? + key : key ] ,
77
+ path : [ isNewObjArray ? + key : key ] ,
72
78
value : newObj [ key ] ,
73
79
} ) ;
74
80
}
You can’t perform that action at this time.
0 commit comments