@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

    111

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    2.46 kB

    Total Files

    3

    Last publish

    Collaborators

    • omrilotan