woocommerce/packages/woocommerce-admin/dist/csv-export/index.js
2021-12-10 12:03:04 +00:00

2 lines
5.1 KiB
JavaScript

/*! For license information please see index.js.LICENSE.txt */
this.wc=this.wc||{},this.wc.csvExport=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},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 r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},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=442)}({264:function(e,t,n){var r=r||function(e){"use strict";if("undefined"==typeof navigator||!/MSIE [1-9]\./.test(navigator.userAgent)){var t=e.document,n=function(){return e.URL||e.webkitURL||e},r=t.createElementNS("http://www.w3.org/1999/xhtml","a"),o="download"in r,i=/Version\/[\d\.]+.*Safari/.test(navigator.userAgent),a=e.webkitRequestFileSystem,c=e.requestFileSystem||a||e.mozRequestFileSystem,u=function(t){(e.setImmediate||e.setTimeout)((function(){throw t}),0)},f=0,l=function(e){setTimeout((function(){"string"==typeof e?n().revokeObjectURL(e):e.remove()}),4e4)},s=function(e,t,n){for(var r=(t=[].concat(t)).length;r--;){var o=e["on"+t[r]];if("function"==typeof o)try{o.call(e,n||e)}catch(e){u(e)}}},d=function(e){return/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob(["\ufeff",e],{type:e.type}):e},p=function(t,u,p){p||(t=d(t));var y,v,w,m=this,b=t.type,g=!1,S=function(){s(m,"writestart progress write writeend".split(" "))},h=function(){if(v&&i&&"undefined"!=typeof FileReader){var r=new FileReader;return r.onloadend=function(){var e=r.result;v.location.href="data:attachment/file"+e.slice(e.search(/[,;]/)),m.readyState=m.DONE,S()},r.readAsDataURL(t),void(m.readyState=m.INIT)}(!g&&y||(y=n().createObjectURL(t)),v)?v.location.href=y:void 0===e.open(y,"_blank")&&i&&(e.location.href=y);m.readyState=m.DONE,S(),l(y)},O=function(e){return function(){if(m.readyState!==m.DONE)return e.apply(this,arguments)}},R={create:!0,exclusive:!1};if(m.readyState=m.INIT,u||(u="download"),o)return y=n().createObjectURL(t),void setTimeout((function(){var e,t;r.href=y,r.download=u,e=r,t=new MouseEvent("click"),e.dispatchEvent(t),S(),l(y),m.readyState=m.DONE}));e.chrome&&b&&"application/octet-stream"!==b&&(w=t.slice||t.webkitSlice,t=w.call(t,0,t.size,"application/octet-stream"),g=!0),a&&"download"!==u&&(u+=".download"),("application/octet-stream"===b||a)&&(v=e),c?(f+=t.size,c(e.TEMPORARY,f,O((function(e){e.root.getDirectory("saved",R,O((function(e){var n=function(){e.getFile(u,R,O((function(e){e.createWriter(O((function(n){n.onwriteend=function(t){v.location.href=e.toURL(),m.readyState=m.DONE,s(m,"writeend",t),l(e)},n.onerror=function(){var e=n.error;e.code!==e.ABORT_ERR&&h()},"writestart progress write abort".split(" ").forEach((function(e){n["on"+e]=m["on"+e]})),n.write(t),m.abort=function(){n.abort(),m.readyState=m.DONE},m.readyState=m.WRITING})),h)})),h)};e.getFile(u,{create:!1},O((function(e){e.remove(),n()})),O((function(e){e.code===e.NOT_FOUND_ERR?n():h()})))})),h)})),h)):h()},y=p.prototype;return"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?function(e,t,n){return n||(e=d(e)),navigator.msSaveOrOpenBlob(e,t||"download")}:(y.abort=function(){this.readyState=this.DONE,s(this,"abort")},y.readyState=y.INIT=0,y.WRITING=1,y.DONE=2,y.error=y.onwritestart=y.onprogress=y.onwrite=y.onabort=y.onerror=y.onwriteend=null,function(e,t,n){return new p(e,t,n)})}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content);e.exports?e.exports.saveAs=r:"undefined"!=typeof define&&null!==define&&null!==define.amd&&define([],(function(){return r}))},442:function(e,t,n){"use strict";n.r(t),n.d(t,"generateCSVDataFromTable",(function(){return f})),n.d(t,"generateCSVFileName",(function(){return l})),n.d(t,"downloadCSVFile",(function(){return s}));var r=n(9),o=n.n(r),i=n(264);function a(e){let t=e.toString();return["=","+","-","@"].includes(t.charAt(0))?t='"\t'+t+'"':t.match(/[,"\s]/)&&(t='"'+t.replace(/"/g,'""')+'"'),t}function c(e){return Array.isArray(e)?e.map(e=>a(e.label)).join(","):[]}function u(e){return Array.isArray(e)?e.map(e=>e.map(e=>void 0===e.value||null===e.value?"":a(e.value)).join(",")).join("\n"):[]}function f(e,t){return[c(e),u(t)].filter(e=>e.length).join("\n")}function l(e="",t={}){return[e.toLowerCase().replace(/[^a-z0-9]/g,"-"),o()().format("YYYY-MM-DD"),Object.keys(t).map(e=>e.toLowerCase().replace(/[^a-z0-9]/g,"-")+"-"+decodeURIComponent(t[e]).toLowerCase().replace(/[^a-z0-9]/g,"-")).join("_")].filter(e=>e.length).join("_")+".csv"}function s(e,t){const n=new Blob([t],{type:"text/csv;charset=utf-8"});Object(i.saveAs)(n,e)}},9:function(e,t){e.exports=window.moment}});