You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
684 B
20 lines
684 B
2 years ago
|
import { getRandomFileName } from './util';
|
||
2 years ago
|
|
||
|
export function exportAsFile(filename, data, type = 'text/csv') {
|
||
|
// eslint-disable-next-line no-param-reassign
|
||
|
filename = filename || getRandomFileName();
|
||
|
// source: https://stackoverflow.com/a/33542499 by Ludovic Feltz
|
||
|
const blob = new window.Blob([data], { type });
|
||
|
if (window.navigator.msSaveOrOpenBlob) {
|
||
|
window.navigator.msSaveBlob(blob, filename);
|
||
|
} else {
|
||
|
const elem = window.document.createElement('a');
|
||
|
elem.target = '_blank';
|
||
|
elem.href = window.URL.createObjectURL(blob);
|
||
|
elem.download = filename;
|
||
|
document.body.appendChild(elem);
|
||
|
elem.click();
|
||
|
document.body.removeChild(elem);
|
||
|
}
|
||
|
}
|