@@ -62,6 +62,7 @@ class JSON2CSVBase {
62
62
const processedRow = ( this . opts . unwind && this . opts . unwind . length )
63
63
? this . unwindData ( row , this . opts . unwind )
64
64
: [ row ] ;
65
+
65
66
if ( this . opts . flatten ) {
66
67
return processedRow . map ( this . flatten ) ;
67
68
}
@@ -231,32 +232,30 @@ class JSON2CSVBase {
231
232
* @returns {Array } Array of objects containing all rows after unwind of chosen paths
232
233
*/
233
234
unwindData ( dataRow , unwindPaths ) {
234
- return Array . prototype . concat . apply ( [ ] ,
235
- unwindPaths . reduce ( ( data , unwindPath ) =>
236
- Array . prototype . concat . apply ( [ ] ,
237
- data . map ( ( dataEl ) => {
238
- const unwindArray = lodashGet ( dataEl , unwindPath ) ;
239
-
240
- if ( ! Array . isArray ( unwindArray ) ) {
241
- return dataEl ;
242
- }
243
-
244
- if ( unwindArray . length ) {
245
- return unwindArray . map ( ( unwindEl ) => {
246
- const dataCopy = lodashCloneDeep ( dataEl ) ;
247
- lodashSet ( dataCopy , unwindPath , unwindEl ) ;
248
- return dataCopy ;
249
- } ) ;
250
- }
251
-
252
- const dataCopy = lodashCloneDeep ( dataEl ) ;
253
- lodashSet ( dataCopy , unwindPath , undefined ) ;
254
- return dataCopy ;
255
- } )
256
- ) ,
257
- [ dataRow ]
258
- )
235
+ return unwindPaths
236
+ . reduce ( ( data , unwindPath ) =>
237
+ data . map ( ( dataEl ) => {
238
+ const unwindArray = lodashGet ( dataEl , unwindPath ) ;
239
+
240
+ if ( ! Array . isArray ( unwindArray ) ) {
241
+ return dataEl ;
242
+ }
243
+
244
+ if ( unwindArray . length ) {
245
+ return unwindArray . map ( ( unwindEl ) => {
246
+ const dataCopy = lodashCloneDeep ( dataEl ) ;
247
+ lodashSet ( dataCopy , unwindPath , unwindEl ) ;
248
+ return dataCopy ;
249
+ } ) ;
250
+ }
251
+
252
+ const dataCopy = lodashCloneDeep ( dataEl ) ;
253
+ lodashSet ( dataCopy , unwindPath , undefined ) ;
254
+ return dataCopy ;
255
+ } ) . reduce ( ( tempData , rows ) => tempData . concat ( rows ) , [ ] ) ,
256
+ [ dataRow ]
259
257
)
258
+ . reduce ( ( tempData , rows ) => tempData . concat ( rows ) , [ ] ) ;
260
259
}
261
260
}
262
261
0 commit comments