README
seq-ord
seq-ord
generates the function (a, b) => 1 | 0 | -1
accepted by Array#sort()
from complex rules.
Examples
import seqOrd from 'seq-ord';
let sortedBooks = books.sort(seqOrd(function* (a, b, rules) {
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, rules) {
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 && !b
anda && b
date
– older dates firstmoment
– treats arguments as Moment.js datesnumeric
– smaller numbers firsttext(., ., locales, options)
– useslocaleCompare(locales, options)
textCodepoint
– uses<
and>
, lowest codepoint firstsequence(<generator>, <this>)