object-transform-stack
v3.3.0
Published
Simple module to map one object to another using a stack of declarative pointers and transforms
Downloads
18
Maintainers
Readme
object-transform-stack
Install
npm install object-transform-stack --save
Usage
import { transform } from 'object-transform-stack'
const transforms = {
trim: {
name: 'Trim',
signature: [
{
name: 'Text',
types: [ 'string' ],
required: true
}
],
returns: 'string',
execute: (v) => v.trim()
}
}
const stack = {
bday: { field: 'birth' },
name: {
transform: 'trim',
arguments: [ { field: 'name.legal' } ]
}
}
const input = {
name: {
legal: 'Don Adams',
preferred: 'Donny'
},
birth: '11/12/27'
}
console.log(await transform(stack, input, { transforms }))
/*
Prints:
{
"bday": "2027-11-12T05:00:00.000Z",
"name": "Don Adams"
}
*/