JSPM

@does/sortby

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q28767F
  • License MIT

⚔️ Sort array of objects by key or function

Package Exports

  • @does/sortby

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 (@does/sortby) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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