alphanum-compare
Compare function extrated from alphanum-sort. It can be used as compareFunction
in Array.prototype.sort()
.
Install
yarn add alphanum-compare
Usage
import compareFn from "alphanum-compare";
console.log("5".localeCompare("10"));
console.log(compareFn("5", "10"));
console.log(compareFn("-5", "5"));
console.log(compareFn("-5", "5", { sign: true }));
console.log(["item20", "item19", "item1", "item10", "item2"].sort(compareFn));
CodeSandbox
compareFn(a: number | string, b: number | string, opts?: Options): number
It returns a negative value if first argument is less than second argument, zero if they're equal and a positive value otherwise.
Options
License