# data-tree

> Data oriented tree structure that unleashes the power of callbacks to create, search and traverse the tree.

Latest version **1.2.4** (published 2016-04-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install data-tree
pnpm add data-tree
yarn add data-tree
bun add data-tree
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.4 |
| Published | 2016-04-06 |
| First published | 2015-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Chaitanya Chandurkar |
| Maintainers | cchandurkar |
| Keywords | node, graph, tree, binary, data-tree, data, binary-tree, search-tree, BFS, DFS, import tree, export tree, search, BST, traversal, traverse |

## Links

- npm: https://www.npmjs.com/package/data-tree
- Repository: https://github.com/cchandurkar/Data-Tree
- Homepage: https://github.com/cchandurkar/Data-Tree#readme
- Issues: https://github.com/cchandurkar/Data-Tree/issues
- npm.io page: https://npm.io/package/data-tree

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 1.2.4 (latest) — 2016-04-06
- 1.2.3 — 2016-03-25
- 1.2.2 — 2016-03-06
- 1.2.1 — 2016-03-06
- 1.2.0 — 2016-03-06
- 1.1.27 — 2016-03-02
- 1.1.26 — 2016-02-17
- 1.1.25 — 2016-02-10
- 1.1.24 — 2016-02-10
- 1.1.22 — 2016-01-24
- 1.1.21 — 2016-01-24
- 1.1.20 — 2016-01-24
- 1.1.19 — 2016-01-24
- 1.1.17 — 2016-01-24
- 1.1.15 — 2016-01-24
- … 14 more at https://npm.io/package/data-tree/versions

## README

[![Build Status](https://travis-ci.org/cchandurkar/Data-Tree.svg?branch=master)](https://travis-ci.org/cchandurkar/Data-Tree) [![npm version](https://badge.fury.io/js/data-tree.svg)](https://badge.fury.io/js/data-tree) [![Dependency Status](https://david-dm.org/cchandurkar/data-tree.svg)](https://david-dm.org/cchandurkar/data-tree) [![devDependency Status](https://david-dm.org/cchandurkar/data-tree/dev-status.svg)](https://david-dm.org/cchandurkar/data-tree#info=devDependencies) [![Gitter](https://badges.gitter.im/cchandurkar/Data-Tree.svg)](https://gitter.im/cchandurkar/Data-Tree?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

# Data Tree
Data oriented tree structure that unleashes the power of callbacks to create, search and traverse tree. Data tree keeps the track of current node which updates upon insertion and deletion of the node from tree.

<img height="120" width="120" src="http://cchandurkar.github.io/data-tree/icon/icon.png"/>

## Install:
`$ npm install data-tree`<br /><br /> Then use via `require('data-tree')` **OR** use browserified build available at [dataTree.min.js](http://cchandurkar.github.io/Data-Tree/dataTree.min.js) in `<script/>` directly.

## Examples:
Following examples will guide you to create tree, insert/remove nodes and search/traverse a tree. Don't forget to checkout [Data-Tree reference](http://cchandurkar.github.io/Data-Tree/docs/).

### Create tree
`dataTree` is global variable that can be used to create a tree in following way.

```javascript
  var tree = dataTree.create();
```

### Insert data

```javascript
// Insert single value
tree.insert(183);

// Insert array of values
// NOTE: This does not create 3 different nodes. It considers an array as a whole data and puts in a single node.
tree.insert([34, 565, 78]);

// Insert Objects
tree.insert({
  key: '#berries',
  value: { name: 'Apple', color: 'Red'}
});
```

### Create and append node to a parent node that satisfies the given criteria

```javascript
// Insert data
tree.insert({
  key: '#apple',
  value: { name: 'Apple', color: 'Red'}
});

// New Data
var greenApple = {
  key: '#greenapple',
  value: { name: 'Green Apple', color: 'Green' }
};

// Insert data to node which has `key` = #apple
tree.insertTo(function(data){
  return data.key === '#apple'
}, greenApple);
```

### Create and append node using parent node's instance

```javascript
// Insert data
var node = tree.insert({
  key: '#apple',
  value: { name: 'Apple', color: 'Red'}
});

// New Data
var greenApple = {
 key: '#greenapple',
 value: { name: 'Green Apple', color: 'Green' }
};

// Insert data to node
// This will create a new node with given data and append to parent node provided
tree.insertToNode(node, greenApple);
```

### Remove Node

```javascript
// Insert Node
var node = tree.insert({
  key: '#apple',
  value: { name: 'Apple', color: 'Red'}
});

// Remove it
tree.remove(node);
```

### Search BFS

```javascript
var node = tree.traverser().searchBFS(function(data){
  return data.key === '#apple';
});
```

### Search DFS

```javascript
var node = tree.traverser().searchDFS(function(data){
  return data.key === '#apple';
});
```

### Traverse BFS

```javascript
tree.traverser().traverseBFS(function(node){
  console.log(node.data());
});
```

#### Traverse DFS

```javascript
tree.traverser().traverseDFS(function(node){
  console.log(node.data());
});
```

#### Find common parent

```javascript
var commonParent = tree.findCommonParent(fromNode, toNode);
```
## Developers
1. Clone this repositoy and `cd` into it
2. `npm install`
3. `npm run build` to build browserify files **OR** `npm run dev-server` to start a development server.

---
_Source: https://npm.io/package/data-tree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
