data-structure-conversion
v0.1.0
Published
``` $ npm install data-structure-conversion ```
Downloads
2
Readme
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
}
]