Comparing version 0.2.0 to 0.3.0
@@ -1,3 +0,10 @@ | ||
# v0.2.0 | ||
# Change Logs | ||
## v0.3.0 | ||
- add `toString` api | ||
## v0.2.0 | ||
- further minimize generated js file with mangling and compression | ||
@@ -13,3 +20,3 @@ - rename `csv4xls.js`, `csv4xls.min.js` to `index.js` and `index.min.js` | ||
# v0.1.0 | ||
## v0.1.0 | ||
@@ -19,3 +26,3 @@ - add `download` api for trigger csv download directly. | ||
# v0.0.2 | ||
## v0.0.2 | ||
@@ -22,0 +29,0 @@ - quote double quote properly by converting single double quote to double double quote. |
10
index.js
(function(){ | ||
var obj, csv4xls; | ||
obj = { | ||
toArray: function(data){ | ||
var str, ba, i$, to$, i; | ||
toString: function(data){ | ||
var str; | ||
str = data.map(function(d, i){ | ||
@@ -11,3 +11,3 @@ return d.map(function(v, j){ | ||
}).join('\r\n'); | ||
str = data.map(function(d, i){ | ||
return str = data.map(function(d, i){ | ||
return d.map(function(v, j){ | ||
@@ -17,2 +17,6 @@ return '"' + ('' + v).replace(/"/g, '""').replace(/\n/g, '\r') + '"'; | ||
}).join('\r\n'); | ||
}, | ||
toArray: function(data){ | ||
var str, ba, i$, to$, i; | ||
str = obj.toString(data); | ||
ba = new Uint8Array(2 + str.length * 2); | ||
@@ -19,0 +23,0 @@ for (i$ = 0, to$ = str.length; i$ < to$; ++i$) { |
@@ -1,1 +0,1 @@ | ||
(function(){var t,n;(function(t,n){var e={}.hasOwnProperty;for(var o in n)e.call(n,o)&&(t[o]=n[o])})(n=function(n){return t.toHref(n)},t={toArray:function(t){var n,e,o,r,u;for(n=t.map(function(t,n){return t.map(function(t,n){return t+""}).join("\t")}).join("\r\n"),n=t.map(function(t,n){return t.map(function(t,n){return'"'+(""+t).replace(/"/g,'""').replace(/\n/g,"\r")+'"'}).join("\t")}).join("\r\n"),e=new Uint8Array(2+2*n.length),o=0,r=n.length;o<r;++o)e[2*(u=o)+2]=n.charCodeAt(u),e[2*u+3]=n.charCodeAt(u)>>8;return e[0]=255,e[1]=254,e},toBlob:function(n){var e;return e=t.toArray(n),new Blob([e],{type:"text/csv"})},toHref:function(n){var e;return e=t.toBlob(n),URL.createObjectURL(e)},download:function(t,n){var e,o;return null==n&&(n="data.csv"),e=this.toHref(t),(o=document.createElement("a")).setAttribute("href",e),o.setAttribute("download",n+(/\.csv$/i.exec(n)?"":".csv")),o.style.opacity=0,o.style.position="absolute",document.body.appendChild(o),o.click(),document.body.removeChild(o)}}),"undefined"!=typeof module&&null!==module?module.exports=n:"undefined"!=typeof window&&null!==window&&(window.csv4xls=n)}).call(this); | ||
!function(){var t,u={toString:function(t){t.map(function(t,n){return t.map(function(t,n){return t+""}).join("\t")}).join("\r\n");return t.map(function(t,n){return t.map(function(t,n){return'"'+(""+t).replace(/"/g,'""').replace(/\n/g,"\r")+'"'}).join("\t")}).join("\r\n")},toArray:function(t){for(var n,e=u.toString(t),o=new Uint8Array(2+2*e.length),r=0,i=e.length;r<i;++r)o[2*(n=r)+2]=e.charCodeAt(n),o[2*n+3]=e.charCodeAt(n)>>8;return o[0]=255,o[1]=254,o},toBlob:function(t){t=u.toArray(t);return new Blob([t],{type:"text/csv"})},toHref:function(t){t=u.toBlob(t);return URL.createObjectURL(t)},download:function(t,n){var e;return null==n&&(n="data.csv"),t=this.toHref(t),(e=document.createElement("a")).setAttribute("href",t),e.setAttribute("download",n+(/\.csv$/i.exec(n)?"":".csv")),e.style.opacity=0,e.style.position="absolute",document.body.appendChild(e),e.click(),document.body.removeChild(e)}},n=function(t){return u.toHref(t)},e=n,o=u,r={}.hasOwnProperty;for(t in o)r.call(o,t)&&(e[t]=o[t]);"undefined"!=typeof module&&null!==module?module.exports=n:"undefined"!=typeof window&&null!==window&&(window.csv4xls=n)}.call(this); |
@@ -1,1 +0,1 @@ | ||
{"author":"zbryikt","name":"csv4xls","license":"MIT","browser":"index.min.js","main":"index.min.js","description":"csv generator friendly for Microsoft Excel","version":"0.2.0","homepage":"https://github.com/plotdb/csv4xls","repository":{"type":"git","url":"https://github.com/plotdb/csv4xls"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true"},"devDependencies":{"@zbryikt/template":"^2.3.33","fedep":"^1.1.2","livescript":">=1.6.0","puppeteer":"^5.3.1","uglify-js":"^3.13.1"},"frontendDependencies":{"root":"web/static/assets/lib","modules":[]}} | ||
{"author":"zbryikt","name":"csv4xls","license":"MIT","browser":"index.min.js","main":"index.min.js","description":"csv generator friendly for Microsoft Excel","version":"0.3.0","homepage":"https://github.com/plotdb/csv4xls","repository":{"type":"git","url":"https://github.com/plotdb/csv4xls"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true"},"devDependencies":{"@zbryikt/template":"^2.3.45","fedep":"^1.1.11","livescript":">=1.6.0","uglify-js":"^3.13.1"},"frontendDependencies":{"root":"web/static/assets/lib","modules":[]}} |
@@ -17,6 +17,7 @@ # csv4xls | ||
* toArray(data) - convert given 2D array to an xls-compatible CSV file, stores in an Uint8Array and returns the array. | ||
* toBlob(data) - same as `toArray` but return a corresponding blob. | ||
* toHref(data) - same as `toBlob` but return a corresponding object url. | ||
* download(data, filename) - trigger file download | ||
- `toString(data)` - convert given 2D array to CSV in String format. | ||
- `toArray(data)` - convert given 2D array to an xls-compatible CSV file in thr returned Uint8Array. | ||
- `toBlob(data)` - same as `toArray` but return a corresponding blob. | ||
- `toHref(data)` - same as `toBlob` but return a corresponding object url. | ||
- `download(data, filename)` - trigger file download | ||
@@ -23,0 +24,0 @@ |
5221
4
75
32