Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 9846b1e

Browse files
committed
Optimize default compare function
1 parent a2e0f37 commit 9846b1e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function stableJsonStringify(value: any, compareFn?: CompareFunction | nu
8686
}
8787

8888
else {
89-
compareFn = compareFn ?? defaultCompareKeys;
89+
compareFn = typeof compareFn === 'function' ? compareFn : defaultCompareKeys;
9090

9191
return Array.isArray(value)
9292
? stableSerializeArray(value, compareFn, safe)
@@ -101,6 +101,6 @@ export function stableJsonStringify(value: any, compareFn?: CompareFunction | nu
101101
return;
102102
}
103103

104-
function defaultCompareKeys([keyA]: [string, any], [keyB]: [string, any]) {
105-
return keyA.localeCompare(keyB);
104+
function defaultCompareKeys([keyA]: string[], [keyB]: string[]) {
105+
return keyA > keyB ? 1 : -1;
106106
}

0 commit comments

Comments
 (0)