There are two main functions: map and transform. They take a map from one reference list into an object to another reference list, and optionally one or more maps from the value at that location to a new value, and return a function that performs those maps when called on an object. The function map returns will return a new object when called, and transform's will change the original object.
Both map and transform also have a compose method that will combine several maps and transforms into a single function.
There are four map builder functions included: path and ref for the reference path map, and val and nomap for the value map.
.map( refMap [, valMap] )
Returns a function fn( object ) that calls refMap( refList ) and valMap( value, abort ) for every path to a leaf node in object, where refList is an array of keys representing the path and value is the value at that path, and returns a new object based on the results.
refMap should return an array of keys to map to in the result object, or a falsy value to not map the path.
valMap should return a value to map to in the result. If no valMap is given, the value will be unchanged. valMap can also be an array of functions, which will be called in order with each function getting the value returned by the last one. Any valMap function can call the abort callback, which will result in the path not being mapped even if refMap returned a new refList.
Examples
var jsonmap = require( 'json-map' )var map = jsonmap.map
This behaves the same as .map() in all respects except that the returned function will map changes onto the source object rather than returning a new object. refMap changes will result in properties being moved from the original path in the object to the new path.
A refMap function builder that will map any valid JavaScript reference expression from in the source object to the same path in the result, or to the expression to if specified.
A refMap function builder that will return any refList it is passed unchanged, mapping all paths on the object. Note that this is just the identity function function ( x ) { return x }.