@@ -30,18 +30,10 @@ yarn add quick-stable-stringify
3030
3131## Examples
3232
33- Node.JS with CommonJS:
34-
3533``` js
34+ // Node.JS with CommonJS
3635const stringify = require (" quick-stable-stringify" );
37-
38- const obj = { c: 8 , b: [{ z: 6 , y: 5 , x: 4 }, 7 ], a: 3 };
39- console .log (stringify (obj));
40- ```
41-
42- Typescript or modern Javascript environment:
43-
44- ``` ts
36+ // Typescript or modern Javascript environment
4537import stringify from " quick-stable-stringify" ;
4638
4739const obj = { c: 8 , b: [{ z: 6 , y: 5 , x: 4 }, 7 ], a: 3 };
@@ -69,11 +61,11 @@ type ComparatorFunction = (a: KeyValue, b: KeyValue) => number;
6961For example, to sort by the object keys in reverse order:
7062
7163``` js
72- var stringify = require (" quick-stable-stringify" );
64+ const stringify = require (" quick-stable-stringify" );
7365
74- var obj = { c: 8 , b: [{ z: 6 , y: 5 , x: 4 }, 7 ], a: 3 };
75- var s = stringify (obj, function (a , b ) {
76- return a .key < b .key ? 1 : - 1 ;
66+ const obj = { c: 8 , b: [{ z: 6 , y: 5 , x: 4 }, 7 ], a: 3 };
67+ const s = stringify (obj, function (a , b ) {
68+ return a .key < b .key ? 1 : a . key === b . key ? 0 : - 1 ;
7769});
7870console .log (s);
7971```
@@ -87,11 +79,11 @@ which results in the output string:
8779To sort by the object values in reverse order:
8880
8981``` js
90- var stringify = require (" quick-stable-stringify" );
82+ const stringify = require (" quick-stable-stringify" );
9183
92- var obj = { d: 6 , c: 5 , b: [{ z: 3 , y: 2 , x: 1 }, 9 ], a: 10 };
93- var s = stringify (obj, function (a , b ) {
94- return a .value < b .value ? 1 : - 1 ;
84+ const obj = { d: 6 , c: 5 , b: [{ z: 3 , y: 2 , x: 1 }, 9 ], a: 10 };
85+ const s = stringify (obj, function (a , b ) {
86+ return a .value < b .value ? 1 : a . value === b . value ? 0 : - 1 ;
9587});
9688console .log (s);
9789```
0 commit comments