npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

key-tree-store

v1.3.0

Published

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

Downloads

114,252

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:

{
    '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'});

// 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:

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:

// 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 on twitter.

license

MIT