transform property should accept transformer
Closed this issue · 1 comments
I am trying to parse big arrays of objects and it would be awesome if the transform property also accepts a transformer.
Example:
const transformPerson = (obj) => {
return createTransformer({
personId: 'id',
surname: 'name'
})
}
const source = {
items: [
{
id: 5,
name: 'Test'
},
{
id: 6,
name: 'another'
}
]
}
const applyTransform = createTransformer({
items: { transform: transformPerson, iterate: true}
})
applyTransform(source).then(output => console.dir(output))
Output: { items: [ [AsyncFunction], [AsyncFunction] ] }
Expected output: { items: [ { personId: 5, surname: 'Test' }, { personId: 6, surname: 'another' } ] }
Since you closed this issue I'll assume that you figured it out yourself, but just in case someone else is facing a similar issue: createTransformer()
returns a function which will then accept raw source data. So the transformPerson
function above would always return a new function, which is why the output for the items
array consisted of [AsyncFunction]
values.
The solution here is to assign the return value of createTransformer
to transformPerson
like so:
const transformPerson = createTransformer({
personId: 'id',
surname: 'name'
})