-
Notifications
You must be signed in to change notification settings - Fork 5
/
save-csv.min.js
2 lines (2 loc) · 1.71 KB
/
save-csv.min.js
1
2
/*! save-csv v4.1.0 | (c) silverwind | BSD license */
!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.saveCsv=t()}("undefined"!=typeof self?self:this,function(){"use strict";return function(e,i){if(!Array.isArray(e)||!e.length)throw new Error("Expected an array of values, got "+e);(i=i||{}).filename=i.filename||"export.csv",i.sep=i.sep||"auto",i.eol=i.eol||"\r\n",i.bom="boolean"!=typeof i.bom||i.bom,i.quote=i.quote||'"',i.mime=i.mime||"text/csv;charset=utf-8","auto"===i.sep&&("toLocaleString"in Number.prototype?i.sep=","===1.2.toLocaleString().substring(1,2)?";":",":i.sep=",");var o=new RegExp(i.quote,"g"),n=new RegExp(i.sep,"g");i.formatter=i.formatter||function(e){var t=!1;return"string"!=typeof e&&(e=JSON.stringify(e)||""),o.test(e)&&(e=i.quote+e.replace(o,i.quote+i.quote)+i.quote,t=!0),n.test(e)&&!t&&(e=i.quote+e+i.quote),e};var a=[];!function o(n,r,e){e.forEach(function(e){var t=n?n+"."+e:e;"object"==typeof r[e]&&null!==r[e]?o(t,r[e],Object.keys(r[e])):a.push(i.formatter(t))})}(null,e[0],Object.keys(e[0]));var t=a.join(i.sep)+i.eol+e.map(function(e){var n=[];return function t(o,e){e.forEach(function(e){"object"==typeof o[e]&&null!==o[e]?t(o[e],Object.keys(o[e])):n.push(i.formatter(o[e]))})}(e,Object.keys(e)),n.join(i.sep)}).join(i.eol),r=new Blob([i.bom?"\ufeff"+t:t]);if(window.navigator.msSaveOrOpenBlob)window.navigator.msSaveOrOpenBlob(r,i.filename);else{var u=document.createElement("a");u.setAttribute("href",URL.createObjectURL(r,{type:i.mime})),u.setAttribute("download",i.filename),u.setAttribute("target","_blank"),u.style.display="none",document.body.appendChild(u),u.click(),setTimeout(function(){document.body.removeChild(u)},0)}}});