offers simple transformations for object literals
$ npm install --save oniyi-object-transform
const transform = require('oniyi-object-transform');
Transforms one object into another
Kind: global function
Returns: Object
- result of transforms applied to params.source
Param | Type | Description |
---|---|---|
params | Object |
describing the function arguments |
params.source | Object |
source object to be transformed. takes precendence over params.src |
[params.src] | Object |
alias for params.source |
[params.target] | Object |
target object to join the transformed source into |
[params.method] | String |
name of method to be used when joining results from pick and map . Options are: [merge , assign , defaults , defaultsDeep ]. For details see lodash documentation: https://lodash.com/docs#assign |
[params.map] | Object |
key => value map of source properties to be copied to target with a different name |
[params.whitelist] | Array.<String> |
list of strings that are allowed as params.map values. This feature is helpful when you transform from one object to a specified schema and want to restrict target names of params.map to the list of schema keys |
[params.pick] | Array.<String> |
properties to be picked from source and copied to target with the same name |
[params.parse] | Object |
key => value map of target properties to be run through value parsers. Value can be either of type String to reference one of the built-in parsers [integer , date , lowercase , uppercase , trim ] or of type Function to be called with the original value as single argument. |
Apache-2.0 © Benjamin Kroeger