fileSaver = function (fileName, text) {
    fileName = fileName.replace(/[\\\/\*\:\?\"\|\>\<]/g, '-');
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie\s([\d.]+)/)) ? Sys.ie = s[1] :
    (s = ua.match(/trident.*rv:([\d.]+)/)) ? Sys.ie = s[1] :
    (s = ua.match(/edge\/([\d.]+)/)) ? Sys.ie = s[1] :
    (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
    (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
    (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
    (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
    if (Sys.ie) {
        if (Sys.ie < 10) {
            var oWin = window.top.open('about:blank', '_blank');
            oWin.document.write('\uFEFF' + text);
            oWin.document.close();
            oWin.document.execCommand('SaveAs', true, fileName);
            oWin.close();
        }
        else {
            navigator.msSaveBlob(new Blob(['\uFEFF' + text], { type: 'text/csv' }), fileName);
        }
    }
    else {
        var link = document.createElement("a");
        link.download = fileName;
        if (window.Blob && window.URL && window.URL.createObjectURL) {
            link.href = URL.createObjectURL(new Blob(['\uFEFF' + text], { type: 'text/csv' }));
        }
        else {
            link.href = 'data:text/csv;charset=utf-8,' + '\uFEFF' + text;
        }
        document.body.appendChild(link);
        if (Sys.safari) {
            var click_ev = document.createEvent("MouseEvents");
            click_ev.initEvent("click", true /* bubble */, true /* cancelable */);
            link.dispatchEvent(click_ev);
        }
        else {
            link.click();
        }
        document.body.removeChild(link);
    }
}