1
1
'use strict' ;
2
- const property = require ( 'nested-property' ) ;
3
- const keyBy = require ( 'lodash.keyby' ) ;
2
+ var property = require ( 'nested-property' ) ;
3
+ var keyBy = require ( 'lodash.keyby' ) ;
4
4
5
- const createTree = ( array , rootNodes , customID , childrenProperty ) => {
6
- const tree = [ ] ;
5
+ var createTree = ( array , rootNodes , customID , childrenProperty ) => {
6
+ var tree = [ ] ;
7
7
8
- for ( const rootNode in rootNodes ) {
9
- const node = rootNodes [ rootNode ] ;
10
- const childNode = array [ node [ customID ] ] ;
8
+ for ( var rootNode in rootNodes ) {
9
+ var node = rootNodes [ rootNode ] ;
10
+ var childNode = array [ node [ customID ] ] ;
11
11
12
12
if ( ! node && ! rootNodes . hasOwnProperty ( rootNode ) ) {
13
13
continue ;
@@ -28,8 +28,8 @@ const createTree = (array, rootNodes, customID, childrenProperty) => {
28
28
return tree ;
29
29
} ;
30
30
31
- const groupByParents = ( array , options ) => {
32
- const arrayByID = keyBy ( array , options . customID ) ;
31
+ var groupByParents = ( array , options ) => {
32
+ var arrayByID = keyBy ( array , options . customID ) ;
33
33
34
34
return array . reduce ( ( prev , item ) => {
35
35
let parentID = property . get ( item , options . parentProperty ) ;
@@ -49,7 +49,7 @@ const groupByParents = (array, options) => {
49
49
50
50
function isObject ( o ) {
51
51
return Object . prototype . toString . call ( o ) === "[object Object]" ;
52
- } ;
52
+ }
53
53
54
54
function deepClone ( data ) {
55
55
if ( Array . isArray ( data ) ) {
@@ -99,7 +99,7 @@ module.exports = function arrayToTree(data, options) {
99
99
throw new TypeError ( 'Expected an object but got an invalid argument' ) ;
100
100
}
101
101
102
- const grouped = groupByParents ( deepClone ( data ) , options ) ;
102
+ var grouped = groupByParents ( deepClone ( data ) , options ) ;
103
103
return createTree (
104
104
grouped ,
105
105
grouped [ options . rootID ] ,
0 commit comments