Skip to content

Commit 148dc58

Browse files
author
Philipp Alferov
committed
Add readme
1 parent 744869f commit 148dc58

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

readme.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# array-to-tree
2+
3+
> Convert a plain array of nodes (with pointers to parent nodes) to a tree.
4+
5+
Solves a problem with conversion of retrieved from a database sets of data to a nested structure (i.e. navigation tree).
6+
7+
## Install
8+
9+
```
10+
$ npm install --save array-to-tree
11+
```
12+
13+
## Usage
14+
15+
```js
16+
var arrayToTree = require('array-to-tree');
17+
18+
var navigation = [{
19+
id: 1,
20+
name: "Portfolio",
21+
parent_id: null
22+
}, {
23+
id: 2,
24+
name: "Web Development",
25+
parent_id: 1
26+
}, {
27+
id: 3,
28+
name: "Recent Works",
29+
parent_id: 2
30+
}, {
31+
id: 4,
32+
name: "About Me",
33+
parent_id: null
34+
}];
35+
36+
var navigationTree = arrayToTree(navigation);
37+
38+
/*
39+
* Output:
40+
* Portfolio
41+
* Web Development
42+
* Recent Works
43+
* About Me
44+
*/
45+
46+
```
47+
48+
## License
49+
50+
MIT
51+
[Philipp Alferov](https://github.com/alferov)

0 commit comments

Comments
 (0)