All Projects → alferov → Array To Tree

alferov / Array To Tree

Licence: mit
Convert a plain array of nodes (with pointers to parent nodes) to a nested data structure

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Array To Tree

Data-structures
Data Structures in Java
Stars: ✭ 13 (-90.78%)
Mutual labels:  arrays, tree-structure
Bosket
Collection of tree view components for front-end frameworks. 🌳
Stars: ✭ 457 (+224.11%)
Mutual labels:  tree, tree-structure
Data Structures Algorithms
My implementation of 85+ popular data structures and algorithms and interview questions in Python 3 and C++
Stars: ✭ 273 (+93.62%)
Mutual labels:  tree, arrays
InterviewBit
Collection of solution for problems on InterviewBit
Stars: ✭ 77 (-45.39%)
Mutual labels:  tree, arrays
Containers
This library provides various containers. Each container has utility functions to manipulate the data it holds. This is an abstraction as to not have to manually manage and reallocate memory.
Stars: ✭ 125 (-11.35%)
Mutual labels:  tree, tree-structure
react-treefold
A renderless tree component for your hierarchical React views
Stars: ✭ 37 (-73.76%)
Mutual labels:  tree, tree-structure
Data Structures With Go
Data Structures with Go Language
Stars: ✭ 121 (-14.18%)
Mutual labels:  tree, arrays
TreeRep
Learning Tree structures and Tree metrics
Stars: ✭ 18 (-87.23%)
Mutual labels:  tree, tree-structure
Ki
Go language (golang) full strength tree structures (ki in Japanese)
Stars: ✭ 61 (-56.74%)
Mutual labels:  tree, tree-structure
Angular2 Tree Diagram
Angular Hierarchical UI module
Stars: ✭ 50 (-64.54%)
Mutual labels:  tree, tree-structure
prune
A tree library for Java 8 with functional sensibilities.
Stars: ✭ 22 (-84.4%)
Mutual labels:  tree, tree-structure
Abp.generaltree
For Abp vNext
Stars: ✭ 106 (-24.82%)
Mutual labels:  tree, tree-structure
stefano-tree
Framework agnostic Nested Set (MPTT) implementation for PHP
Stars: ✭ 24 (-82.98%)
Mutual labels:  tree, tree-structure
tree-json-generator
Simple JavaScript Tree Generator library
Stars: ✭ 13 (-90.78%)
Mutual labels:  tree, tree-structure
treetime
TreeTime is a data organisation, management and analysis tool. A tree is a hierarchical structure that arranges information in units and sub-units. TreeTime uses linked trees (one data item can be part of different distinct trees) to store and organise any general purpose data.
Stars: ✭ 26 (-81.56%)
Mutual labels:  tree, tree-structure
Wmderland
🌳 X11 tiling window manager using space partitioning trees
Stars: ✭ 341 (+141.84%)
Mutual labels:  tree, tree-structure
performant-array-to-tree
Converts an array of items with ids and parent ids to a nested tree in a performant O(n) way. Runs in browsers and Node.js.
Stars: ✭ 193 (+36.88%)
Mutual labels:  tree, tree-structure
react-tree
Hierarchical tree component for React in Typescript
Stars: ✭ 174 (+23.4%)
Mutual labels:  tree, tree-structure
Cracking The Coding Interview
Solutions for Cracking the Coding Interview - 6th Edition
Stars: ✭ 35 (-75.18%)
Mutual labels:  tree, arrays
Buckets Js
A complete, fully tested and documented data structure library written in pure JavaScript.
Stars: ✭ 1,128 (+700%)
Mutual labels:  tree, tree-structure

array-to-tree

Build Status Dependency Status

array-to-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 data structure (i.e. navigation tree).

Installation

$ npm install array-to-tree --save

Usage

var arrayToTree = require('array-to-tree');

var dataOne = [
  {
    id: 1,
    name: 'Portfolio',
    parent_id: undefined
  },
  {
    id: 2,
    name: 'Web Development',
    parent_id: 1
  },
  {
    id: 3,
    name: 'Recent Works',
    parent_id: 2
  },
  {
    id: 4,
    name: 'About Me',
    parent_id: undefined
  }
];

arrayToTree(dataOne);

/*
 * Output:
 *
 * Portfolio
 *   Web Development
 *     Recent Works
 * About Me
 */

var dataTwo = [
  {
    _id: 'ec654ec1-7f8f-11e3-ae96-b385f4bc450c',
    name: 'Portfolio',
    parent: null
  },
  {
    _id: 'ec666030-7f8f-11e3-ae96-0123456789ab',
    name: 'Web Development',
    parent: 'ec654ec1-7f8f-11e3-ae96-b385f4bc450c'
  },
  {
    _id: 'ec66fc70-7f8f-11e3-ae96-000000000000',
    name: 'Recent Works',
    parent: 'ec666030-7f8f-11e3-ae96-0123456789ab'
  },
  {
    _id: '32a4fbed-676d-47f9-a321-cb2f267e2918',
    name: 'About Me',
    parent: null
  }
];

arrayToTree(dataTwo, {
  parentProperty: 'parent',
  customID: '_id'
});

/*
 * Output:
 *
 * Portfolio
 *   Web Development
 *     Recent Works
 * About Me
 */

API

arrayToTree(data, [options])

Convert a plain array of nodes (with pointers to parent nodes) to a a nested data structure.

Parameters

  • Array data: An array of data
  • Object options: An object containing the following fields:
    • parentProperty (String): A name of a property where a link to a parent node could be found. Default: 'parent_id'.
    • childrenProperty (String): A name of a property where children nodes are going to be stored. Default: 'children'.
    • customID (String): An unique node identifier. Default: 'id'.

Return

  • Array: Result of transformation

License

MIT © Philipp Alferov

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].