mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-20 13:36:20 +00:00
Extracted helper function to generate a Csv file
This commit is contained in:
12
src/utils/helpers/csv.ts
Normal file
12
src/utils/helpers/csv.ts
Normal 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);
|
||||
};
|
||||
Reference in New Issue
Block a user