0.1.0 • Published 5 years ago
data-structure-conversion v0.1.0
Install
$ npm install data-structure-conversion
Usage
const { list2tree } = require('data-structure-conversion');
const rawList = [
{ id: 1 },
{ id: 2, pid: 1 },
{ id: 3, pid: 2 },
{ id: 4 }
];
list2tree(rawList);
//=>
[
{
id: 1,
nodes: [
{
id: 2,
pid: 1,
nodes: [
{
id: 3,
pid: 2
}
]
}
]
},
{
id: 4
}
]
API
list2tree(data[, key, parentKey])
0.1.0
5 years ago