11'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' ) ;
44
5- var createTree = function ( array , rootNodes , customID , childrenProperty ) {
6- var tree = [ ] ;
5+ const createTree = ( array , rootNodes , customID , childrenProperty ) => {
6+ const tree = [ ] ;
77
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 ] ] ;
1111
1212 if ( ! node && ! rootNodes . hasOwnProperty ( rootNode ) ) {
1313 continue ;
@@ -28,11 +28,11 @@ var createTree = function(array, rootNodes, customID, childrenProperty) {
2828 return tree ;
2929} ;
3030
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 ) ;
3333
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 ) ;
3636 if ( ! parentID || ! arrayByID . hasOwnProperty ( parentID ) ) {
3737 parentID = options . rootID ;
3838 }
@@ -82,7 +82,7 @@ module.exports = function arrayToTree(data, options) {
8282 throw new TypeError ( 'Expected an object but got an invalid argument' ) ;
8383 }
8484
85- var grouped = groupByParents ( data . slice ( ) , options ) ;
85+ const grouped = groupByParents ( data . slice ( ) , options ) ;
8686 return createTree (
8787 grouped ,
8888 grouped [ options . rootID ] ,
0 commit comments