seq-ord
v0.2.0
Published
`seq-ord` generates the function `(a, b) => 1 | 0 | -1` accepted by `Array#sort()` from complex rules.
Readme
seq-ord
seq-ord generates the function (a, b) => 1 | 0 | -1 accepted by Array#sort() from complex rules.
Examples
import seqOrd, { Rules } from 'seq-ord';
let sortedBooks = books.sort(seqOrd(function* (a, b) {
yield Rules.binary(a.available, b.available);
yield Rules.text(a.title, b.title);
yield Rules.date(a.date, b.date);
}));let sortedBooks = books.sort(seqOrd(function* (a, b) {
yield Rules.binaryExt(
Rules.sequence(function* () { /* both are unavailable */ }),
Rules.sequence(function* () { /* both are available */ })
)(a.available, b.available);
}));Rules
binary– false values firstbinaryExt(<cmp func>, <cmp func>)– allows using different rules for!a && !banda && bdate– older dates firstnumeric– smaller numbers firsttext(., ., locales, options)– useslocaleCompare(locales, options)textCodepoint– uses<and>, lowest codepoint firstsequence(<generator>, <this>)
