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 ]
23
34![ array-to-tree] ( media/array-to-tree.png )
45
@@ -13,16 +14,13 @@ $ npm install array-to-tree --save
1314```
1415
1516## Usage
16-
17- ### With Default Attributes
18-
1917``` js
2018var arrayToTree = require (' array-to-tree' );
2119
22- var data = [{
20+ var dataOne = [{
2321 id: 1 ,
2422 name: " Portfolio" ,
25- parent_id: null
23+ parent_id: undefined
2624}, {
2725 id: 2 ,
2826 name: " Web Development" ,
@@ -34,10 +32,10 @@ var data = [{
3432}, {
3533 id: 4 ,
3634 name: " About Me" ,
37- parent_id: null
35+ parent_id: undefined
3836}];
3937
40- arrayToTree (data );
38+ arrayToTree (dataOne );
4139
4240/*
4341 * Output:
@@ -48,14 +46,7 @@ arrayToTree(data);
4846 * About Me
4947 */
5048
51- ```
52-
53- ### With Custom Attributes
54-
55- ``` js
56- var arrayToTree = require (' array-to-tree' );
57-
58- var data = [{
49+ var dataTwo = [{
5950 _id: ' ec654ec1-7f8f-11e3-ae96-b385f4bc450c' ,
6051 name: " Portfolio" ,
6152 parent: null
@@ -73,7 +64,7 @@ var data = [{
7364 parent: null
7465}];
7566
76- arrayToTree (data , {
67+ arrayToTree (dataTwo , {
7768 parentProperty: ' parent' ,
7869 customID: ' _id'
7970});
@@ -89,11 +80,10 @@ arrayToTree(data, {
8980```
9081
9182## API
92-
93- ### ` arrayToTree(data, options) `
83+ ### ` arrayToTree(data, [options]) `
9484Convert a plain array of nodes (with pointers to parent nodes) to a a nested data structure.
9585
96- #### Params
86+ #### Parameters
9787- ** Array** ` data ` : An array of data
9888- ** Object** ` options ` : An object containing the following fields:
9989 - ` 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
10595## License
10696
10797MIT © [ 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