JSPM

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

Isomorphic, load-anywhere function to sort an array by scalar, deep or computed values in any standard or custom order

Package Exports

  • sort-array
  • sort-array/index.mjs

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

Readme

view on npm npm module downloads Build Status Dependency Status js-standard-style

sort-array

Isomorphic, load-anywhere function to sort an array by scalar, deep or computed values in any standard or custom order.

const sortArray = require('sort-array')

Synopsis

With this data

> DJs = [
  { name: 'Trevor', slot: 'twilight' },
  { name: 'Chris', slot: 'twilight' },
  { name: 'Mike', slot: 'afternoon' },
  { name: 'Rodney', slot: 'morning' },
  { name: 'Chris', slot: 'morning' },
  { name: 'Zane', slot: 'evening' }
]

Sort by slot using an ascending sort type

> sortArray(DJs, { by: 'slot' })
[ { name: 'Mike', slot: 'afternoon' },
  { name: 'Zane', slot: 'evening' },
  { name: 'Chris', slot: 'morning' },
  { name: 'Rodney', slot: 'morning' },
  { name: 'Chris', slot: 'twilight' },
  { name: 'Trevor', slot: 'twilight' } ]

Sort by slot using a descending sort type

> sortArray(DJs, { by: 'slot', order: 'desc' })
[ { name: 'Chris', slot: 'twilight' },
  { name: 'Trevor', slot: 'twilight' },
  { name: 'Chris', slot: 'morning' },
  { name: 'Rodney', slot: 'morning' },
  { name: 'Zane', slot: 'evening' },
  { name: 'Mike', slot: 'afternoon' }]

Sort by slot in a custom order.

> const slotOrder = [ 'morning', 'afternoon', 'evening', 'twilight' ]
> sortArray(DJs, { by: 'slot', order: 'slotOrder', customOrders: { slotOrder } })
[ { name: 'Rodney', slot: 'morning' },
  { name: 'Chris', slot: 'morning' },
  { name: 'Mike', slot: 'afternoon' },
  { name: 'Zane', slot: 'evening' },
  { name: 'Trevor', slot: 'twilight' },
  { name: 'Chris', slot: 'twilight' } ]

sort-array

Isomorphic, load-anywhere function to sort an array by scalar, deep or computed values in any standard or custom order.

Example

const sortArray = require('sort-array')

sortArray(arr, [options]) ⏏

Kind: Exported function

Param Type Description
arr Array Input array.
[options] object Sort config.
[options.by] Array.<string> One or more properties to sort by.
[options.order] Array.<string> One or more sort orders.
[options.customOrders] object An object containing one or more custom orders.
[options.computed] object An object containing one or more computed field functions.

Load anywhere

This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.

Node.js:

const arrayify = require('sort-array')

Within Node.js with ECMAScript Module support enabled:

import arrayify from 'sort-array'

Within an modern browser ECMAScript Module:

import arrayify from './node_modules/sort-array/index.mjs'

Old browser (adds window.sortArray):

<script nomodule src="./node_modules/sort-array/dist/index.js"></script>

© 2015-19 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.