🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

array-to-tree

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-to-tree - npm Package Compare versions

Comparing version

to
1.1.2

32

index.js
'use strict';
var isArray = require('isarray');
var extend = require('shallow-object-extend');
var exists = require('property-exists');
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 = [];
for (var key in rootNodes) {
if (!exists(rootNodes, key)) {
for (var rootNode in rootNodes) {
if (!exists(rootNodes, rootNode)) {
continue ;
}
var parentNode = rootNodes[key];
var childNode = array[parentNode[customID]];
var node = rootNodes[rootNode];
var childNode = array[node[customID]];
if (childNode) {
parentNode.children = createTree(array, childNode, customID);
node.children = createTree(array, childNode, customID);
}
tree.push(parentNode);
tree.push(node);
}

@@ -56,3 +44,3 @@

* arrayToTree
* Convert a plain array of nodes (with pointers to parent nodes) to a tree
* Convert a plain array of nodes (with pointers to parent nodes) to a nested data structure
*

@@ -59,0 +47,0 @@ * @name arrayToTree

{
"name": "array-to-tree",
"version": "1.1.1",
"version": "1.1.2",
"description": "Convert a plain array of nodes (with pointers to parent nodes) to a tree",

@@ -10,3 +10,3 @@ "main": "index.js",

},
"repository": "alferov/array-to-tree",
"repository": "alferov/property-exists",
"keywords": [

@@ -33,3 +33,8 @@ "array",

},
"license": "MIT"
"license": "MIT",
"dependencies": {
"isarray": "0.0.1",
"property-exists": "^1.0.1",
"shallow-object-extend": "0.0.1"
}
}
# array-to-tree [![Build Status](https://travis-ci.org/alferov/array-to-tree.svg?branch=master)](https://travis-ci.org/alferov/array-to-tree)
> Convert a plain array of nodes (with pointers to parent nodes) to a tree.
> Convert a plain array of nodes (with pointers to parent nodes) to a nested data structure.
Solves a problem with conversion of retrieved from a database sets of data to a nested structure (i.e. navigation tree).
Solves a problem with conversion of retrieved from a database sets of data to a nested data structure (i.e. navigation tree).

@@ -91,3 +91,3 @@ ## Install

### `arrayToTree(options)`
Convert a plain array of nodes (with pointers to parent nodes) to a tree.
Convert a plain array of nodes (with pointers to parent nodes) to a a nested data structure.

@@ -94,0 +94,0 @@ #### Params