11import { Injectable } from '@angular/core' ;
2- import * as FileSaver from 'file-saver' ;
2+ import { saveAs } from 'file-saver' ;
33import { AutoCsvRowMapper } from './AutoCsvRowMapper' ;
44import { CsvConfiguration } from './CsvConfiguration' ;
55import { ICsvRowMapper } from './ICsvRowMapper' ;
@@ -17,7 +17,7 @@ export class Ng2CsvService {
1717 + ( config . includeHeaderLine ? 'present' : 'absent' ) ;
1818
1919 const csvBlob : Blob = new Blob ( [ csvData ] , { type : mimeType } ) ;
20- FileSaver . saveAs ( csvBlob , filename , true ) ;
20+ saveAs ( csvBlob , filename , true ) ;
2121 }
2222
2323 public convertToCsv < T > (
@@ -42,13 +42,30 @@ export class Ng2CsvService {
4242
4343 for ( const row of data ) {
4444 rows . push ( csvRowMapper . map ( row )
45+ . map ( x => this . mapNullOrUndefinedValues ( x , config ) )
4546 . map ( x => this . escapeRowValue ( x , config ) )
4647 . join ( config . delimiter ) ) ;
4748 }
4849
4950 return rows . join ( config . newLine ) ;
5051 }
5152
53+ private mapNullOrUndefinedValues (
54+ value : string ,
55+ config : CsvConfiguration ) : string {
56+ switch ( value ) {
57+ case null : {
58+ return config . outputValueForNull ;
59+ }
60+ case undefined : {
61+ return config . outputValueForUndefined ;
62+ }
63+ default : {
64+ return value ;
65+ }
66+ }
67+ }
68+
5269 private escapeQuotes (
5370 value : string ,
5471 quoteChar : string ) : string {
0 commit comments