const source = {
data: [
{
content: {
name: 'An interesting piece',
meta: {
author: 'fredj',
date: 1533750490952
}
}
}
]
}
const def = [
'data[0].content',
{
title: 'name',
author: 'meta.author',
},
]
//docs: provide MapTransform with a target that the transformation will be applied to
const target = { id: '12345', title: 'Default title' }
const result = await mapTransform(def)(source, { target })
//expect:
//{
// id: '12345',
// title: 'An interesting piece',
// author: 'fredj',
//}
//returns (=> no id field):
//{
// title: 'An interesting piece',
// author: 'fredj',
//}
Using:
map-transform@1.5.4