Skip to content

Instantly share code, notes, and snippets.

@albinekb albinekb/download.js
Last active Sep 25, 2018

Embed
What would you like to do?
function download(csv) {
if (csv == null) return
const filename = `export-${new Date()}.csv`
if (!csv.match(/^data:text\/csv/i)) {
csv = 'data:text/csv;charset=utf-8,' + csv
}
const data = encodeURI(csv)
const link = document.createElement('a')
link.setAttribute('href', data)
link.setAttribute('download', filename)
link.click()
}
export { download }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.