Package Exports
- cmpby
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cmpby) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
cmpby

Make comparator from key function, less function, or both.
Comparator is a function that given two arguments a and b returns a number that is:
- negative if
aprecedesb; - zero if
aandbare effectively equal; - positive if
bprecedesa.
Comparators are used in such functions as Array.prototype.sort to set up object ordering.
Unfortunately, it is not very pleasant to define such functions, hence this module.
Example
> ['aaa', 'zz', 'd'].sort(cmpby({
less: function (a, b) { return a.length < b.length; }
}))
[ 'd', 'zz', 'aaa' ]API
cmpby([keyfn], [options])
keyfn maps objects to keys.
options.less maps pairs of objects to boolean values.
options.asc controls in what order does comparator order objects (ascending or descending).
| Type | Required? | Default | |
|---|---|---|---|
| keyfn | obj -> key | No | identity |
| options.less | (key1, key2) -> boolean | No | operator |
| options.asc | boolean | No | true |
Install
npm install cmpbyLicense
MIT
