From 867017ef2177f188cd4b7dda38498c5c107cecea Mon Sep 17 00:00:00 2001 From: Philipp Alferov Date: Thu, 1 Oct 2015 13:54:07 -0400 Subject: [PATCH] Get rid of dependencies --- index.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 96bff0e..698dbbb 100644 --- a/index.js +++ b/index.js @@ -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 = []; @@ -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', @@ -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'); }