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

data_by_key

v0.0.1

Published

A set of functions to allow for pulling of data from hierarchical structures using a single key separated.. .useful for templates and the like

Downloads

2

Readme

  • Data By Key Module

This module allows reading elements from within multiple levels of a javascript data object by using character separated keys instead of the usual notation.

The motivation for this module was to support template engines, though there could well be other applications.

There are two basic functions in this module and a wrapper class.

Functions

byKey(key, dataObject, separator (optional)) *returns: the element at that the location specified by key param key is a string containing the nested keys of the desired item in the object.. param dataObject is a javascript object or array.
Key is parsed with the assumption that all the elements in the key are intended to be strings, unless the object at that level in the hierarchy is an array, in which case the key would be parsed into an integer.

param *separator* (optional) specifies which character will separate the nested keys in the string.  Default is "."

- example of two ways to return the value at obj["a"]["zero"]:
	- byKey("a.zero");
	- byKey("a/zero", "/");
	The second differs by specifying a separator character other than ".".

setByKey(key, dataObject, value, separator) returns( the original data object ) param key in the same as for byKey function. param dataObject is the same as for byKey function. param value is the value to be set at that location. param separator is the same as for byKey function.

- example of two ways to set the value "19551105" at obj["a"]["one"]:
	- setByKey("a.zero", 19551105);
	- setByKey("a.zero", 19551105, "/");

KeyedData Class

This class will encapsulate a data object as an instance variable and also a default character separator as an instance variable. It calls the byKey and setByKey functions on this data object.

To create a KeyedData instance:

var keyedData = new KeyedData(dataObject, separator);

To get a value from a KeyedData instance:

var value = keyedData.get("one.interiorkey");

To set a value in a KeyedData instance: keyedData.set("one.interiorkey", "trumanshow");