# data_by_key

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

Latest version **0.0.1** (published 2015-02-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install data_by_key
pnpm add data_by_key
yarn add data_by_key
bun add data_by_key
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2015-02-14 |
| First published | 2015-02-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | bobbwhy |
| Keywords | data, object, json, data, cache |

## Links

- npm: https://www.npmjs.com/package/data_by_key
- Repository: https://github.com/bobbwhy/data_by_key
- Issues: https://github.com/bobbwhy/data_by_key/issues
- npm.io page: https://npm.io/package/data_by_key

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.1 (latest) — 2015-02-14

## 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");

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