Package Exports
- sort-o
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-o) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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-oyarn add sort-oUsage
Require
const sorto = require('sort-o');
sorto.sort(data);ES6 Import
import { sort, sortOrder } from 'sort-o';
sort(data, sortOrder.ASC);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.
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
// }
// }Sort array of strings.
import { sort, sortOrder } from 'sort-o';
const input = ['dddd', 'bb', 'ccc', 'a'];
sort(input, sortOrder.LENGTH);
// => [
// 'a',
// 'bb',
// 'ccc',
// 'dddd'
// ]