Sorting comparators so you don't have to remember what to substract from what
npm i @iamnapo/sort
import { numberSmallToLarge } from "@iamnapo/sort";
[12, -42, -Infinity, 123, Number.NaN].sort(numberSmallToLarge());
//=> [Number.NaN, -Infinity, -42, 12, 123]
[{ name: "Mary", age: 20 }, { name: "Bob", age: 30 }, { name: "Napoleon", age: 26 }].sort(numberSmallToLarge((p) => p.age));
//=> [{ name: "Mary", age: 20 }, { name: "Napoleon", age: 26 }, { name: "Bob", age: 30 }];
Ascending sort comparator for numbers.
Descending sort comparator for numbers.
Ascending sort comparator for Dates.
Descending sort comparator for Dates.
Ascending sort comparator for strings.
Descending sort comparator for strings.
Case-insensitive ascending sort comparator for strings.
Note: In case of equality, a case-sensitive comparison is the tie-breaker.
Case-insensitive descending sort comparator for strings.
Note: In case of equality, a case-sensitive comparison is the tie-breaker.
Type: function
Default: (v) => v
Function used to extract each value to compare.