Created
April 18, 2020 04:41
-
-
Save ericsoco/57483b0b569545c79b830ed590f424df to your computer and use it in GitHub Desktop.
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
// Based on Brian Grinstead's console.save() | |
// http://bgrins.github.io/devtools-snippets/#console-save | |
(function(console){ | |
console.saveCsv = function(data, filename){ | |
if(!data) { | |
console.error('Console.saveCsv: No data') | |
return; | |
} | |
if(!filename) filename = 'console.csv' | |
if(Array.isArray(data)){ | |
data = data.reduce((csv, row) => { | |
csv += (row.join(',') + '\n'); | |
return csv; | |
}, ''); | |
} | |
console.log(data); | |
var blob = new Blob([data], {type: 'text/csv'}), | |
e = document.createEvent('MouseEvents'), | |
a = document.createElement('a') | |
a.download = filename | |
a.href = window.URL.createObjectURL(blob) | |
a.dataset.downloadurl = ['text/csv', a.download, a.href].join(':') | |
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) | |
a.dispatchEvent(e) | |
} | |
})(console) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment