Skip to content

Commit 867017e

Browse files
author
Philipp Alferov
committed
Get rid of dependencies
1 parent 3b13e7d commit 867017e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
'use strict';
2-
var util = require('util');
32

43
var exists = function(obj, key) {
54
return obj != null && Object.hasOwnProperty.call(obj, key);
65
};
76

7+
var extend = function(destination, source) {
8+
for (var property in source) {
9+
destination[property] = source[property];
10+
}
11+
return destination;
12+
}
13+
14+
var isArray = Array.isArray || function(obj) {
15+
return toString.call(obj) === '[object Array]';
16+
};
17+
818
var createTree = function(array, rootNodes, customID) {
919
var tree = [];
1020

@@ -58,7 +68,7 @@ var groupByParents = function(array, options) {
5868
*/
5969

6070
module.exports = function arrayToTree(options) {
61-
options = util._extend({
71+
options = extend({
6272
parentProperty: 'parent_id',
6373
data: [],
6474
customID: 'id',
@@ -67,7 +77,7 @@ module.exports = function arrayToTree(options) {
6777

6878
var data = options.data;
6979

70-
if (!util.isArray(data)) {
80+
if (!isArray(data)) {
7181
throw new Error('Expected an object but got an invalid argument');
7282
}
7383

0 commit comments

Comments
 (0)