@@ -11,14 +11,33 @@ jsonDiff.useLongestToken = true;
11
11
12
12
jsonDiff . tokenize = lineDiff . tokenize ;
13
13
jsonDiff . castInput = function ( value ) {
14
- return typeof value === 'string' ? value : JSON . stringify ( canonicalize ( value ) , undefined , ' ' ) ;
14
+ const { undefinedReplacement} = this ;
15
+
16
+ return typeof value === 'string' ? value : JSON . stringify ( canonicalize ( value ) , function ( k , v ) {
17
+ if ( typeof v === 'undefined' ) {
18
+ return undefinedReplacement ;
19
+ }
20
+
21
+ return v ;
22
+ } , ' ' ) ;
15
23
} ;
16
24
jsonDiff . equals = function ( left , right ) {
17
25
return Diff . prototype . equals ( left . replace ( / , ( [ \r \n ] ) / g, '$1' ) , right . replace ( / , ( [ \r \n ] ) / g, '$1' ) ) ;
18
26
} ;
19
27
20
- export function diffJson ( oldObj , newObj , callback ) { return jsonDiff . diff ( oldObj , newObj , callback ) ; }
28
+ export function diffJson ( oldObj , newObj , options , callback ) {
29
+ if ( typeof options === 'function' ) {
30
+ callback = options ;
31
+ options = { } ;
32
+ }
21
33
34
+ if ( typeof options === 'undefined' ) {
35
+ options = { } ;
36
+ }
37
+
38
+ jsonDiff . undefinedReplacement = options . undefinedReplacement ;
39
+ return jsonDiff . diff ( oldObj , newObj , callback ) ;
40
+ }
22
41
23
42
// This function handles the presence of circular references by bailing out when encountering an
24
43
// object that is already on the "stack" of items being processed.
0 commit comments