# live-tree

> Fast tree with live iterator

Latest version **1.0.0** (published 2014-09-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install live-tree
pnpm add live-tree
yarn add live-tree
bun add live-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.0.0 |
| Published | 2014-09-20 |
| First published | 2013-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maximilian Antoni |
| Maintainers | mantoni |
| Keywords | tree, iterator |

## Links

- npm: https://www.npmjs.com/package/live-tree
- Repository: https://github.com/mantoni/live-tree.js
- Issues: https://github.com/mantoni/live-tree.js/issues
- npm.io page: https://npm.io/package/live-tree

## Dependencies (3)

- [inherits](https://npm.io/package/inherits.md) ^2.0
- [live-list](https://npm.io/package/live-list.md) ^1.0
- [min-iterator](https://npm.io/package/min-iterator.md) ^1.0

## Recent versions

- 1.0.0 (latest) — 2014-09-20
- 0.3.0 — 2014-01-15
- 0.2.0 — 2013-12-17
- 0.1.0 — 2013-12-10

## README

# live-tree.js

[![Build Status]](https://travis-ci.org/mantoni/live-tree.js)
[![SemVer]](http://semver.org)
[![License]](https://github.com/mantoni/live-tree.js/blob/master/LICENSE)

Fast tree with live iterator. The tree can be modified
while iterating over the nodes.

## Install with npm

```
npm install live-tree
```

## Browser compatibility

To use this module in a browser, download the npm package and then use
[Browserify](http://browserify.org) to create a standalone version.

## Usage

```js
var Node = require('live-tree').Node;

var n = new Node('root');
n.set('a', 2);
n.set('a.b', 3);
n.set('a.c', 7);

var c, i = n.iterator();
while ((c = i.next()) !== undefined) {
  console.log(c.value);
}
```

## Node API

- `Node(name)`: Returns a new Node with the given name. The name must be of
  type string and not empty.
- `name`: The name of the node
- `value`: The value of the node
- `children`: The list of children (see [live-list][])
- `set(name, value)`: Sets the value of the named node. If the node does not
  exist, it is created and added to the children by calling `_add(node)`. The
  value is changed by calling `_value(value)`.
- `get(name)`: Returns the value of the named node. If the node does not exist,
   undefined is returned.
- `remove(name)`: Removes the named node. If it has children, the value is
  deleted. Parent nodes in the path with no value and no remaining children
  will be removed as well.
- `removeAll()`: Removes all child nodes
- `node(name)`: Return the named node or undefined if the node does not exist
- `_add(node)`: Called by `set` to add a node to the children. The default
  implementation does `this.children.push(node);`.
- `_value(value)`: Called by `set` to change the value. The default
  implementation does `this.value = value;`.
- `toObject()`: Returns a plain object representation of the node and it's
  children
- `iterator()`: Returns a new `Iterator`

[live-list]: https://github.com/mantoni/live-list.js "Fast linked list with live iterator"

## Iterator API

The iterator is derived from [min-iterator][].

- `Iterator(node)`: Returns a new Iterator using the given root node
- `next()`: Returns the next node in the tree. If there are no items left,
  `undefined` is returned.

[min-iterator]: https://github.com/mantoni/min-iterator.js

## License

MIT

[Build Status]: http://img.shields.io/travis/mantoni/live-tree.js.svg
[SemVer]: http://img.shields.io/:semver-%E2%9C%93-brightgreen.svg
[License]: http://img.shields.io/npm/l/live-tree.svg

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