blob: 440ed15b69822984f8ec2da23e21a7bfbcc78229 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
export default class {
constructor(rows) {
this.rows = rows;
}
download() {
// XXX: should escape various things, but the quick-n-dirty
// calls.
const data = 'sequence 1,sequence 2,identity\r\n' + 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);
}
}
|