Created
March 15, 2025 01:53
-
-
Save wesleybliss/2237998a165962dfbf35d633369e32bd to your computer and use it in GitHub Desktop.
Download a string as a file
This file contains 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
const downloadCsv = (text, filename, encoding = 'text/plain') => { | |
// text/csv | |
const blob = new Blob([csvString], { type: encoding }) | |
const url = window.URL.createObjectURL(blob) | |
const a = document.createElement('a') | |
a.setAttribute('href', url) | |
a.setAttribute('download', filename || 'download.txt') | |
a.style.display = 'none' | |
document.body.appendChild(a) | |
a.click() | |
document.body.removeChild(a) | |
window.URL.revokeObjectURL(url) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment