Skip to content

Commit

Permalink
Get rid of dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Alferov committed Oct 1, 2015
1 parent 3b13e7d commit 867017e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
'use strict';
var util = require('util');

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

var extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}

var isArray = Array.isArray || function(obj) {
return toString.call(obj) === '[object Array]';
};

var createTree = function(array, rootNodes, customID) {
var tree = [];

Expand Down Expand Up @@ -58,7 +68,7 @@ var groupByParents = function(array, options) {
*/

module.exports = function arrayToTree(options) {
options = util._extend({
options = extend({
parentProperty: 'parent_id',
data: [],
customID: 'id',
Expand All @@ -67,7 +77,7 @@ module.exports = function arrayToTree(options) {

var data = options.data;

if (!util.isArray(data)) {
if (!isArray(data)) {
throw new Error('Expected an object but got an invalid argument');
}

Expand Down

0 comments on commit 867017e

Please sign in to comment.