Skip to content

Latest commit

 

History

History

sortby

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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');