Extracted helper function to generate a Csv file

This commit is contained in:
Alejandro Celaya
2021-03-14 11:47:23 +01:00
parent 1594717f33
commit 3f3523b80f
3 changed files with 17 additions and 42 deletions

12
src/utils/helpers/csv.ts Normal file
View File

@@ -0,0 +1,12 @@
export const saveCsv = ({ document }: Window, csv: string, filename: string) => {
const link = document.createElement('a');
const blob = new Blob([ csv ], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', filename);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};