sort-o
Utility for your sorting needs.
Features
- Sort keys of an object.
- Sort arrays by length and value.
- TBD..
Installation
npm install --save sort-o
yarn add sort-o
Usage
Require
const sorto = ; sorto;
ES6 Import
; ;
API
sorto.sort(data [, sortOrder])
Sort data as per the specified order.
- Suppports deep sorting for object keys.
sortOrder
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 |
Example
Sort keys of an object.
; const input = a: 1 c: b: 2 c: 3 a: 1 b: 2; ; // => {// a: 1,// b: 2,// c:{// a: 1,// b: 2,// c: 3// }// }
Sort array of strings.
; const input = 'dddd' 'bb' 'ccc' 'a'; ; // => [// 'a',// 'bb',// 'ccc',// 'dddd'// ]