https://github.com/smart-table/smart-table-sort
take a sort configuration object and return a sort function operating on arrays
https://github.com/smart-table/smart-table-sort
arrray order smart-table sort sortable
Last synced: 4 months ago
JSON representation
take a sort configuration object and return a sort function operating on arrays
- Host: GitHub
- URL: https://github.com/smart-table/smart-table-sort
- Owner: smart-table
- License: mit
- Created: 2017-02-01T16:57:01.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-08-10T17:38:28.000Z (over 4 years ago)
- Last Synced: 2025-09-05T09:33:14.294Z (5 months ago)
- Topics: arrray, order, smart-table, sort, sortable
- Language: JavaScript
- Size: 101 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# smart-table-sort
[](https://circleci.com/gh/smart-table/smart-table-sort)
takes a sort configuration object and returns a sort function operating on arrays (returning a new array without modifying the input array). For nodejs and browsers.
## Installation
### npm
``npm install smart-table-sort --save``
### yarn
``yarn add smart-table-sort``
## Usage
```Javascript
import sorter from 'smart-table-sort';
const input = [{prop: 'foo'}, {prop: 'bar'}, {prop: 'woot'}];
const sort = sorter({pointer:'prop', direction:'desc'}) // default direction is "asc"
const output = sort(input);
// > [{foo: 'woot'}, {prop: 'foo'}, {prop: 'bar'}]
```
it works on nested properties as well
```Javascript
import sorter from 'smart-table-sort';
const input = [
{foo: {bar: 'bcd'}},
{foo: {bar: 'acd'}},
{foo: {bar: 'abd'}}
];
const output = sorter({pointer: 'foo.bar'})(input);
// > [{foo: {bar: 'abd'}},{foo: {bar: 'acd'}},{foo: {bar: 'bcd'}}]);
```
### object conf
* pointer: the property to use for ordering the collection (can be a nested property)
* direction: 'asc', 'desc', 'none' (default is 'asc', 'none' will returned in the order of the input array untouched)
## Contributing
### Test
``npm test``
or
``yarn test``
### Issues
Only **bugs** and must come with a **running reproduction** of the issue