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:
{
'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.
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'});
tree.get('first');
tree.get('first.second');
tree.get('first.second.third');
removing items:
var KeyTree = require('key-tree-store');
var tree = new KeyTree();
var obj1 = {obj: '1'};
tree.add('key.path', obj1);
tree.remove(obj1);
credits
If you like this follow @HenrikJoreteg on twitter.
license
MIT