Last active
May 8, 2025 13:56
-
-
Save robertStrunk/1053b45a2fe9460d73b6e108120e8119 to your computer and use it in GitHub Desktop.
dload from chatgpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| downloadCsv(lines, filename = 'export.csv') { | |
| if (!lines || !lines.length) { | |
| console.error('No data to export'); | |
| return; | |
| } | |
| const csvContent = lines.join('\n'); | |
| // Use a safe MIME type | |
| const blob = new Blob([csvContent], { type: 'text/plain;charset=utf-8' }); | |
| // Create a download link | |
| const link = document.createElement('a'); | |
| link.href = URL.createObjectURL(blob); | |
| link.setAttribute('download', filename); | |
| // Append, trigger download, and clean up | |
| document.body.appendChild(link); | |
| link.click(); | |
| document.body.removeChild(link); | |
| URL.revokeObjectURL(link.href); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment