1
1
'use strict' ;
2
- var isArray = require ( 'isarray' ) ;
3
- var extend = require ( 'extend' ) ;
4
- var exists = require ( 'property-exists' ) ;
2
+ var isArray = require ( 'lodash.isarray' ) ;
3
+ var assign = require ( 'lodash.assign' ) ;
5
4
6
5
var createTree = function ( array , rootNodes , customID ) {
7
6
var tree = [ ] ;
@@ -10,7 +9,7 @@ var createTree = function(array, rootNodes, customID) {
10
9
var node = rootNodes [ rootNode ] ;
11
10
var childNode = array [ node [ customID ] ] ;
12
11
13
- if ( ! node && ! exists ( rootNodes , rootNode ) ) {
12
+ if ( ! node && ! rootNodes . hasOwnProperty ( rootNode ) ) {
14
13
continue ;
15
14
}
16
15
@@ -30,7 +29,7 @@ var groupByParents = function(array, options) {
30
29
array . forEach ( function ( item ) {
31
30
var parentID = item [ options . parentProperty ] || options . rootID ;
32
31
33
- if ( parentID && exists ( parents , parentID ) ) {
32
+ if ( parentID && parents . hasOwnProperty ( parentID ) ) {
34
33
parents [ parentID ] . push ( item ) ;
35
34
return ;
36
35
}
@@ -61,7 +60,7 @@ var groupByParents = function(array, options) {
61
60
62
61
module . exports = function arrayToTree ( data , options ) {
63
62
data = data || [ ] ;
64
- options = extend ( {
63
+ options = assign ( {
65
64
parentProperty : 'parent_id' ,
66
65
customID : 'id' ,
67
66
rootID : '0'
0 commit comments