README
Object Mapper
Maps objects by dot notation
Installation
npm install @aetherwave/object-mapper
Usage
ObjectMapper#constructor(mapSchema[, options])
mapSchema
: map schemaoptions
: (optional) configurationcontext
: Object, context, default:{}
mapEachElement
: Boolean, error if map path doesn't exist, default:false
stripEmptyObjects
: Boolean, ignore empty objects, default:true
ObjectMapper#map(mixed[, mapSchema])
mixed
: object to mapmapSchema
: map schema, default (this.mapSchema)
Map Schema
{
<string: destination name>: <string: source path>,
<string: destination name>: <string: '$.' + context source path>,
<string: destination name>: <object: nested schema>
}
Example
var ObjectMapper = require('@schornio/object-mapper');
var obj = {
simpleProperty: 42,
complexProperty: {
child: 126
}
};
var map = {
flattern: 'complexProperty.child',
explode: {
child: 'simpleProperty'
}
};
var objMap = new MapObjLib(map);
objMap.map(obj);
/* result == {
flattern: 126,
explode: {
child: 42
}
}*/
});
Test
npm test