sort-array
Isomorphic, load-anywhere function to sort an array by scalar, deep or computed values in any standard or custom order
Last updated 7 years ago by 75lb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install sort-array 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 5.1.2                                ...           latest (a month ago)
  • 4.1.0-0                                ...           next (7 years ago)

31 Versions

  • 5.1.2                                ...           a month ago
  • 5.1.1                                ...           a year ago
  • 5.1.0                                ...           a year ago
  • 5.0.0                                ...           2 years ago
  • 4.1.5                                ...           5 years ago
  • 4.1.4                                ...           6 years ago
  • 4.1.3                                ...           6 years ago
  • 4.1.2                                ...           6 years ago
  • 4.1.1                                ...           7 years ago
  • 4.1.0                                ...           7 years ago
  • 4.1.0-0                                ...           7 years ago
  • 4.0.1                                ...           7 years ago
  • 4.0.0                                ...           7 years ago
  • 3.0.5                                ...           7 years ago
  • 3.0.4                                ...           7 years ago
  • 3.0.3                                ...           7 years ago
  • 3.0.2                                ...           7 years ago
  • 3.0.1                                ...           7 years ago
  • 3.0.0                                ...           7 years ago
  • 3.0.0-3                                ...           7 years ago
  • 3.0.0-2                                ...           7 years ago
  • 3.0.0-1                                ...           7 years ago
  • 3.0.0-0                                ...           7 years ago
  • 1.1.2                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.1.1                                ...           10 years ago
  • 1.1.0                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
  • 0.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Total 61
Today 0
This Week 8
This Month 46
Last Day 4
Last Week 20
Last Month 2
Dependencies (2)
Dev Dependencies (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE