-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser-csv-exporter.min.js
1 lines (1 loc) · 3.16 KB
/
browser-csv-exporter.min.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CSVExporter=t():e.CSVExporter=t()}(window,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}();function r(e){return Object.prototype.toString.call(e).slice(8,-1)}function i(e){return(e=String(e)).indexOf(",")>-1||e.indexOf('"')>-1?'"'+(e=e.replace(/"/g,'""'))+'"':e}var c=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.data=t.data||[],this.fileName=(t.fileName||new Date)+".csv",this.csv="",this.columns=t.columns||[];var n="";this.columns.forEach((function(e){var t=""+("Object"===r(e)?e.title:e);t=i(t),n+=t+","})),this.csv+=n.slice(0,-1)+"\r\n",this.columns.length&&this.data.forEach((function(e){var t="",n="";this.columns.forEach((function(o,c){n="Object"===r(e)?e[o.key||o.title]:e[c],"Object"===r(o)&&"Function"===r(o.formatter)&&(n=o.formatter(n,e)),n=i(n),t+=n+","})),this.csv+=t.slice(0,-1)+"\r\n"}),this)}return o(e,[{key:"getContent",value:function(){return this.csv}},{key:"export",value:function(){var e="\ufeff"+this.getContent();if(window.Blob){var t=new Blob([e],{type:"text/csv"});if(window.navigator.msSaveBlob)window.navigator.msSaveBlob(t,this.fileName);else if(window.URL&&window.URL.createObjectURL){var n=window.URL.createObjectURL(t),o=document.createElement("a");o.id="downloadCSVLink",o.href=n,document.body.appendChild(o);var r=document.getElementById("downloadCSVLink");r.setAttribute("download",this.fileName),r.click(),document.body.removeChild(r),window.URL.revokeObjectURL(n)}}else{var i=document.createElement("iframe");document.body.appendChild(i),i.contentWindow.document.open("text/html","replace"),i.contentWindow.document.write("sep=,\r\n"+e),i.contentWindow.document.close(),i.contentWindow.focus(),i.contentWindow.document.execCommand("SaveAs",!0,this.fileName),document.body.removeChild(i)}}}]),e}();t.default=c}]).default}));