Skip to content

Commit 176e082

Browse files
pichimledvinap
andauthored
Replace non valid values with NaN instead of "" in csv export (#660)
* Replace non valid values with 0 instead of "" in csv export * Changes according to PR comments * Removed redundant double negation * Removed unnecessary use of conditional expression for default assignment. * Update js/webworkers/csv-export-worker.js Co-authored-by: Petr Ledvina <[email protected]> --------- Co-authored-by: Petr Ledvina <[email protected]>
1 parent d5c4f6c commit 176e082

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

js/webworkers/csv-export-worker.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,29 @@ onmessage = function(event) {
2525
.join(opts.columnDelimiter);
2626
}
2727

28+
/**
29+
* Converts `null` entries in columns and other empty non-numeric values to NaN value string.
30+
*
31+
* @param {array} columns
32+
* @returns {string}
33+
*/
34+
function joinColumnValues(columns) {
35+
return _(columns)
36+
.map(value =>
37+
(_.isNumber(value) || _.value)
38+
? value
39+
: "NaN")
40+
.join(opts.columnDelimiter);
41+
}
42+
2843
let opts = event.data.opts,
2944
stringDelim = opts.quoteStrings
3045
? opts.stringDelimiter
3146
: "",
3247
mainFields = _([joinColumns(event.data.fieldNames)])
3348
.concat(_(event.data.frames)
3449
.flatten()
35-
.map(row => joinColumns(row))
50+
.map(row => joinColumnValues(row))
3651
.value())
3752
.join("\n"),
3853
headers = _(event.data.sysConfig)

0 commit comments

Comments
 (0)