You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -612,3 +613,59 @@ If a content line is empty, then the corresponding comparison line is automatica
612
613
|`aIndicator`|`'-·'`|`'-'`|
613
614
|`bIndicator`|`'+·'`|`'+'`|
614
615
|`commonIndicator`|`' ·'`|`''`|
616
+
617
+
### Example of option for sorting object keys
618
+
619
+
When two objects are compared their keys are printed in alphabetical order by default. If this was not the original order of the keys the diff becomes harder to read as the keys are not in their original position.
620
+
621
+
Use `compareKeys` to pass a function which will be used when sorting the object keys.
622
+
623
+
```js
624
+
consta= {c:'c', b:'b1', a:'a'};
625
+
constb= {c:'c', b:'b2', a:'a'};
626
+
627
+
constoptions= {
628
+
// The keys will be in their original order
629
+
compareKeys: () =>0,
630
+
};
631
+
632
+
constdifference=diff(a, b, options);
633
+
```
634
+
635
+
```diff
636
+
- Expected
637
+
+ Received
638
+
639
+
Object {
640
+
"c": "c",
641
+
- "b": "b1",
642
+
+ "b": "b2",
643
+
"a": "a",
644
+
}
645
+
```
646
+
647
+
Depending on the implementation of `compareKeys` any sort order can be used.
0 commit comments