Skip to content

Commit 39ecf46

Browse files
author
Philipp Alferov
committed
Update documentation
1 parent 2f3921b commit 39ecf46

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

readme.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
77
Solves a problem with conversion of retrieved from a database sets of data to a nested data structure (i.e. navigation tree).
88

9-
## Install
9+
## Installation
1010

1111
```
12-
$ npm install --save array-to-tree
12+
$ npm install array-to-tree --save
1313
```
1414

1515
## Usage
1616

17-
### Basic
17+
### With Default Attributes
1818

1919
```js
2020
var arrayToTree = require('array-to-tree');
@@ -37,10 +37,11 @@ var data = [{
3737
parent_id: null
3838
}];
3939

40-
var tree = arrayToTree({ data: data });
40+
arrayToTree(data);
4141

4242
/*
4343
* Output:
44+
*
4445
* Portfolio
4546
* Web Development
4647
* Recent Works
@@ -72,14 +73,14 @@ var data = [{
7273
parent: null
7374
}];
7475

75-
var tree = arrayToTree({
76+
arrayToTree(data, {
7677
parentProperty: 'parent',
7778
customID: '_id'
78-
data: data
7979
});
8080

8181
/*
8282
* Output:
83+
*
8384
* Portfolio
8485
* Web Development
8586
* Recent Works
@@ -93,10 +94,10 @@ var tree = arrayToTree({
9394
Convert a plain array of nodes (with pointers to parent nodes) to a a nested data structure.
9495

9596
#### Params
96-
**Object** `options`: An object containing the following fields:
97-
- `parentProperty` (String): A name of a property where a link to a parent node could be found. Default: 'parent_id'
98-
- `data` (Array): An array of` data
99-
- `customID` (String): An unique node identifier. Default: 'id'
97+
- **Array** `data`: An array of data
98+
- **Object** `options`: An object containing the following fields:
99+
- `parentProperty` (String): A name of a property where a link to a parent node could be found. Default: 'parent_id'
100+
- `customID` (String): An unique node identifier. Default: 'id'
100101

101102
#### Return
102103
- **Array**: Result of transformation

test/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ describe('array-to-tree', function() {
7171
describe('with different options', function() {
7272
it('should work with custom parents links', function() {
7373

74-
current = toTree(
75-
customInitial,
76-
{ parentProperty: 'parent', customID: '_id' });
74+
current = toTree(customInitial, {
75+
parentProperty: 'parent', customID: '_id'
76+
});
7777

7878
expect(current)
7979
.to.be.deep.equal(customExpected);

0 commit comments

Comments
 (0)