1
1
'use strict' ;
2
- var property = require ( 'nested-property' ) ;
3
- var keyBy = require ( 'lodash.keyby' ) ;
2
+ const property = require ( 'nested-property' ) ;
3
+ const keyBy = require ( 'lodash.keyby' ) ;
4
4
5
- var createTree = function ( array , rootNodes , customID , childrenProperty ) {
6
- var tree = [ ] ;
5
+ const createTree = ( array , rootNodes , customID , childrenProperty ) => {
6
+ const tree = [ ] ;
7
7
8
- for ( var rootNode in rootNodes ) {
9
- var node = rootNodes [ rootNode ] ;
10
- var childNode = array [ node [ customID ] ] ;
8
+ for ( const rootNode in rootNodes ) {
9
+ const node = rootNodes [ rootNode ] ;
10
+ const childNode = array [ node [ customID ] ] ;
11
11
12
12
if ( ! node && ! rootNodes . hasOwnProperty ( rootNode ) ) {
13
13
continue ;
@@ -28,11 +28,11 @@ var createTree = function(array, rootNodes, customID, childrenProperty) {
28
28
return tree ;
29
29
} ;
30
30
31
- var groupByParents = function ( array , options ) {
32
- var arrayByID = keyBy ( array , options . customID ) ;
31
+ const groupByParents = ( array , options ) => {
32
+ const arrayByID = keyBy ( array , options . customID ) ;
33
33
34
- return array . reduce ( function ( prev , item ) {
35
- var parentID = property . get ( item , options . parentProperty ) ;
34
+ return array . reduce ( ( prev , item ) => {
35
+ let parentID = property . get ( item , options . parentProperty ) ;
36
36
if ( ! parentID || ! arrayByID . hasOwnProperty ( parentID ) ) {
37
37
parentID = options . rootID ;
38
38
}
@@ -82,7 +82,7 @@ module.exports = function arrayToTree(data, options) {
82
82
throw new TypeError ( 'Expected an object but got an invalid argument' ) ;
83
83
}
84
84
85
- var grouped = groupByParents ( data . slice ( ) , options ) ;
85
+ const grouped = groupByParents ( data . slice ( ) , options ) ;
86
86
return createTree (
87
87
grouped ,
88
88
grouped [ options . rootID ] ,
0 commit comments