use Intl.Collator over String.prototype.localeCompare for better performance

This commit is contained in:
Germain Souquet 2021-06-02 10:42:17 +01:00
parent c6c1e09cae
commit d7a5547d80
11 changed files with 49 additions and 27 deletions

View file

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { memoize } from "lodash";
/**
* Copy plaintext to user's clipboard
* It will overwrite user's selection range
@ -73,3 +75,14 @@ export function copyNode(ref: Element): boolean {
selectText(ref);
return document.execCommand('copy');
}
const collator = new Intl.Collator();
/**
* Performant language-sensitive string comparison
* @param a the first string to compare
* @param b the second string to compare
*/
export function compare(a: string, b: string): number {
return collator.compare(a, b);
}