deep-map-object v0.0.5
The utility for deep mapping object keys and values
Why deep-map-object?
The util help facilitating the deep transform from one object to another by given helpers function.
Install:
npm i deep-map-object
Usage:
ES6
import deepMap from 'deep-map-object'; const options = { return value + 1;}; const data = x: 1 y: z: 2 3 t: 4 ; const result = data; console;/*{ x: 2, y: { z: [3, 4], t: 5 }}*/
ES5
var deepMap = ; var { return value + 1;}; var data = x: 1 y: z: 2 3 t: 4 ; var result = data; console;/*{ x: 2, y: { z: [3, 4], t: 5 }}*/
Api:
deepMap(options)(obj)
deepMap: function(options: function|object) => (resolve: function(value: any) => result:any)
- deepMap(options) will create a resolve function which can transform(resolve) object into another format.
- the resolve function is the util function that help you to loop deeper into input value.
- options may be a function that take a primitive value and transform it to target value or may take a object with below format:
import deepMap from 'deep-map-object'; const data = x: 1 ; const result = data; console; // {x : 2}
mapValue: function(value: primitive, resolve: function(value: any))
import deepMap from 'deep-map-object'; const data = x: 1 ; const result = data; console; // {x : 2}
mapArray: function(value: array, resolve: function(value: any))
import deepMap from 'deep-map-object'; const data = a: 1 2 3 ; const result = data; console; // { a: [2, 3, 4] };
mapObject: function(value: object, resolve: function(value: any))
import deepMap from 'deep-map-object'; const data = a: num: 0 b: num: 1 ; const result = data; console; // { a: { num: 0 }, b: { num: 2 } };
mapFn: function(value:any, resolve: function(value: any))
// If mapFn is used, mapValue, mapArray, mapObject options will be disabled
import deepMap from 'deep-map-object'; const data = a: num: 0 c: d: 1 2 ; const result = data; console; // { a: { num: 1 }, c: { d: [2, 3] } };
- Based on the type of variable we want to convert, it may be object, array or primitive value.
- deepMap internally support you to loop deeply in nested object, so you only need to care about transform business
Static functions
deepMap.mapArray: function(value: array, resolve: function(value: any))
- default mapArray util which run resolve to every array's items
deepMap.mapObject: function(value: object, resolve: function(value: any))
- default mapObject util which run resolve to every object's key