Skip to content

Commit 67f97fa

Browse files
author
Philipp Alferov
committed
Switch to lodash
1 parent 9356dd6 commit 67f97fa

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'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');
54

65
var createTree = function(array, rootNodes, customID) {
76
var tree = [];
@@ -10,7 +9,7 @@ var createTree = function(array, rootNodes, customID) {
109
var node = rootNodes[rootNode];
1110
var childNode = array[node[customID]];
1211

13-
if (!node && !exists(rootNodes, rootNode)) {
12+
if (!node && !rootNodes.hasOwnProperty(rootNode)) {
1413
continue ;
1514
}
1615

@@ -30,7 +29,7 @@ var groupByParents = function(array, options) {
3029
array.forEach(function(item) {
3130
var parentID = item[options.parentProperty] || options.rootID;
3231

33-
if (parentID && exists(parents, parentID)) {
32+
if (parentID && parents.hasOwnProperty(parentID)) {
3433
parents[parentID].push(item);
3534
return ;
3635
}
@@ -61,7 +60,7 @@ var groupByParents = function(array, options) {
6160

6261
module.exports = function arrayToTree(data, options) {
6362
data = data || [];
64-
options = extend({
63+
options = assign({
6564
parentProperty: 'parent_id',
6665
customID: 'id',
6766
rootID: '0'

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"dependencies": {
3535
"extend": "^3.0.0",
3636
"isarray": "0.0.1",
37-
"property-exists": "^1.0.1"
37+
"lodash.assign": "^4.0.6",
38+
"lodash.isarray": "^4.0.0"
3839
}
3940
}

0 commit comments

Comments
 (0)