Here is the source code which could be used to convert text to file and trigger download
function getOrCreateDownloadLink() {
var $link = $('#downloadLink');
if ($link.length === 0) {
$link = $('<a id="downloadLink">download</a>').appendTo('body');
}
$link.hide();
return $link;
}
function saveAsTextFile(text, fileName) {
var textFileAsBlob = new Blob([text], { type:'text/plain' }),
$downloadLink = getOrCreateDownloadLink();
$downloadLink.attr('download', fileName || 'file');
if (typeof window.URL !== 'undefined') {
$downloadLink.attr('href', window.URL.createObjectURL(textFileAsBlob));
}
$downloadLink.get(0).click();
}
function getOrCreateUploadLink() {
var $link = $('#uploadLink');
if ($link.length === 0) {
$link = $('<input type="file" id="uploadLink" />').appendTo('body');
}
$link.hide();
return $link;
}
function loadTextFile(callback) {
var $link = getOrCreateUploadLink(),
reader = new FileReader();
reader.onload = function(evt) {
callback(evt.target.result);
};
$link.change(function() {
reader.readAsText($link.get(0).files[0], 'UTF-8');
$link.val('');
});
$link.click();
}