UNPKG

cutls

Version:

Some JavaScript util functions.

26 lines (20 loc) • 626 B
/** * Download a file with the the text passed as parameter. * @param filename * @param content * @param contentType */ function download (filename, content, contentType = 'text/json') { const element = document.createElement('a') const blob = new Blob([content], { type: contentType }) element.href = window.URL.createObjectURL(blob) element.download = filename element.dataset.downloadurl = [contentType, element.download, element.href].join(':') element.style.display = 'none' document.body.appendChild(element) element.click() document.body.removeChild(element) } export default { download }