Skip to content

Commit

Permalink
Merge pull request #298 from vizzuhq/doc_csv
Browse files Browse the repository at this point in the history
documentation: csv file generation fixed
  • Loading branch information
veghdev committed Feb 26, 2024
2 parents 6b252c4 + 1e0f9fc commit 4b1c90b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tools/docs/examples/mjs2csv.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down

0 comments on commit 4b1c90b

Please sign in to comment.