forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace localeCompare with primitive comparison
- Loading branch information
1 parent
f268c39
commit 684d496
Showing
6 changed files
with
42 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Compare two strings in a case-insensitive manner. It is a performance fallback for the built-in String.localeCompare method in Hermes. | ||
* @param a - The first string to compare | ||
* @param b - The second string to compare | ||
* @returns - `1` if first string takes precedence, `-1` if second string takes precedence, `0` if they are equal | ||
*/ | ||
function stringCompare(a: string, b: string): number { | ||
if (a < b) { | ||
return -1; | ||
} | ||
if (a > b) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export default stringCompare; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Compare two strings in a case-insensitive manner. It is a performance fallback for Hermes engine. For other engines, it is a wrapper around the built-in localeCompare method. | ||
* @param a - The first string to compare | ||
* @param b - The second string to compare | ||
* @returns - `1` if first string takes precedence, `-1` if second string takes precedence, `0` if they are equal | ||
*/ | ||
function stringCompare(a: string, b: string): number { | ||
return a.localeCompare(b); | ||
} | ||
|
||
export default stringCompare; |