# key-tree-store

> Simple tool for storing/retrieving objects events based hierarchical keypaths.

Latest version **1.3.0** (published 2015-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install key-tree-store
pnpm add key-tree-store
yarn add key-tree-store
bun add key-tree-store
```

## 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.3.0 |
| Published | 2015-08-08 |
| First published | 2014-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Henrik Joreteg |
| Maintainers | henrikjoreteg, latentflip, pgilad |
| Keywords | events, keypath, trigger |

## Links

- npm: https://www.npmjs.com/package/key-tree-store
- Repository: https://github.com/HenrikJoreteg/key-tree-store
- Issues: https://github.com/HenrikJoreteg/key-tree-store/issues
- npm.io page: https://npm.io/package/key-tree-store

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.3.0 (latest) — 2015-08-08
- 1.2.1 — 2015-07-21
- 1.2.0 — 2014-06-21
- 1.1.0 — 2014-06-21
- 1.0.0 — 2014-06-14
- 0.3.0 — 2014-06-05
- 0.2.0 — 2014-06-04
- 0.1.2 — 2014-06-02
- 0.1.1 — 2014-05-30
- 0.1.0 — 2014-05-29

## README

# key-tree-store

Simple tool for storing/retrieving objects events based hierarchical keypaths.

It lets you store and retrive objects that are at an equal or deeper key path than what you give it.

## install

```
npm install key-tree-store
```

## example

Assume you've got a structure like this:

```js
{
    'first': [ {obj: 1}, {obj: 2} ],
    'first.stuff': [ {obj: 3} ],
    'first.something.other': [ {obj: 4}, {obj: 5} ]
}
```

Then you can retrive it by key. Where it returns anything at or deeper than level supplied. 

```javascript
var KeyTree = require('key-tree-store');

var tree = new KeyTree();

tree.add('first', {id: 'one'});
tree.add('first.second', {id: 'two'});
tree.add('first.second', {id: 'three'});
tree.add('first.second.third', {id: 'four'});

// now we can retrieve them by key
tree.get('first'); // returns all of them
tree.get('first.second'); // returns array of objects two, three and four
tree.get('first.second.third'); // returns array of object four;

// the `get` method returns them all in an array
// if we still need them grouped by key we can use
// `getGrouped`
tree.getGrouped('first.second'); // returns {'first.second': [...], 'first.second.third': [...]}

// calling `.get()` or `.getGrouped` without arguments
// returns all in appropriate format

// that's all there is to it

```

removing items:

```javascript
var KeyTree = require('key-tree-store');

var tree = new KeyTree();
var obj1 = {obj: '1'};

tree.add('key.path', obj1);

// removes it no matter what key
tree.remove(obj1);
```

running items:

```javascript
// as a shortcut, there's also the `run` method
// to help you run functions that match they keypath
// this assumes you're storing functions, of course.
var KeyTree = require('key-tree-store');

var tree = new KeyTree();

tree.add('key.path', function () {
    console.log('function ran!');
});

tree.run('key'); //=> function ran!

// you can also optionally pass a context or arguments to run them with
tree.run('key', {some: 'object'});

// with arguments
tree.run('key', {some: 'object'}, 'arg1', 'arg2');

```

## credits

If you like this follow [@HenrikJoreteg](http://twitter.com/henrikjoreteg) on twitter.

## license

MIT

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