Utility for your sorting needs.
- Sort keys of an object.
- Sort arrays by length and value.
- TBD..
npm install --save sort-o
yarn add sort-o
const sorto = require('sort-o');
sorto.sort(data);
import { sort, sortOrder } from 'sort-o';
sort(data, sortOrder.ASC);
Sort data as per the specified order.
- Suppports deep sorting for object keys.
sortOrder | Type | Value | Description |
---|---|---|---|
sortOrder.ASC (default) |
string |
'asc' | Sort in ascending order |
sortOrder.DESC | string |
'desc' | Sort in descending order |
sortOrder.ASC_LENGTH | string |
'asc_length' | Sort in ascending order by length |
sortOrder.DESC_LENGTH | string |
'desc_length' | Sort in descending order by length |
import { sortKeys, sortOrder } from 'sort-o';
const input = {
a: 1,
c: {
b: 2,
c: 3,
a: 1
},
b: 2
};
sortKeys(input, sortOrder.ASC);
// => {
// a: 1,
// b: 2,
// c:{
// a: 1,
// b: 2,
// c: 3
// }
// }
import { sort, sortOrder } from 'sort-o';
const input = ['dddd', 'bb', 'ccc', 'a'];
sort(input, sortOrder.LENGTH);
// => [
// 'a',
// 'bb',
// 'ccc',
// 'dddd'
// ]