libj-object-sort
v1.1.0
Published
This is used to sort objects
Downloads
2
Readme
libj-object-sort
Part of libj tools
This is used to sort objects
Usage (npm)
npm install libj-object-sort
import { sortObjects } from 'libj-object-sort'
var list = [
{ id: 1, name: 'reza', parentId: 0 },
{ id: 2, name: 'ali', parentId: 1 },
{ id: 3, name: 'hasan', parentId: 1 },
{ id: 4, name: 'mehdi', parentId: 1 },
{ id: 5, name: 'ahmad', parentId: 1 },
{ id: 6, name: 'saeid', parentId: 1 },
{ id: 7, name: 'masoud', parentId: 1 },
{ id: 10, name: 'mahbod', parentId: 3 },
{ id: 11, name: 'bardiya', parentId: 4 },
{ id: 12, name: 'mahdiyar', parentId: 5 },
{ id: 13, name: 'alireza', parentId: 5 },
{ id: 8, name: 'niyayesh', parentId: 2 },
{ id: 9, name: 'amir hosein', parentId: 2 },
];
var k = sortObjects(list, [
{
column: 'parentId',
ascending: true
},
{
column: 'id',
ascending: false
}
])
assert.deepEqual(
[
{ id: 1, name: 'reza', parentId: 0 },
{ id: 7, name: 'masoud', parentId: 1 },
{ id: 6, name: 'saeid', parentId: 1 },
{ id: 5, name: 'ahmad', parentId: 1 },
{ id: 4, name: 'mehdi', parentId: 1 },
{ id: 3, name: 'hasan', parentId: 1 },
{ id: 2, name: 'ali', parentId: 1 },
{ id: 9, name: 'amir hosein', parentId: 2 },
{ id: 8, name: 'niyayesh', parentId: 2 },
{ id: 10, name: 'mahbod', parentId: 3 },
{ id: 11, name: 'bardiya', parentId: 4 },
{ id: 13, name: 'alireza', parentId: 5 },
{ id: 12, name: 'mahdiyar', parentId: 5 }
], k)
Test
- Run this in a separate command line to start node server
node server.js
- Run one of the following to re-create bundles
npm run dev
npm run dev:watch
- Navigate to http://localhost:3000
Build
npm run build
npm run build:watch