@@ -478,6 +478,41 @@ export function runTests() {
478478 assert . equal ( csv , updatedCsv ) ;
479479 } ) ;
480480
481+ // Test case for #244
482+ it ( 'should exclude a matched key prefix from the output when unwinding arrays' , ( ) => {
483+ const updatedCsv = csvTestData . unwind . replace ( ',data.options.name' , '' )
484+ . replace ( / , M a c B o o k ( P r o | A i r ) \d + / g, '' )
485+ . replace ( / , ( S u p e r | T u r b o ) c h a r g e r / g, '' )
486+ . replace ( '5cf7ca3616c91100018844af,Computers\n' , '' )
487+ // Remove duplicate lines
488+ . replace ( '5cf7ca3616c91100018844bf,Cars\n' , '' ) ;
489+
490+ const csv = json2csv ( jsonTestData . unwind , {
491+ unwindArrays : true ,
492+ expandArrayObjects : true ,
493+ excludeKeys : [ 'data.options' ]
494+ } ) ;
495+
496+ assert . equal ( csv , updatedCsv ) ;
497+ } ) ;
498+
499+ // Test case for #244
500+ it ( 'should exclude a matched key prefix from the output when unwinding arrays' , ( ) => {
501+ const updatedCsv = csvTestData . unwind . replace ( ',data.category,data.options.name' , '' )
502+ . replace ( / , C o m p u t e r s , M a c B o o k ( P r o | A i r ) \d + / g, '' )
503+ . replace ( / , C a r s , ( S u p e r | T u r b o ) c h a r g e r / g, '' )
504+ . replace ( '5cf7ca3616c91100018844af\n' , '' )
505+ // Remove duplicate lines
506+ . replace ( '5cf7ca3616c91100018844bf\n' , '' ) ;
507+
508+ const csv = json2csv ( jsonTestData . unwind , {
509+ unwindArrays : true ,
510+ excludeKeys : [ 'data' ]
511+ } ) ;
512+
513+ assert . equal ( csv , updatedCsv ) ;
514+ } ) ;
515+
481516 it ( 'should use a custom value parser function when provided' , ( ) => {
482517 const updatedCsv = csvTestData . trimmedFields . split ( '\n' ) ;
483518 const textRow = 'Parsed Value,Parsed Value,Parsed Value,Parsed Value,Parsed Value' ;
0 commit comments