2.0.1 • Published 10 years ago
@aetherwave/object-mapper v2.0.1
Object Mapper
Maps objects by dot notation
Installation
npm install @aetherwave/object-mapperUsage
ObjectMapper#constructor(mapSchema, options)
mapSchema: map schemaoptions: (optional) configurationcontext: Object, context, default:{}mapEachElement: Boolean, error if map path doesn't exist, default:falsestripEmptyObjects: 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 test2.0.1
10 years ago