Created
January 21, 2019 14:44
-
-
Save PCouaillier/9bf091038f26d7673f96f7055521f619 to your computer and use it in GitHub Desktop.
exportVar
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
function exportVar(varToExport, filename) { | |
if (varToExport === undefined) { throw new Error('undefined var'); } | |
if (!filename) { | |
filename = 'exportedVar.json'; | |
} | |
const fileBlob = new File([JSON.stringify(varToExport)], filename); | |
const dowloader = document.createElement('a'); | |
dowloader.setAttribute('download', filename); | |
const url = URL.createObjectURL(fileBlob); | |
dowloader.setAttribute('href', url); | |
document.body.appendChild(dowloader); | |
dowloader.click(); | |
requestIdleCallback(() => { | |
URL.revokeObjectURL(url); | |
document.body.removeChild(dowloader); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment