1.2.2 • Published 11 years ago
@schornio/map-object v1.2.2
map-object
Usage
_constructor(map, options)
map: map schemaoptions: (optional) configurationstrictMode: error on unsuccessful mapping (default: ignore)context: provide a context object
prototype.map(obj, callback)
obj: object to mapcallback(error, obj): on mapping finished
Map Schema
{
  <string: destination name>: <string: source path>,
  <string: destination name>: <string: '$' + context source path>,
  <string: destination name>: <object: nested schema>
}Example
var MapObjLib = require('@schornio/map-object');
var obj = {
  simpleProperty: 42,
  complexProperty: {
    child: 126
  }
};
var map = {
  flattern: 'complexProperty.child',
  explode: {
    child: 'simpleProperty'
  }
};
var objMap = new MapObjLib(map);
objMap.map(obj, function(error, result) {
  /* result == {
    flattern: 126,
    explode: {
      child: 42
    }
  }*/
});