-
Notifications
You must be signed in to change notification settings - Fork 0
/
table2csv.min.js
1 lines (1 loc) · 1.7 KB
/
table2csv.min.js
1
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}!function(s){var d={filename:"table.csv",appendTo:"body",separator:",",newline:"\n",quoteFields:!0,trimContent:!0,excludeColumns:"",excludeRows:""},f={};s.fn.table2csv=function(e,t){if("object"===_typeof(e)?(t=e,e="download"):void 0===e&&(e="download"),"string"!=typeof e)throw new Error('"action" argument must be a string');if(void 0!==t&&"object"!==_typeof(t))throw new Error('"options" argument must be an object');f=s.extend({},d,t);var o=this.filter("table");if(o.length<=0)throw new Error("table2csv must be called on a <table> element");if(1<o.length)throw new Error("converting multiple table elements at once is not supported yet");var r,n,i,l,a,u,c=(r="",n=o.find("tr").not(f.excludeRows),i=n.first().find("td,th").filter(":visible").not(f.excludeColumns).length,n.each(function(e,t){s(t).find("td,th").filter(":visible").not(f.excludeColumns).each(function(e,t){var o=s(t),n=f.trimContent?s.trim(o.text()):o.text();r+=f.quoteFields?'"'+n.replace(/"/g,'""')+'"':n,r+=e!==i-1?f.separator:f.newline})}),r);switch(e){case"download":l=f.filename,a=c,(u=document.createElement("a")).setAttribute("href","data:text/csv;charset=utf-8,\ufeff"+encodeURIComponent(a)),u.setAttribute("download",l),u.style.display="none",document.body.appendChild(u),u.click(),document.body.removeChild(u);break;case"output":s(f.appendTo).append(s("<pre>").text(c));break;case"return":return c;default:throw new Error('"action" argument must be one of the supported action strings')}return this}}(jQuery);