diff options
Diffstat (limited to 'csv-dump.mjs')
| -rw-r--r-- | csv-dump.mjs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/csv-dump.mjs b/csv-dump.mjs new file mode 100644 index 0000000..76e1e08 --- /dev/null +++ b/csv-dump.mjs @@ -0,0 +1,22 @@ +export default class { + constructor(rows) { + this.rows = rows; + } + + download() { + // XXX: should escape various things, but the quick-n-dirty + // calls. + const data = this.rows.map(row => row.join(',')).join('\r\n'); + const file = new Blob([data], { type: 'text/csv' }) + let a = document.createElement('a'); + const url = URL.createObjectURL(file); + a.href = url; + a.download = 'filename.csv'; + document.body.appendChild(a); + a.click(); + setTimeout(_ => { + document.body.removeChild(a); + URL.revokeObjectURL(url); + }, 0); + } +} |
