Package Exports
- list-to-tree-lite
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 (list-to-tree-lite) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
list-to-tree-lite
A simple function converts a flat-list of objects with id
, parent
and children
to a tree-list of objects.
without any dependencies.
[{
id: 6,
any: 'opps'
}, {
id: 2,
parent: 5,
any: 'foo',
}, {
id: 1,
parent: 2,
any: 'bar'
}, {
id: 5,
any: 'hello'
}, {
id: 3,
parent: 2,
any: 'other'
}]
to
[{
id: 6,
any: 'opps',
children: []
}, {
id: 5,
any: 'hello',
children: [{
id: 2,
parent: 5,
any: 'foo',
children: [{
id: 1,
parent: 2,
any: 'bar',
children: []
}, {
id: 3,
parent: 2,
any: 'other',
children: []
}]
}]
}]
#UsagelistToTree(list[, options])
options.idKey
the id key of the item object, default id
options.parentKey
the parent key of the item object, default parent
options.childrenKey
the children key of the item object, default children
#Install
npm install list-to-tree-lite --save
#Testnpm run test
#License
MIT:http://william17.mit-license.org