antsort
v1.1.2
Published
`Another sort` - sort elements by level, before and afte.
Downloads
5,495
Readme
antsort
Another sort
- sort elements by level, before and afte.
antsort(list)
var sort = require('antsort');
var list = [
{
name: 'a',
level: 3
},
{
name: 'b',
level: 4
},
{
name: 'c',
before: 'b'
},
{
name: 'd',
level: 3
},
{
name: 'e',
after: 'a'
}
];
var sorted = sort(list);
sorted.map(item => item.name)
.should.be.eql(['a', 'e', 'd', 'c', 'b']);
antsort(list, { defaultLevel: ... })
var list = [
{
name: 'a',
level: 1
},
{
name: 'b' // will be last
},
{
name: 'c',
level: 1
}
];
sort(list).map(item => item.name)
.should.be.eql(['a', 'c', 'b']);
sort(list, { defaultLevel: 0 }).map(item => item.name)
.should.be.eql(['b', 'a', 'c']);