Skip to content

Commit d57b328

Browse files
author
Scott Switzer
committed
added commented out test for Including parent items in arrays wankdanker#50
1 parent 7d8252d commit d57b328

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/object-mapper.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,13 @@ function update_arr(dest, key, data, keys, context)
251251
if (key.add) {
252252
if (data !== null && typeof data !== 'undefined') {
253253
dest = dest || []
254-
dest.push(data)
254+
//dest.push(data)
255+
dest = dest.concat(data)
255256
}
256257
return dest
257258
}
258259

259-
// Make sure that there is an array item for each item in the data array
260+
// If the data is in an array format then make sure that there is a dest index for each data index
260261
if (Array.isArray(data)) {
261262
dest = dest || []
262263
// Loop through each index in the data array and update the destination object with the data

test/test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,3 +2202,35 @@ test('2 array mapping wraps destination in an unwanted array #49', function (t)
22022202
t.end();
22032203
});
22042204

2205+
// test('Including parent items in arrays #50', function (t) {
2206+
// const src = {
2207+
// "a": "AA",
2208+
// "b": "BB",
2209+
// "array": [
2210+
// { "x": "one" },
2211+
// { "x": "two" }
2212+
// ]
2213+
// };
2214+
// const map = {
2215+
// "array[].x": "results[].ex",
2216+
// "a": "results[].aye",
2217+
// "b": "results[].bee"
2218+
// }
2219+
// var expect = {
2220+
// "results": [
2221+
// {
2222+
// "aye": "AA",
2223+
// "bee": "BB",
2224+
// "ex": "one"
2225+
// },
2226+
// {
2227+
// "aye": "AA",
2228+
// "bee": "BB",
2229+
// "ex": "two"
2230+
// }
2231+
// ]
2232+
// };
2233+
// var result = om(src, map);
2234+
// t.deepEqual(result, expect);
2235+
// t.end();
2236+
// });

0 commit comments

Comments
 (0)