From 1e0f9fca72921f8d427d1a27935fd7dd59e375bf Mon Sep 17 00:00:00 2001 From: David Vegh Date: Mon, 26 Feb 2024 11:04:13 +0100 Subject: [PATCH] documentation: csv file generation fixed --- tools/docs/examples/mjs2csv.mjs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/docs/examples/mjs2csv.mjs b/tools/docs/examples/mjs2csv.mjs index 108b5d1e..2d8d8bd6 100644 --- a/tools/docs/examples/mjs2csv.mjs +++ b/tools/docs/examples/mjs2csv.mjs @@ -15,8 +15,12 @@ class Js2csv { const line = [] const record = {} for (const j in this.data.series) { - record[this.data.series[j].name] = this.data.series[j].values[i] - line.push(this.data.series[j].values[i]) + let value = this.data.series[j].values[i] + if (typeof value === 'string' && value.includes(',')) { + value = `"${value}"` + } + record[this.data.series[j].name] = value + line.push(value) } if (this.data.filter) { if (!this.data.filter(record)) { @@ -27,10 +31,15 @@ class Js2csv { } getRecordLine(i) { - const line = this.data.records[i] + const line = [] const record = {} for (const j in this.data.series) { - record[this.data.series[j].name] = this.data.records[i][j] + let value = this.data.records[i][j] + if (typeof value === 'string' && value.includes(',')) { + value = `"${value}"` + } + record[this.data.series[j].name] = value + line.push(value) } if (this.data.filter) { if (!this.data.filter(record)) {