A module for mapping between JSON keys and values
npm install json-key-map
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'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" });Type: Object
Type: Function
Default: JSON.parse
Parses strings into the keys they represent.
Type: Function
Default: JSON.stringify
Converts keys into strings.
const stringify = require("json-stable-stringify");
const map = new JsonKeyMap(undefined, { keyStringifier: stringify });Removes all key/value pairs from the JsonKeyMap.
Returns true if a element in the JsonKeyMap existed and has been removed, or false if the element does
not exist.
Type: Array Object string number boolean null
The key of the element to be deleted.
Returns a new Iterator object that contains an array of [key, value] for each element in the JsonKeyMap.
Calls callbackFn once for each element present in the JsonKeyMap.
Returns the value associated to the key, or undefined if there is none.
Type: Array Object string number boolean null
The key of the element to be returned.
Returns a boolean asserting whether a value has been associated to the key in the JsonKeyMap or not.
Type: Array Object string number boolean null
The key of the element to be found.
Returns a new Iterator object that contains the keys for each element in the JsonKeyMap.
Sets the value of the key in the JsonKeyMap. Returns the JsonKeyMap.
Type: Array Object string number boolean null
The key to set the value for.
Type: any
The value to store.
Type: number
The number of elements in the JsonKeyMap.
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));Returns a new Iterator object that contains the values for each element in the JsonKeyMap.
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.
Some text from this readme was sourced from developer.mozilla.org.