1
- # array-to-tree [ ![ Build Status] ( https://travis-ci.org/alferov/array-to-tree.svg?branch=master )] ( https://travis-ci.org/alferov/array-to-tree )
1
+ # array-to-tree
2
+ [ ![ Build Status] [ travis-image ]] [ travis-url ] [ ![ Dependency Status] [ depstat-image ]] [ depstat-url ]
2
3
3
4
![ array-to-tree] ( media/array-to-tree.png )
4
5
@@ -13,16 +14,13 @@ $ npm install array-to-tree --save
13
14
```
14
15
15
16
## Usage
16
-
17
- ### With Default Attributes
18
-
19
17
``` js
20
18
var arrayToTree = require (' array-to-tree' );
21
19
22
- var data = [{
20
+ var dataOne = [{
23
21
id: 1 ,
24
22
name: " Portfolio" ,
25
- parent_id: null
23
+ parent_id: undefined
26
24
}, {
27
25
id: 2 ,
28
26
name: " Web Development" ,
@@ -34,10 +32,10 @@ var data = [{
34
32
}, {
35
33
id: 4 ,
36
34
name: " About Me" ,
37
- parent_id: null
35
+ parent_id: undefined
38
36
}];
39
37
40
- arrayToTree (data );
38
+ arrayToTree (dataOne );
41
39
42
40
/*
43
41
* Output:
@@ -48,14 +46,7 @@ arrayToTree(data);
48
46
* About Me
49
47
*/
50
48
51
- ```
52
-
53
- ### With Custom Attributes
54
-
55
- ``` js
56
- var arrayToTree = require (' array-to-tree' );
57
-
58
- var data = [{
49
+ var dataTwo = [{
59
50
_id: ' ec654ec1-7f8f-11e3-ae96-b385f4bc450c' ,
60
51
name: " Portfolio" ,
61
52
parent: null
@@ -73,7 +64,7 @@ var data = [{
73
64
parent: null
74
65
}];
75
66
76
- arrayToTree (data , {
67
+ arrayToTree (dataTwo , {
77
68
parentProperty: ' parent' ,
78
69
customID: ' _id'
79
70
});
@@ -89,11 +80,10 @@ arrayToTree(data, {
89
80
```
90
81
91
82
## API
92
-
93
- ### ` arrayToTree(data, options) `
83
+ ### ` arrayToTree(data, [options]) `
94
84
Convert a plain array of nodes (with pointers to parent nodes) to a a nested data structure.
95
85
96
- #### Params
86
+ #### Parameters
97
87
- ** Array** ` data ` : An array of data
98
88
- ** Object** ` options ` : An object containing the following fields:
99
89
- ` parentProperty ` (String): A name of a property where a link to a parent node could be found. Default: 'parent_id'
@@ -105,3 +95,9 @@ Convert a plain array of nodes (with pointers to parent nodes) to a a nested dat
105
95
## License
106
96
107
97
MIT © [ Philipp Alferov] ( https://github.com/alferov )
98
+
99
+ [ travis-url ] : https://travis-ci.org/alferov/array-to-tree
100
+ [ travis-image ] : https://img.shields.io/travis/alferov/array-to-tree.svg?style=flat-square
101
+
102
+ [ depstat-url ] : https://david-dm.org/alferov/array-to-tree
103
+ [ depstat-image ] : https://david-dm.org/alferov/array-to-tree.svg?style=flat-square
0 commit comments