Socket
Book a DemoInstallSign in
Socket

json-key-map

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-key-map

A module for mapping between JSON keys and values

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
7
250%
Maintainers
1
Weekly downloads
 
Created
Source

json-key-map

A module for mapping between JSON keys and values

Install

npm install json-key-map

Usage

const JsonKeyMap = require("json-key-map");
const map = new JsonKeyMap();
map.set({ foo: 1, bar: 2 }, "test-value");
map.get({ foo: 1, bar: 2 });
//=> 'test-value'

API

new JsonKeyMap([entries, [options]])

entries

Type: JsonKeyMap Object

Elements to populate the JsonKeyMap with. Object inputs must be in the same form as those created by the JsonKeyMap.prototype.toJSON() method.

const map1 = new JsonKeyMap();
const map2 = new JsonKeyMap(map1);
const map3 = new JsonKeyMap({ '{"foo":1,"bar":2}': "test-value" });

options

Type: Object

keyParser

Type: Function
Default: JSON.parse

Parses strings into the keys they represent.

keyStringifier

Type: Function
Default: JSON.stringify

Converts keys into strings.

const stringify = require("json-stable-stringify");
const map = new JsonKeyMap(undefined, { keyStringifier: stringify });

JsonKeyMap.prototype.clear()

Removes all key/value pairs from the JsonKeyMap.

JsonKeyMap.prototype.delete(key)

Returns true if a element in the JsonKeyMap existed and has been removed, or false if the element does not exist.

key

Type: Array Object string number boolean null

The key of the element to be deleted.

JsonKeyMap.prototype.entries()

Returns a new Iterator object that contains an array of [key, value] for each element in the JsonKeyMap.

JsonKeyMap.prototype.forEach(callbackFn)

Calls callbackFn once for each element present in the JsonKeyMap.

JsonKeyMap.prototype.get(key)

Returns the value associated to the key, or undefined if there is none.

key

Type: Array Object string number boolean null

The key of the element to be returned.

JsonKeyMap.prototype.has(key)

Returns a boolean asserting whether a value has been associated to the key in the JsonKeyMap or not.

key

Type: Array Object string number boolean null

The key of the element to be found.

JsonKeyMap.prototype.keys()

Returns a new Iterator object that contains the keys for each element in the JsonKeyMap.

JsonKeyMap.prototype.set(key, value)

Sets the value of the key in the JsonKeyMap. Returns the JsonKeyMap.

key

Type: Array Object string number boolean null

The key to set the value for.

value

Type: any

The value to store.

JsonKeyMap.prototype.size

Type: number

The number of elements in the JsonKeyMap.

JsonKeyMap.prototype.toJSON()

Returns an Object containing all elements in the JsonKeyMap.

const map = new JsonKeyMap();
map.set({ foo: 1, bar: 2 }, "test-value");
const json = JSON.stringify(map);
console.log(JSON.parse(json));
//=>{ '{"foo":1,"bar":2}': "test-value" }
const map2 = new JsonKeyMap(JSON.parse(json));

JsonKeyMap.prototype.values()

Returns a new Iterator object that contains the values for each element in the JsonKeyMap.

JsonKeyMap.prototype[@@iterator]()

Returns a new Iterator object that contains an array of [key, value] for each element in the JsonKeyMap.

  • composite-map - A module for mapping between multi-part keys and values.
  • composite-object - A module for mapping between multi-part string keys and values.

License

MIT

Sources

Some text from this readme was sourced from developer.mozilla.org.

Keywords

json

FAQs

Package last updated on 03 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.