# key-nodes

> Tree nodes for key and key/value pairs in object path hierarchies.

Latest version **2.0.2** (published 2019-10-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install key-nodes
pnpm add key-nodes
yarn add key-nodes
bun add key-nodes
```

## 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 | 2.0.2 |
| Published | 2019-10-14 |
| First published | 2019-09-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 2.6 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Michael Price |
| Maintainers | mikepricedev |

## Links

- npm: https://www.npmjs.com/package/key-nodes
- Repository: https://github.com/mikepricedev/keyNodes
- Homepage: https://github.com/mikepricedev/keyNodes#readme
- Issues: https://github.com/mikepricedev/keyNodes/issues
- npm.io page: https://npm.io/package/key-nodes

## Dependencies (1)

- [path-notation](https://npm.io/package/path-notation.md) ^2.1.0

## Recent versions

- 2.0.2 (latest) — 2019-10-14
- 2.0.1 — 2019-10-09
- 2.0.0 — 2019-10-06
- 1.1.0 — 2019-09-26
- 1.0.0 — 2019-09-24

## README

# Key Nodes
Tree nodes for key and key/value pairs in object path hierarchies.

## [KeyNode](https://mikepricedev.github.io/keyNodes/classes/keynode.html "KeyNode")
Tree node for keys.

### Example:
```
import {KeyNode} from 'key-nodes';

// Start with root key node.
const foo = new KeyNode('foo');

console.log(foo.key); // "foo"

// Add sibling root key node
const bar = foo.addSibling('bar');

console.log(foo.hasSibling('bar')); // true
console.log(bar.hasSibling('foo')); // true

// Add child key node
const baz = foo.addChild('baz');

console.log(foo.hasChild('baz')); // true

// Add child to baz key node
const qux = baz.addChild('qux');

console.log(baz.hasChild('qux')); // true

// Add indexes
const arr0 = qux.addChild(0);

console.log(arr0.keyType); // "index"
console.log(qux.keyType); // "key"

```

## [KeyValueNode](https://mikepricedev.github.io/keyNodes/classes/keyvaluenode.html "KeyValueNode")
Tree node for key/value pairs.

### Example:
```
import {KeyValueNode} from 'key-nodes';

// Start with root key/value node.
const foo = new KeyValueNode('foo');

console.log(foo.key); // "foo"

// Add sibling root key/value node with value.
const bar = foo.addSibling('bar', 11);

console.log(foo.hasSibling('bar')); // true
console.log(bar.hasSibling('foo')); // true

console.log(bar.value); // 11

// Track value history up to 2 changes
bar.keepHistory = 2;

// Change bar value
bar.value = 13;

console.log(bar.value); // 13

// Undo value change
bar.undo();

console.log(bar.value); // 11

// Redo value change
bar.redo();

console.log(bar.value); // 13

// Stop tracking history
bar.keepHistory = false;
bar.value = 17;

console.log(bar.value); // 17
console.log( bar.undo() ); // false
console.log(bar.value); // 17

// Add child key/value node
const baz = foo.addChild('baz');

console.log(foo.hasChild('baz')); // true

// Add indexes with values
const arr0 = baz.addChild(0, 'Value at index 0');
const arr1 = baz.addChild(1, 'Value at index 1');


console.log(arr0.value); // "Value at index 0"
console.log(arr1.value); // "Value at index 1"

console.log(arr1.keyType); // "index"
console.log(baz.keyType); // "key"
```

#
Full [docs](https://mikepricedev.github.io/keyNodes "docs").

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