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');
tree.getGrouped('first.second');
removing items:
var KeyTree = require('key-tree-store');
var tree = new KeyTree();
var obj1 = {obj: '1'};
tree.add('key.path', obj1);
tree.remove(obj1);
running items:
var KeyTree = require('key-tree-store');
var tree = new KeyTree();
tree.add('key.path', function () {
console.log('function ran!');
});
tree.run('key');
tree.run('key', {some: 'object'});
tree.run('key', {some: 'object'}, 'arg1', 'arg2');
credits
If you like this follow @HenrikJoreteg on twitter.
license
MIT