Exploring the transform()
functionality demonstrated in the Hoek documentation, is there a method to transform arrays within the source object?
For instance, modifying the example to work with an array structure, such as this:
var source = {
address: [
{
one: '123 main street',
two: 'PO Box 1234'
},
{
one: '456 fake street',
two: 'Apt 2b'
}],
title: 'Warehouse',
state: 'CA'
};
var result = Hoek.transform(source, {
'person.address.lineOne': 'address.one',
'person.address.lineTwo': 'address.two',
'title': 'title',
'person.address.region': 'state'
});
the output would be:
{
person: {
address: {
lineOne: undefined,
lineTwo: undefined,
region: 'CA'
}
},
title: 'Warehouse'
}
UPDATE: introducing expected outcome:
{
person: {
address: [{
lineOne: '123 main street',
lineTwo: 'PO Box 1234',
region: 'CA'
},
{
lineOne: '465 fake street',
lineTwo: 'Apt 2b',
region: 'CA'
}]
},
title: 'Warehouse'
}
I suspect that what I'm attempting may exceed the capabilities of this function, but I want to confirm it's not due to user error.
If it goes beyond the scope of hoek's transform, do you have any recommendations for efficiently mapping a JS object to a new object while assigning new key names?