array-to-tree
Advanced tools
Comparing version
24
index.js
'use strict'; | ||
var property = require('nested-property'); | ||
var keyBy = require('lodash.keyby'); | ||
const property = require('nested-property'); | ||
const keyBy = require('lodash.keyby'); | ||
var createTree = function(array, rootNodes, customID, childrenProperty) { | ||
var tree = []; | ||
const createTree = (array, rootNodes, customID, childrenProperty) => { | ||
const tree = []; | ||
for (var rootNode in rootNodes) { | ||
var node = rootNodes[rootNode]; | ||
var childNode = array[node[customID]]; | ||
for (const rootNode in rootNodes) { | ||
const node = rootNodes[rootNode]; | ||
const childNode = array[node[customID]]; | ||
@@ -31,7 +31,7 @@ if (!node && !rootNodes.hasOwnProperty(rootNode)) { | ||
var groupByParents = function(array, options) { | ||
var arrayByID = keyBy(array, options.customID); | ||
const groupByParents = (array, options) => { | ||
const arrayByID = keyBy(array, options.customID); | ||
return array.reduce(function(prev, item) { | ||
var parentID = property.get(item, options.parentProperty); | ||
return array.reduce((prev, item) => { | ||
let parentID = property.get(item, options.parentProperty); | ||
if (!parentID || !arrayByID.hasOwnProperty(parentID)) { | ||
@@ -86,3 +86,3 @@ parentID = options.rootID; | ||
var grouped = groupByParents(data.slice(), options); | ||
const grouped = groupByParents(data.slice(), options); | ||
return createTree( | ||
@@ -89,0 +89,0 @@ grouped, |
{ | ||
"name": "array-to-tree", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Convert a plain array of nodes (with pointers to parent nodes) to a tree", | ||
@@ -32,3 +32,3 @@ "main": "index.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
@@ -35,0 +35,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
113066
0.04%