@@ -248,39 +248,41 @@ function createColumnContent(params, str) {
248
248
stringifiedElement = JSON . stringify ( val ) ;
249
249
}
250
250
251
- if ( params . preserveNewLinesInValues && typeof val === 'string' ) {
252
- stringifiedElement = stringifiedElement
253
- . replace ( / \u2028 / g, '\n' )
254
- . replace ( / \u2029 / g, '\r' ) ;
255
- }
256
-
257
- if ( typeof val === 'object' ) {
258
- // In some cases (e.g. val is a Date), stringifiedElement is already a quoted string.
259
- // Strip the leading and trailing quote if so, so we don't end up double-quoting it
260
- stringifiedElement = replaceQuotationMarks ( stringifiedElement , '' ) ;
261
-
262
- // If val is a normal object, we want to escape its JSON so any commas etc
263
- // don't get interpreted as field separators
264
- stringifiedElement = JSON . stringify ( stringifiedElement ) ;
265
- }
266
-
267
- if ( params . quote !== '"' ) {
268
- stringifiedElement = replaceQuotationMarks ( stringifiedElement , params . quote ) ;
251
+ if ( stringifiedElement !== undefined ) {
252
+ if ( params . preserveNewLinesInValues && typeof val === 'string' ) {
253
+ stringifiedElement = stringifiedElement
254
+ . replace ( / \u2028 / g, '\n' )
255
+ . replace ( / \u2029 / g, '\r' ) ;
256
+ }
257
+
258
+ if ( typeof val === 'object' ) {
259
+ // In some cases (e.g. val is a Date), stringifiedElement is already a quoted string.
260
+ // Strip the leading and trailing quote if so, so we don't end up double-quoting it
261
+ stringifiedElement = replaceQuotationMarks ( stringifiedElement , '' ) ;
262
+
263
+ // If val is a normal object, we want to escape its JSON so any commas etc
264
+ // don't get interpreted as field separators
265
+ stringifiedElement = JSON . stringify ( stringifiedElement ) ;
266
+ }
267
+
268
+ if ( params . quote !== '"' ) {
269
+ stringifiedElement = replaceQuotationMarks ( stringifiedElement , params . quote ) ;
270
+ }
271
+
272
+ //JSON.stringify('\\') results in a string with two backslash
273
+ //characters in it. I.e. '\\\\'.
274
+ stringifiedElement = stringifiedElement . replace ( / \\ \\ / g, '\\' ) ;
275
+
276
+ if ( params . excelStrings && typeof val === 'string' ) {
277
+ stringifiedElement = '"="' + stringifiedElement + '""' ;
278
+ }
279
+
280
+ //Replace single quote with double quote. Single quote are preceeded by
281
+ //a backslash, and it's not at the end of the stringifiedElement.
282
+ stringifiedElement = stringifiedElement . replace ( / ( \\ " ) (? = .) / g, params . doubleQuote ) ;
283
+
284
+ line += stringifiedElement ;
269
285
}
270
-
271
- //JSON.stringify('\\') results in a string with two backslash
272
- //characters in it. I.e. '\\\\'.
273
- stringifiedElement = stringifiedElement . replace ( / \\ \\ / g, '\\' ) ;
274
-
275
- if ( params . excelStrings && typeof val === 'string' ) {
276
- stringifiedElement = '"="' + stringifiedElement + '""' ;
277
- }
278
-
279
- //Replace single quote with double quote. Single quote are preceeded by
280
- //a backslash, and it's not at the end of the stringifiedElement.
281
- stringifiedElement = stringifiedElement . replace ( / ( \\ " ) (? = .) / g, params . doubleQuote ) ;
282
-
283
- line += stringifiedElement ;
284
286
}
285
287
286
288
line += params . delimiter ;
0 commit comments