npm

Need private packages and team management tools?Check out npm Orgs. »

@does/sortby

1.1.0 • Public • Published

sortby

⚔️ Sort array of objects by key or function

const sortby = require('@does/sortby');
 
sortby(
    [
        {name: 'John', age: 30},
        {name: 'Alfred', age: 10},
        {name: 'Paul', age: 20}
    ],
    'name',
    {
        order: 'desc',
        modify: name => name.toLowerCase()
    }
);
 
/*
 * [
 *  {name: 'Alfred', age: 10},
 *  {name: 'John', age: 30},
 *  {name: 'Paul', age: 20},
 * ]
 */
option type description default example
order {String} asc/desc Order of sorting asc {order: 'desc'}
modify {Function} modify value before sorting a => a {modify: a => a.toLowerCase()}

Transpiled version

Environments which exclude node_modules from the transpiling pipeline should include the "browser" entry instead of "main". This exposes an ES5 commonjs module.

Also available for explicit import:

const sortby = require('@does/sortby/dist');

install

npm i @does/sortby

Downloadsweekly downloads

18

version

1.1.0

license

MIT

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability