array mapping wraps destination in an unwanted array
As shown in my codesandbox, I tried to map as suggested in your readme, but I didn't find a way to remove the wrapping array from the destination object
const src = {
foo: [{ bar: 4 }, { bar: 33 }]
};
const mapper = {
"foo[].bar": "[]",
}
const res = map(src, mapper);
// res = [ [ 4, 33 ] ]
// i would expect [4, 33]
I would not expect to have a wrapping array in the result, and this behavior is a big restriction IMHO, because, for example, it seems impossible to use "append" + operator (useful to me) in order to build a collection from this object:
const src = {
foo: [{ bar: 4 }, { bar: 33 }],
bifoo: [{ bar: 77 }, { bar: 97 }]
};
const mapper = {
"foo[].bar": "[]+",
"bifoo[].bar": "[]+"
}
const res = map(src, mapper);
// res = [ [ 4, 33 ] ]
// i would expect [4, 33, 77, 97]
const mapper2 = {
"foo[].bar": "num[]+",
"bifoo[].bar": "num[]+"
}
const res = map(src, mapper2);
// res = { "num": [ [ 4, 33 ], [ 77, 97 ] ] }
// i would expect {"num": [4, 33, 77, 97] }
Why array items are not processed one at a time? Is it possible to easily achieve what I would like to?
@lsimone Facing the same issue. Have you found any solution to this?
not yet @shwetajoshi601 .
I'd like to solve it, maybe I'll fork because there are other use cases that I would like to handle...like computing destination value from several sources (i.e: dest.name = src.firstName || src.lastName )
I see your point. The current functionality of + is specified as: stop what you are doing and add the data onto an array, for each item that has the +. I am not sure of the use case for this. @wankdanker may want to weigh in. I modified so that the + is specified as: add the results of this key to the existing array. If @wankdanker wants to leave as is, I'll back out this change.