tableexport
Advanced tools
Comparing version 3.3.10 to 3.3.11
{ | ||
"name": "tableexport.js", | ||
"version": "3.3.10", | ||
"version": "3.3.11", | ||
"authors": [ | ||
@@ -5,0 +5,0 @@ "clarketm <travis.m.clarke@gmail.com>" |
/*! | ||
* TableExport.js v3.3.10 (https://www.travismclarke.com) | ||
* Copyright 2016 Travis Clarke | ||
* TableExport.js v3.3.11 (https://www.travismclarke.com) | ||
* Copyright 2017 Travis Clarke | ||
* Licensed under the MIT license | ||
@@ -40,2 +40,3 @@ */ | ||
var rowD = TableExport.prototype.rowDel, | ||
isTrimWhitespace = self.settings.trimWhitespace, | ||
ignoreRows = self.settings.ignoreRows instanceof Array ? self.settings.ignoreRows : [self.settings.ignoreRows], | ||
@@ -102,5 +103,11 @@ ignoreCols = self.settings.ignoreCols instanceof Array ? self.settings.ignoreCols : [self.settings.ignoreCols], | ||
} | ||
return new Array(total).concat($(val).text()); | ||
return new Array(total).concat({ | ||
v: TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()), | ||
t: TableExport.prototype.getType($(val).attr('class')) | ||
}); | ||
} | ||
return formatValue($(val).text()); | ||
return { | ||
v: TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()), | ||
t: TableExport.prototype.getType($(val).attr('class')) | ||
}; | ||
}).get()]; | ||
@@ -154,5 +161,11 @@ }).get(), | ||
} | ||
return new Array(total).concat($(val).text()); | ||
return new Array(total).concat({ | ||
v: TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()), | ||
t: TableExport.prototype.getType($(val).attr('class')) | ||
}); | ||
} | ||
return formatValue($(val).text()); | ||
return { | ||
v: TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()), | ||
t: TableExport.prototype.getType($(val).attr('class')) | ||
}; | ||
}).get()]; | ||
@@ -185,3 +198,6 @@ }).get(), | ||
} | ||
return formatValue($(val).text()); | ||
return { | ||
v: TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()), | ||
t: TableExport.prototype.getType($(val).attr('class')) | ||
}; | ||
}).get().join(colD); | ||
@@ -214,3 +230,3 @@ }).get().join(rdel), | ||
} | ||
return '"' + formatValue($(val).text().replace(/"/g, '""')) + '"'; | ||
return '"' + TableExport.prototype.formatValue(isTrimWhitespace, $(val).text().replace(/"/g, '""')) + '"'; | ||
}).get().join(colD); | ||
@@ -243,3 +259,3 @@ }).get().join(rdel), | ||
} | ||
return formatValue($(val).text()); | ||
return TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()); | ||
}).get().join(colD); | ||
@@ -267,13 +283,3 @@ }).get().join(rdel), | ||
); | ||
/** | ||
* Removes leading/trailing whitespace from cell string | ||
* @param string {String} | ||
* @returns {String} trimmed string | ||
*/ | ||
function formatValue(string) { | ||
return self.settings.trimWhitespace ? string.trim() : string; | ||
} | ||
/** | ||
* Initializes table caption with export buttons | ||
@@ -319,3 +325,3 @@ * @param exportButton {HTMLButtonElement} | ||
*/ | ||
version: "3.3.10", | ||
version: "3.3.11", | ||
/** | ||
@@ -332,7 +338,7 @@ * Default plugin options. | ||
position: "bottom", // (top, bottom), position of the caption element relative to table, (default: "bottom") | ||
ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file (default: null) | ||
ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file (default: null) | ||
ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file (default: ".tableexport-ignore") | ||
emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file (default: ".tableexport-empty") | ||
trimWhitespace: false // (Boolean), remove all leading/trailing newlines, spaces (including non-breaking spaces), and tabs from cell text (default: false) | ||
ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file(s) (default: null) | ||
ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file(s) (default: null) | ||
ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file(s) (default: ".tableexport-ignore") | ||
emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file(s) (default: ".tableexport-empty") | ||
trimWhitespace: false // (Boolean), remove all leading/trailing newlines, spaces, and tabs from cell text in the exported file(s) (default: false) | ||
}, | ||
@@ -413,2 +419,29 @@ /** | ||
/** | ||
* Cell-types override and assertion configuration | ||
* @memberof TableExport.prototype | ||
*/ | ||
types: { | ||
string: { | ||
defaultClass: "tableexport-string" | ||
}, | ||
number: { | ||
defaultClass: "tableexport-number", | ||
assert: function (v) { | ||
return !isNaN(v.replace(/,/g, '')); | ||
} | ||
}, | ||
boolean: { | ||
defaultClass: "tableexport-boolean", | ||
assert: function (v) { | ||
return v.toLowerCase() === 'true' || v.toLowerCase() === 'false'; | ||
} | ||
}, | ||
date: { | ||
defaultClass: "tableexport-date", | ||
assert: function (v) { | ||
return !isNaN(Date.parse(v)) | ||
} | ||
} | ||
}, | ||
/** | ||
* Escapes special characters with HTML entities | ||
@@ -425,2 +458,31 @@ * @memberof TableExport.prototype | ||
/** | ||
* Removes leading/trailing whitespace from cell string | ||
* @param isTrimWhitespace {Boolean} | ||
* @param string {String} | ||
* @returns {String} trimmed string | ||
*/ | ||
formatValue: function (isTrimWhitespace, string) { | ||
return isTrimWhitespace ? string.trim() : string; | ||
}, | ||
/** | ||
* Get cell data-type | ||
* @param string {String} | ||
* @returns {String} data-type | ||
*/ | ||
getType: function (string) { | ||
if (!string) return ''; | ||
var types = TableExport.prototype.types; | ||
if (~string.indexOf(types.string.defaultClass)) { | ||
return 's'; | ||
} else if (~string.indexOf(types.number.defaultClass)) { | ||
return 'n'; | ||
} else if (~string.indexOf(types.boolean.defaultClass)) { | ||
return 'b'; | ||
} else if (~string.indexOf(types.date.defaultClass)) { | ||
return 'd'; | ||
} else { | ||
return ''; | ||
} | ||
}, | ||
/** | ||
* Formats datetimes for compatibility with Excel | ||
@@ -441,3 +503,2 @@ * @memberof TableExport.prototype | ||
* @param data {String} | ||
* @returns {Number} epoch time | ||
*/ | ||
@@ -447,4 +508,5 @@ createSheet: function (data) { | ||
var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}}; | ||
for (var R = 0; R != data.length; ++R) { | ||
for (var C = 0; C != data[R].length; ++C) { | ||
var types = TableExport.prototype.types; | ||
for (var R = 0; R !== data.length; ++R) { | ||
for (var C = 0; C !== data[R].length; ++C) { | ||
if (range.s.r > R) range.s.r = R; | ||
@@ -454,9 +516,14 @@ if (range.s.c > C) range.s.c = C; | ||
if (range.e.c < C) range.e.c = C; | ||
var cell = {v: data[R][C]}; | ||
if (cell.v == null) continue; | ||
var cell = data[R][C]; | ||
if (!cell || !cell.v) continue; | ||
var cell_ref = XLSX.utils.encode_cell({c: C, r: R}); | ||
if (typeof cell.v === 'number') cell.t = 'n'; | ||
else if (typeof cell.v === 'boolean') cell.t = 'b'; | ||
else if (cell.v instanceof Date) { | ||
if (!cell.t) { | ||
if (types.number.assert(cell.v)) cell.t = 'n'; | ||
else if (types.boolean.assert(cell.v)) cell.t = 'b'; | ||
else if (types.date.assert(cell.v)) cell.t = 'd'; | ||
else cell.t = 's'; | ||
} | ||
if (cell.t === 'd') { | ||
cell.t = 'n'; | ||
@@ -466,3 +533,2 @@ cell.z = XLSX.SSF._table[14]; | ||
} | ||
else cell.t = 's'; | ||
@@ -493,3 +559,3 @@ ws[cell_ref] = cell; | ||
var view = new Uint8Array(buf); | ||
for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; | ||
for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; | ||
return buf; | ||
@@ -506,3 +572,3 @@ }, | ||
export2file: function (data, mime, name, extension) { | ||
if (XLSX && extension.substr(0, 4) == (".xls")) { | ||
if (XLSX && extension.substr(0, 4) === (".xls")) { | ||
var wb = new this.Workbook(), | ||
@@ -509,0 +575,0 @@ ws = this.createSheet(data); |
/*! | ||
* TableExport.js v3.3.10 (https://www.travismclarke.com) | ||
* Copyright 2016 Travis Clarke | ||
* TableExport.js v3.3.11 (https://www.travismclarke.com) | ||
* Copyright 2017 Travis Clarke | ||
* Licensed under the MIT license | ||
*/ | ||
!function(t,e){"function"==typeof define&&define.amd?define(["exports","jquery","blobjs","file-saverjs","xlsx-js"],e):"object"==typeof exports&&"string"!=typeof exports.nodeName?e(exports,require("jquery"),require("blobjs"),require("file-saverjs"),require("xlsx-js")):e(t,t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this||window,function(t,e,n,o,i){"use strict";var r=function(t,n,o){var s=this;s.settings=o?n:e.extend({},r.prototype.defaults,n),s.selectors=t;var a,p,f,l=r.prototype.rowDel,u=s.settings.ignoreRows instanceof Array?s.settings.ignoreRows:[s.settings.ignoreRows],c=s.settings.ignoreCols instanceof Array?s.settings.ignoreCols:[s.settings.ignoreCols],x=s.settings.ignoreCSS instanceof Array?s.settings.ignoreCSS.join(", "):s.settings.ignoreCSS,d=s.settings.emptyCSS instanceof Array?s.settings.emptyCSS.join(", "):s.settings.emptyCSS;return s.settings.bootstrap?(a=r.prototype.bootstrap[0]+" ",p=r.prototype.bootstrap[1]+" ",f=r.prototype.bootstrap[2]+" "):(a=r.prototype.defaultButton+" ",p=f=""),s.selectors.each(function(){function t(t){return s.settings.trimWhitespace?t.trim():t}function n(t){var e=m.find("caption:not(.head)");e.length?e.append(t):m.prepend('<caption class="'+f+s.settings.position+'">'+t+"</caption>")}function y(t,e,o){var i="<button data-fileblob='"+t+"' class='"+a+p+o+"'>"+e+"</button>";n(i)}var m=e(this);o&&m.find("caption:not(.head)").remove();var g=m.find("tbody").find("tr"),g=s.settings.headings?g.add(m.find("thead>tr")):g,g=s.settings.footers?g.add(m.find("tfoot>tr")):g,b=s.settings.headings?m.find("thead>tr").length:0,v="id"===s.settings.fileName?m.attr("id")?m.attr("id"):r.prototype.defaultFileName:s.settings.fileName,h={xlsx:function(n,o){var i={},s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return[r.map(function(o,r){if(!~c.indexOf(o)&&!e(r).is(x)){if(e(r).is(d))return" ";if(r.hasAttribute("colspan")&&(i[n]=i[n]||{},i[n][o+1]=r.getAttribute("colspan")-1),r.hasAttribute("rowspan"))for(var s=1;s<r.getAttribute("rowspan");s++)i[n+s]=i[n+s]||{},i[n+s][o]=1;if(i[n]){for(var a=o+1,p=0,f=0,s=0;s<=Math.max.apply(Math,Object.keys(i[n]))&&(i[n][s]?p=f>=o?p+i[n][s]:p:f++,f!==a);s++);return new Array(p).concat(e(r).text())}return t(e(r).text())}}).get()]}}).get(),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xlsx.mimeType,fileExtension:r.prototype.xlsx.fileExtension})),p=r.prototype.xlsx.buttonContent,f=r.prototype.xlsx.defaultClass;y(a,p,f)},xlsm:function(n,o){var i={},s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return[r.map(function(o,r){if(!~c.indexOf(o)&&!e(r).is(x)){if(e(r).is(d))return" ";if(r.hasAttribute("colspan")&&(i[n]=i[n]||{},i[n][o+1]=r.getAttribute("colspan")-1),r.hasAttribute("rowspan"))for(var s=1;s<r.getAttribute("rowspan");s++)i[n+s]=i[n+s]||{},i[n+s][o]=1;if(i[n]){for(var a=o+1,p=0,f=0,s=0;s<=Math.max.apply(Math,Object.keys(i[n]))&&(i[n][s]?p=f>=o?p+i[n][s]:p:f++,f!==a);s++);return new Array(p).concat(e(r).text())}return t(e(r).text())}}).get()]}}).get(),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xls.mimeType,fileExtension:r.prototype.xls.fileExtension})),p=r.prototype.xls.buttonContent,f=r.prototype.xls.defaultClass;y(a,p,f)},xls:function(n,o){var i=r.prototype.xls.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(d)?" ":t(e(o).text())}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xls.mimeType,fileExtension:r.prototype.xls.fileExtension})),p=r.prototype.xls.buttonContent,f=r.prototype.xls.defaultClass;y(a,p,f)},csv:function(n,o){var i=r.prototype.csv.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(d)?" ":'"'+t(e(o).text().replace(/"/g,'""'))+'"'}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.csv.mimeType,fileExtension:r.prototype.csv.fileExtension})),p=r.prototype.csv.buttonContent,f=r.prototype.csv.defaultClass;y(a,p,f)},txt:function(n,o){var i=r.prototype.txt.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(d)?" ":t(e(o).text())}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.txt.mimeType,fileExtension:r.prototype.txt.fileExtension})),p=r.prototype.txt.buttonContent,f=r.prototype.txt.defaultClass;y(a,p,f)}};s.settings.formats.forEach(function(t){!(!i||"xls"!==t)&&(t="xlsm"),!i&&"xlsx"===t&&(t=null),t&&h[t](l,v)})}),e("button[data-fileblob]").off("click").on("click",function(){var t=e(this).data("fileblob"),n=t.data,o=t.fileName,i=t.mimeType,s=t.fileExtension;r.prototype.export2file(n,i,o,s)}),s};r.prototype={version:"3.3.10",defaults:{headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",trimWhitespace:!1},charset:"charset=utf-8",defaultFileName:"myDownload",defaultButton:"button-default",bootstrap:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return r.prototype.entityMap[t]})},dateNum:function(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},o=0;o!=t.length;++o)for(var r=0;r!=t[o].length;++r){n.s.r>o&&(n.s.r=o),n.s.c>r&&(n.s.c=r),n.e.r<o&&(n.e.r=o),n.e.c<r&&(n.e.c=r);var s={v:t[o][r]};if(null!=s.v){var a=i.utils.encode_cell({c:r,r:o});"number"==typeof s.v?s.t="n":"boolean"==typeof s.v?s.t="b":s.v instanceof Date?(s.t="n",s.z=i.SSF._table[14],s.v=this.dateNum(s.v)):s.t="s",e[a]=s}}return n.s.c<1e7&&(e["!ref"]=i.utils.encode_range(n)),e},Workbook:function(){this.SheetNames=[],this.Sheets={}},string2ArrayBuffer:function(t){for(var e=new ArrayBuffer(t.length),n=new Uint8Array(e),o=0;o!=t.length;++o)n[o]=255&t.charCodeAt(o);return e},export2file:function(t,e,r,s){if(i&&".xls"==s.substr(0,4)){var a=new this.Workbook,p=this.createSheet(t);a.SheetNames.push(r),a.Sheets[r]=p;var f={bookType:s.substr(1,3)+(s.substr(4)||"m"),bookSST:!1,type:"binary"},l=i.write(a,f);t=this.string2ArrayBuffer(l)}var u=new n([t],{type:e+";"+this.charset});"undefined"==typeof o&&"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?window.navigator.msSaveOrOpenBlob(u,r+s):o(u,r+s,!0)},update:function(t){return new r(this.selectors,e.extend({},this.settings,t),(!0))},reset:function(){return new r(this.selectors,this.settings,(!0))},remove:function(){this.selectors.each(function(){e(this).find("caption:not(.head)").remove()})}},e.fn.tableExport=function(t,e){return new r(this,t,e)};for(var s in r.prototype)e.fn.tableExport[s]=r.prototype[s];return t["default"]=t.TableExport=r}); | ||
!function(t,e){"function"==typeof define&&define.amd?define(["exports","jquery","blobjs","file-saverjs","xlsx-js"],e):"object"==typeof exports&&"string"!=typeof exports.nodeName?e(exports,require("jquery"),require("blobjs"),require("file-saverjs"),require("xlsx-js")):e(t,t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this||window,function(t,e,o,n,r){"use strict";var s=function(t,o,n){var i=this;i.settings=n?o:e.extend({},s.prototype.defaults,o),i.selectors=t;var a,p,f,l=s.prototype.rowDel,u=i.settings.trimWhitespace,c=i.settings.ignoreRows instanceof Array?i.settings.ignoreRows:[i.settings.ignoreRows],y=i.settings.ignoreCols instanceof Array?i.settings.ignoreCols:[i.settings.ignoreCols],d=i.settings.ignoreCSS instanceof Array?i.settings.ignoreCSS.join(", "):i.settings.ignoreCSS,x=i.settings.emptyCSS instanceof Array?i.settings.emptyCSS.join(", "):i.settings.emptyCSS;return i.settings.bootstrap?(a=s.prototype.bootstrap[0]+" ",p=s.prototype.bootstrap[1]+" ",f=s.prototype.bootstrap[2]+" "):(a=s.prototype.defaultButton+" ",p=f=""),i.selectors.each(function(){function t(t){var e=m.find("caption:not(.head)");e.length?e.append(t):m.prepend('<caption class="'+f+i.settings.position+'">'+t+"</caption>")}function o(e,o,n){var r="<button data-fileblob='"+e+"' class='"+a+p+n+"'>"+o+"</button>";t(r)}var m=e(this);n&&m.find("caption:not(.head)").remove();var g=m.find("tbody").find("tr"),g=i.settings.headings?g.add(m.find("thead>tr")):g,g=i.settings.footers?g.add(m.find("tfoot>tr")):g,b=i.settings.headings?m.find("thead>tr").length:0,v="id"===i.settings.fileName?m.attr("id")?m.attr("id"):s.prototype.defaultFileName:i.settings.fileName,h={xlsx:function(t,n){var r={},i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(d)){var n=e(o).find("th, td");return[n.map(function(o,n){if(!~y.indexOf(o)&&!e(n).is(d)){if(e(n).is(x))return" ";if(n.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][o+1]=n.getAttribute("colspan")-1),n.hasAttribute("rowspan"))for(var i=1;i<n.getAttribute("rowspan");i++)r[t+i]=r[t+i]||{},r[t+i][o]=1;if(r[t]){for(var a=o+1,p=0,f=0,i=0;i<=Math.max.apply(Math,Object.keys(r[t]))&&(r[t][i]?p=f>=o?p+r[t][i]:p:f++,f!==a);i++);return new Array(p).concat({v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))})}return{v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))}}}).get()]}}).get(),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.xlsx.mimeType,fileExtension:s.prototype.xlsx.fileExtension})),p=s.prototype.xlsx.buttonContent,f=s.prototype.xlsx.defaultClass;o(a,p,f)},xlsm:function(t,n){var r={},i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(d)){var n=e(o).find("th, td");return[n.map(function(o,n){if(!~y.indexOf(o)&&!e(n).is(d)){if(e(n).is(x))return" ";if(n.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][o+1]=n.getAttribute("colspan")-1),n.hasAttribute("rowspan"))for(var i=1;i<n.getAttribute("rowspan");i++)r[t+i]=r[t+i]||{},r[t+i][o]=1;if(r[t]){for(var a=o+1,p=0,f=0,i=0;i<=Math.max.apply(Math,Object.keys(r[t]))&&(r[t][i]?p=f>=o?p+r[t][i]:p:f++,f!==a);i++);return new Array(p).concat({v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))})}return{v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))}}}).get()]}}).get(),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.xls.mimeType,fileExtension:s.prototype.xls.fileExtension})),p=s.prototype.xls.buttonContent,f=s.prototype.xls.defaultClass;o(a,p,f)},xls:function(t,n){var r=s.prototype.xls.separator,i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(d)){var n=e(o).find("th, td");return n.map(function(t,o){if(!~y.indexOf(t)&&!e(o).is(d))return e(o).is(x)?" ":{v:s.prototype.formatValue(u,e(o).text()),t:s.prototype.getType(e(o).attr("class"))}}).get().join(r)}}).get().join(t),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.xls.mimeType,fileExtension:s.prototype.xls.fileExtension})),p=s.prototype.xls.buttonContent,f=s.prototype.xls.defaultClass;o(a,p,f)},csv:function(t,n){var r=s.prototype.csv.separator,i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(d)){var n=e(o).find("th, td");return n.map(function(t,o){if(!~y.indexOf(t)&&!e(o).is(d))return e(o).is(x)?" ":'"'+s.prototype.formatValue(u,e(o).text().replace(/"/g,'""'))+'"'}).get().join(r)}}).get().join(t),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.csv.mimeType,fileExtension:s.prototype.csv.fileExtension})),p=s.prototype.csv.buttonContent,f=s.prototype.csv.defaultClass;o(a,p,f)},txt:function(t,n){var r=s.prototype.txt.separator,i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(d)){var n=e(o).find("th, td");return n.map(function(t,o){if(!~y.indexOf(t)&&!e(o).is(d))return e(o).is(x)?" ":s.prototype.formatValue(u,e(o).text())}).get().join(r)}}).get().join(t),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.txt.mimeType,fileExtension:s.prototype.txt.fileExtension})),p=s.prototype.txt.buttonContent,f=s.prototype.txt.defaultClass;o(a,p,f)}};i.settings.formats.forEach(function(t){!(!r||"xls"!==t)&&(t="xlsm"),!r&&"xlsx"===t&&(t=null),t&&h[t](l,v)})}),e("button[data-fileblob]").off("click").on("click",function(){var t=e(this).data("fileblob"),o=t.data,n=t.fileName,r=t.mimeType,i=t.fileExtension;s.prototype.export2file(o,r,n,i)}),i};s.prototype={version:"3.3.11",defaults:{headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",trimWhitespace:!1},charset:"charset=utf-8",defaultFileName:"myDownload",defaultButton:"button-default",bootstrap:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},types:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t.replace(/,/g,""))}},"boolean":{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!isNaN(Date.parse(t))}}},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return s.prototype.entityMap[t]})},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=s.prototype.types;return~t.indexOf(e.string.defaultClass)?"s":~t.indexOf(e.number.defaultClass)?"n":~t.indexOf(e["boolean"].defaultClass)?"b":~t.indexOf(e.date.defaultClass)?"d":""},dateNum:function(t,e){e&&(t+=1462);var o=Date.parse(t);return(o-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},o={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=s.prototype.types,i=0;i!==t.length;++i)for(var a=0;a!==t[i].length;++a){o.s.r>i&&(o.s.r=i),o.s.c>a&&(o.s.c=a),o.e.r<i&&(o.e.r=i),o.e.c<a&&(o.e.c=a);var p=t[i][a];if(p&&p.v){var f=r.utils.encode_cell({c:a,r:i});p.t||(n.number.assert(p.v)?p.t="n":n["boolean"].assert(p.v)?p.t="b":n.date.assert(p.v)?p.t="d":p.t="s"),"d"===p.t&&(p.t="n",p.z=r.SSF._table[14],p.v=this.dateNum(p.v)),e[f]=p}}return o.s.c<1e7&&(e["!ref"]=r.utils.encode_range(o)),e},Workbook:function(){this.SheetNames=[],this.Sheets={}},string2ArrayBuffer:function(t){for(var e=new ArrayBuffer(t.length),o=new Uint8Array(e),n=0;n!==t.length;++n)o[n]=255&t.charCodeAt(n);return e},export2file:function(t,e,s,i){if(r&&".xls"===i.substr(0,4)){var a=new this.Workbook,p=this.createSheet(t);a.SheetNames.push(s),a.Sheets[s]=p;var f={bookType:i.substr(1,3)+(i.substr(4)||"m"),bookSST:!1,type:"binary"},l=r.write(a,f);t=this.string2ArrayBuffer(l)}var u=new o([t],{type:e+";"+this.charset});"undefined"==typeof n&&"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?window.navigator.msSaveOrOpenBlob(u,s+i):n(u,s+i,!0)},update:function(t){return new s(this.selectors,e.extend({},this.settings,t),(!0))},reset:function(){return new s(this.selectors,this.settings,(!0))},remove:function(){this.selectors.each(function(){e(this).find("caption:not(.head)").remove()})}},e.fn.tableExport=function(t,e){return new s(this,t,e)};for(var i in s.prototype)e.fn.tableExport[i]=s.prototype[i];return t["default"]=t.TableExport=s}); |
@@ -92,2 +92,8 @@ /** | ||
/** | ||
* Cell-types override and assertion configuration | ||
* @memberof TableExport.prototype | ||
*/ | ||
types: Types; | ||
/** | ||
* Escapes special characters with HTML entities | ||
@@ -101,2 +107,19 @@ * @memberof TableExport.prototype | ||
/** | ||
* Removes leading/trailing whitespace from cell string | ||
* @memberof TableExport.prototype | ||
* @param isTrimWhitespace {Boolean} | ||
* @param string {String} | ||
* @returns {String} trimmed string | ||
*/ | ||
formatValue: (string: string) => string; | ||
/** | ||
* Get cell data-type | ||
* @memberof TableExport.prototype | ||
* @param string {String} | ||
* @returns {String} data-type | ||
*/ | ||
getType: (string: string) => string; | ||
/** | ||
* Formats datetimes for compatibility with Excel | ||
@@ -116,3 +139,3 @@ * @memberof TableExport.prototype | ||
*/ | ||
createSheet: (data: string) => number; | ||
createSheet: (data: string) => void; | ||
@@ -231,2 +254,18 @@ /** | ||
/** | ||
* Cell-types override and assertion configuration | ||
* @memberof TableExport.prototype | ||
*/ | ||
export interface Types { | ||
string: Type; | ||
number: Type; | ||
boolean: Type; | ||
date: Type; | ||
} | ||
export interface Type { | ||
defaultClass: string; | ||
assert: (v: any) => boolean; | ||
} | ||
interface JQuery { | ||
@@ -233,0 +272,0 @@ |
{ | ||
"name": "tableexport", | ||
"version": "3.3.10", | ||
"version": "3.3.11", | ||
"authors": [ | ||
@@ -5,0 +5,0 @@ "clarketm <travis.m.clarke@gmail.com>" |
@@ -7,5 +7,5 @@ [![Build Status](https://travis-ci.org/clarketm/TableExport.svg?branch=master)](https://travis-ci.org/clarketm/TableExport) | ||
> **Notice:** In May 2017, [v3.0.0](https://github.com/clarketm/TableExport/releases/tag/v3.3.9) will be superceded by [v4.0.0](https://github.com/clarketm/TableExport/releases/tag/v4.0.0-alpha.4). Althought this is a major version bump, fear not, because all changes will be 100% backwards-compatible. | ||
> **Notice:** In May 2017, [v3.0.0](https://github.com/clarketm/TableExport/releases/tag/v3.3.9) will be superceded by [v4.0.0](https://github.com/clarketm/TableExport/releases/tag/v4.0.0-alpha.5). Althought this is a major version bump, fear not, because all changes will be 100% backwards-compatible. | ||
> **So why the major version bump you ask?** Well, the rationale for a major version bump is that due to a change in `TableExport`'s dependencies, in [v4.0.0](https://github.com/clarketm/TableExport/releases/tag/v4.0.0-alpha.4) forth, JQuery will no longer be a **required** dependency, instead it will be purely **optional**. So existing implementations *with* jQuery will continue to work unimpeded, now with the added benefit that new projets no longer need to rely on the overhead of such large library, unless of course you prefer jQuery or it is already part of your project. | ||
> **So why the major version bump you ask?** Well, the rationale for a major version bump is that due to a change in `TableExport`'s dependencies, in [v4.0.0](https://github.com/clarketm/TableExport/releases/tag/v4.0.0-alpha.5) forth, JQuery will no longer be a **required** dependency, instead it will be purely **optional**. So existing implementations *with* jQuery will continue to work unimpeded, now with the added benefit that new projets no longer need to rely on the overhead of such large library, unless of course you prefer jQuery or it is already part of your project. | ||
@@ -127,7 +127,7 @@ ## Getting Started | ||
position: "bottom", // (top, bottom), position of the caption element relative to table | ||
ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file | ||
ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file | ||
ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file | ||
emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file | ||
trimWhitespace: false // (Boolean), remove all leading/trailing newlines, spaces (including non-breaking spaces), and tabs from cell text | ||
ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file(s) | ||
ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file(s) | ||
ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file(s) | ||
emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file(s) | ||
trimWhitespace: false // (Boolean), remove all leading/trailing newlines, spaces, and tabs from cell text in the exported file(s) | ||
}); | ||
@@ -134,0 +134,0 @@ ``` |
/*! | ||
* TableExport.js v3.3.10 (https://www.travismclarke.com) | ||
* Copyright 2016 Travis Clarke | ||
* TableExport.js v3.3.11 (https://www.travismclarke.com) | ||
* Copyright 2017 Travis Clarke | ||
* Licensed under the MIT license | ||
@@ -40,2 +40,3 @@ */ | ||
var rowD = TableExport.prototype.rowDel, | ||
isTrimWhitespace = self.settings.trimWhitespace, | ||
ignoreRows = self.settings.ignoreRows instanceof Array ? self.settings.ignoreRows : [self.settings.ignoreRows], | ||
@@ -102,5 +103,11 @@ ignoreCols = self.settings.ignoreCols instanceof Array ? self.settings.ignoreCols : [self.settings.ignoreCols], | ||
} | ||
return new Array(total).concat($(val).text()); | ||
return new Array(total).concat({ | ||
v: TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()), | ||
t: TableExport.prototype.getType($(val).attr('class')) | ||
}); | ||
} | ||
return formatValue($(val).text()); | ||
return { | ||
v: TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()), | ||
t: TableExport.prototype.getType($(val).attr('class')) | ||
}; | ||
}).get()]; | ||
@@ -154,5 +161,11 @@ }).get(), | ||
} | ||
return new Array(total).concat($(val).text()); | ||
return new Array(total).concat({ | ||
v: TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()), | ||
t: TableExport.prototype.getType($(val).attr('class')) | ||
}); | ||
} | ||
return formatValue($(val).text()); | ||
return { | ||
v: TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()), | ||
t: TableExport.prototype.getType($(val).attr('class')) | ||
}; | ||
}).get()]; | ||
@@ -185,3 +198,6 @@ }).get(), | ||
} | ||
return formatValue($(val).text()); | ||
return { | ||
v: TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()), | ||
t: TableExport.prototype.getType($(val).attr('class')) | ||
}; | ||
}).get().join(colD); | ||
@@ -214,3 +230,3 @@ }).get().join(rdel), | ||
} | ||
return '"' + formatValue($(val).text().replace(/"/g, '""')) + '"'; | ||
return '"' + TableExport.prototype.formatValue(isTrimWhitespace, $(val).text().replace(/"/g, '""')) + '"'; | ||
}).get().join(colD); | ||
@@ -243,3 +259,3 @@ }).get().join(rdel), | ||
} | ||
return formatValue($(val).text()); | ||
return TableExport.prototype.formatValue(isTrimWhitespace, $(val).text()); | ||
}).get().join(colD); | ||
@@ -267,13 +283,3 @@ }).get().join(rdel), | ||
); | ||
/** | ||
* Removes leading/trailing whitespace from cell string | ||
* @param string {String} | ||
* @returns {String} trimmed string | ||
*/ | ||
function formatValue(string) { | ||
return self.settings.trimWhitespace ? string.trim() : string; | ||
} | ||
/** | ||
* Initializes table caption with export buttons | ||
@@ -319,3 +325,3 @@ * @param exportButton {HTMLButtonElement} | ||
*/ | ||
version: "3.3.10", | ||
version: "3.3.11", | ||
/** | ||
@@ -332,7 +338,7 @@ * Default plugin options. | ||
position: "bottom", // (top, bottom), position of the caption element relative to table, (default: "bottom") | ||
ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file (default: null) | ||
ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file (default: null) | ||
ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file (default: ".tableexport-ignore") | ||
emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file (default: ".tableexport-empty") | ||
trimWhitespace: false // (Boolean), remove all leading/trailing newlines, spaces (including non-breaking spaces), and tabs from cell text (default: false) | ||
ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file(s) (default: null) | ||
ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file(s) (default: null) | ||
ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file(s) (default: ".tableexport-ignore") | ||
emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file(s) (default: ".tableexport-empty") | ||
trimWhitespace: false // (Boolean), remove all leading/trailing newlines, spaces, and tabs from cell text in the exported file(s) (default: false) | ||
}, | ||
@@ -413,2 +419,29 @@ /** | ||
/** | ||
* Cell-types override and assertion configuration | ||
* @memberof TableExport.prototype | ||
*/ | ||
types: { | ||
string: { | ||
defaultClass: "tableexport-string" | ||
}, | ||
number: { | ||
defaultClass: "tableexport-number", | ||
assert: function (v) { | ||
return !isNaN(v.replace(/,/g, '')); | ||
} | ||
}, | ||
boolean: { | ||
defaultClass: "tableexport-boolean", | ||
assert: function (v) { | ||
return v.toLowerCase() === 'true' || v.toLowerCase() === 'false'; | ||
} | ||
}, | ||
date: { | ||
defaultClass: "tableexport-date", | ||
assert: function (v) { | ||
return !isNaN(Date.parse(v)) | ||
} | ||
} | ||
}, | ||
/** | ||
* Escapes special characters with HTML entities | ||
@@ -425,2 +458,31 @@ * @memberof TableExport.prototype | ||
/** | ||
* Removes leading/trailing whitespace from cell string | ||
* @param isTrimWhitespace {Boolean} | ||
* @param string {String} | ||
* @returns {String} trimmed string | ||
*/ | ||
formatValue: function (isTrimWhitespace, string) { | ||
return isTrimWhitespace ? string.trim() : string; | ||
}, | ||
/** | ||
* Get cell data-type | ||
* @param string {String} | ||
* @returns {String} data-type | ||
*/ | ||
getType: function (string) { | ||
if (!string) return ''; | ||
var types = TableExport.prototype.types; | ||
if (~string.indexOf(types.string.defaultClass)) { | ||
return 's'; | ||
} else if (~string.indexOf(types.number.defaultClass)) { | ||
return 'n'; | ||
} else if (~string.indexOf(types.boolean.defaultClass)) { | ||
return 'b'; | ||
} else if (~string.indexOf(types.date.defaultClass)) { | ||
return 'd'; | ||
} else { | ||
return ''; | ||
} | ||
}, | ||
/** | ||
* Formats datetimes for compatibility with Excel | ||
@@ -441,3 +503,2 @@ * @memberof TableExport.prototype | ||
* @param data {String} | ||
* @returns {Number} epoch time | ||
*/ | ||
@@ -447,4 +508,5 @@ createSheet: function (data) { | ||
var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}}; | ||
for (var R = 0; R != data.length; ++R) { | ||
for (var C = 0; C != data[R].length; ++C) { | ||
var types = TableExport.prototype.types; | ||
for (var R = 0; R !== data.length; ++R) { | ||
for (var C = 0; C !== data[R].length; ++C) { | ||
if (range.s.r > R) range.s.r = R; | ||
@@ -454,9 +516,14 @@ if (range.s.c > C) range.s.c = C; | ||
if (range.e.c < C) range.e.c = C; | ||
var cell = {v: data[R][C]}; | ||
if (cell.v == null) continue; | ||
var cell = data[R][C]; | ||
if (!cell || !cell.v) continue; | ||
var cell_ref = XLSX.utils.encode_cell({c: C, r: R}); | ||
if (typeof cell.v === 'number') cell.t = 'n'; | ||
else if (typeof cell.v === 'boolean') cell.t = 'b'; | ||
else if (cell.v instanceof Date) { | ||
if (!cell.t) { | ||
if (types.number.assert(cell.v)) cell.t = 'n'; | ||
else if (types.boolean.assert(cell.v)) cell.t = 'b'; | ||
else if (types.date.assert(cell.v)) cell.t = 'd'; | ||
else cell.t = 's'; | ||
} | ||
if (cell.t === 'd') { | ||
cell.t = 'n'; | ||
@@ -466,3 +533,2 @@ cell.z = XLSX.SSF._table[14]; | ||
} | ||
else cell.t = 's'; | ||
@@ -493,3 +559,3 @@ ws[cell_ref] = cell; | ||
var view = new Uint8Array(buf); | ||
for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; | ||
for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; | ||
return buf; | ||
@@ -506,3 +572,3 @@ }, | ||
export2file: function (data, mime, name, extension) { | ||
if (XLSX && extension.substr(0, 4) == (".xls")) { | ||
if (XLSX && extension.substr(0, 4) === (".xls")) { | ||
var wb = new this.Workbook(), | ||
@@ -509,0 +575,0 @@ ws = this.createSheet(data); |
/*! | ||
* TableExport.js v3.3.10 (https://www.travismclarke.com) | ||
* Copyright 2016 Travis Clarke | ||
* TableExport.js v3.3.11 (https://www.travismclarke.com) | ||
* Copyright 2017 Travis Clarke | ||
* Licensed under the MIT license | ||
*/ | ||
!function(t,e){"function"==typeof define&&define.amd?define(["exports","jquery","blobjs","file-saverjs","xlsx-js"],e):"object"==typeof exports&&"string"!=typeof exports.nodeName?e(exports,require("jquery"),require("blobjs"),require("file-saverjs"),require("xlsx-js")):e(t,t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this||window,function(t,e,n,o,i){"use strict";var r=function(t,n,o){var s=this;s.settings=o?n:e.extend({},r.prototype.defaults,n),s.selectors=t;var a,p,f,l=r.prototype.rowDel,u=s.settings.ignoreRows instanceof Array?s.settings.ignoreRows:[s.settings.ignoreRows],c=s.settings.ignoreCols instanceof Array?s.settings.ignoreCols:[s.settings.ignoreCols],x=s.settings.ignoreCSS instanceof Array?s.settings.ignoreCSS.join(", "):s.settings.ignoreCSS,d=s.settings.emptyCSS instanceof Array?s.settings.emptyCSS.join(", "):s.settings.emptyCSS;return s.settings.bootstrap?(a=r.prototype.bootstrap[0]+" ",p=r.prototype.bootstrap[1]+" ",f=r.prototype.bootstrap[2]+" "):(a=r.prototype.defaultButton+" ",p=f=""),s.selectors.each(function(){function t(t){return s.settings.trimWhitespace?t.trim():t}function n(t){var e=m.find("caption:not(.head)");e.length?e.append(t):m.prepend('<caption class="'+f+s.settings.position+'">'+t+"</caption>")}function y(t,e,o){var i="<button data-fileblob='"+t+"' class='"+a+p+o+"'>"+e+"</button>";n(i)}var m=e(this);o&&m.find("caption:not(.head)").remove();var g=m.find("tbody").find("tr"),g=s.settings.headings?g.add(m.find("thead>tr")):g,g=s.settings.footers?g.add(m.find("tfoot>tr")):g,b=s.settings.headings?m.find("thead>tr").length:0,v="id"===s.settings.fileName?m.attr("id")?m.attr("id"):r.prototype.defaultFileName:s.settings.fileName,h={xlsx:function(n,o){var i={},s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return[r.map(function(o,r){if(!~c.indexOf(o)&&!e(r).is(x)){if(e(r).is(d))return" ";if(r.hasAttribute("colspan")&&(i[n]=i[n]||{},i[n][o+1]=r.getAttribute("colspan")-1),r.hasAttribute("rowspan"))for(var s=1;s<r.getAttribute("rowspan");s++)i[n+s]=i[n+s]||{},i[n+s][o]=1;if(i[n]){for(var a=o+1,p=0,f=0,s=0;s<=Math.max.apply(Math,Object.keys(i[n]))&&(i[n][s]?p=f>=o?p+i[n][s]:p:f++,f!==a);s++);return new Array(p).concat(e(r).text())}return t(e(r).text())}}).get()]}}).get(),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xlsx.mimeType,fileExtension:r.prototype.xlsx.fileExtension})),p=r.prototype.xlsx.buttonContent,f=r.prototype.xlsx.defaultClass;y(a,p,f)},xlsm:function(n,o){var i={},s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return[r.map(function(o,r){if(!~c.indexOf(o)&&!e(r).is(x)){if(e(r).is(d))return" ";if(r.hasAttribute("colspan")&&(i[n]=i[n]||{},i[n][o+1]=r.getAttribute("colspan")-1),r.hasAttribute("rowspan"))for(var s=1;s<r.getAttribute("rowspan");s++)i[n+s]=i[n+s]||{},i[n+s][o]=1;if(i[n]){for(var a=o+1,p=0,f=0,s=0;s<=Math.max.apply(Math,Object.keys(i[n]))&&(i[n][s]?p=f>=o?p+i[n][s]:p:f++,f!==a);s++);return new Array(p).concat(e(r).text())}return t(e(r).text())}}).get()]}}).get(),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xls.mimeType,fileExtension:r.prototype.xls.fileExtension})),p=r.prototype.xls.buttonContent,f=r.prototype.xls.defaultClass;y(a,p,f)},xls:function(n,o){var i=r.prototype.xls.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(d)?" ":t(e(o).text())}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xls.mimeType,fileExtension:r.prototype.xls.fileExtension})),p=r.prototype.xls.buttonContent,f=r.prototype.xls.defaultClass;y(a,p,f)},csv:function(n,o){var i=r.prototype.csv.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(d)?" ":'"'+t(e(o).text().replace(/"/g,'""'))+'"'}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.csv.mimeType,fileExtension:r.prototype.csv.fileExtension})),p=r.prototype.csv.buttonContent,f=r.prototype.csv.defaultClass;y(a,p,f)},txt:function(n,o){var i=r.prototype.txt.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(d)?" ":t(e(o).text())}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.txt.mimeType,fileExtension:r.prototype.txt.fileExtension})),p=r.prototype.txt.buttonContent,f=r.prototype.txt.defaultClass;y(a,p,f)}};s.settings.formats.forEach(function(t){!(!i||"xls"!==t)&&(t="xlsm"),!i&&"xlsx"===t&&(t=null),t&&h[t](l,v)})}),e("button[data-fileblob]").off("click").on("click",function(){var t=e(this).data("fileblob"),n=t.data,o=t.fileName,i=t.mimeType,s=t.fileExtension;r.prototype.export2file(n,i,o,s)}),s};r.prototype={version:"3.3.10",defaults:{headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",trimWhitespace:!1},charset:"charset=utf-8",defaultFileName:"myDownload",defaultButton:"button-default",bootstrap:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return r.prototype.entityMap[t]})},dateNum:function(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},o=0;o!=t.length;++o)for(var r=0;r!=t[o].length;++r){n.s.r>o&&(n.s.r=o),n.s.c>r&&(n.s.c=r),n.e.r<o&&(n.e.r=o),n.e.c<r&&(n.e.c=r);var s={v:t[o][r]};if(null!=s.v){var a=i.utils.encode_cell({c:r,r:o});"number"==typeof s.v?s.t="n":"boolean"==typeof s.v?s.t="b":s.v instanceof Date?(s.t="n",s.z=i.SSF._table[14],s.v=this.dateNum(s.v)):s.t="s",e[a]=s}}return n.s.c<1e7&&(e["!ref"]=i.utils.encode_range(n)),e},Workbook:function(){this.SheetNames=[],this.Sheets={}},string2ArrayBuffer:function(t){for(var e=new ArrayBuffer(t.length),n=new Uint8Array(e),o=0;o!=t.length;++o)n[o]=255&t.charCodeAt(o);return e},export2file:function(t,e,r,s){if(i&&".xls"==s.substr(0,4)){var a=new this.Workbook,p=this.createSheet(t);a.SheetNames.push(r),a.Sheets[r]=p;var f={bookType:s.substr(1,3)+(s.substr(4)||"m"),bookSST:!1,type:"binary"},l=i.write(a,f);t=this.string2ArrayBuffer(l)}var u=new n([t],{type:e+";"+this.charset});"undefined"==typeof o&&"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?window.navigator.msSaveOrOpenBlob(u,r+s):o(u,r+s,!0)},update:function(t){return new r(this.selectors,e.extend({},this.settings,t),(!0))},reset:function(){return new r(this.selectors,this.settings,(!0))},remove:function(){this.selectors.each(function(){e(this).find("caption:not(.head)").remove()})}},e.fn.tableExport=function(t,e){return new r(this,t,e)};for(var s in r.prototype)e.fn.tableExport[s]=r.prototype[s];return t["default"]=t.TableExport=r}); | ||
!function(t,e){"function"==typeof define&&define.amd?define(["exports","jquery","blobjs","file-saverjs","xlsx-js"],e):"object"==typeof exports&&"string"!=typeof exports.nodeName?e(exports,require("jquery"),require("blobjs"),require("file-saverjs"),require("xlsx-js")):e(t,t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this||window,function(t,e,o,n,r){"use strict";var s=function(t,o,n){var i=this;i.settings=n?o:e.extend({},s.prototype.defaults,o),i.selectors=t;var a,p,f,l=s.prototype.rowDel,u=i.settings.trimWhitespace,c=i.settings.ignoreRows instanceof Array?i.settings.ignoreRows:[i.settings.ignoreRows],y=i.settings.ignoreCols instanceof Array?i.settings.ignoreCols:[i.settings.ignoreCols],d=i.settings.ignoreCSS instanceof Array?i.settings.ignoreCSS.join(", "):i.settings.ignoreCSS,x=i.settings.emptyCSS instanceof Array?i.settings.emptyCSS.join(", "):i.settings.emptyCSS;return i.settings.bootstrap?(a=s.prototype.bootstrap[0]+" ",p=s.prototype.bootstrap[1]+" ",f=s.prototype.bootstrap[2]+" "):(a=s.prototype.defaultButton+" ",p=f=""),i.selectors.each(function(){function t(t){var e=m.find("caption:not(.head)");e.length?e.append(t):m.prepend('<caption class="'+f+i.settings.position+'">'+t+"</caption>")}function o(e,o,n){var r="<button data-fileblob='"+e+"' class='"+a+p+n+"'>"+o+"</button>";t(r)}var m=e(this);n&&m.find("caption:not(.head)").remove();var g=m.find("tbody").find("tr"),g=i.settings.headings?g.add(m.find("thead>tr")):g,g=i.settings.footers?g.add(m.find("tfoot>tr")):g,b=i.settings.headings?m.find("thead>tr").length:0,v="id"===i.settings.fileName?m.attr("id")?m.attr("id"):s.prototype.defaultFileName:i.settings.fileName,h={xlsx:function(t,n){var r={},i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(d)){var n=e(o).find("th, td");return[n.map(function(o,n){if(!~y.indexOf(o)&&!e(n).is(d)){if(e(n).is(x))return" ";if(n.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][o+1]=n.getAttribute("colspan")-1),n.hasAttribute("rowspan"))for(var i=1;i<n.getAttribute("rowspan");i++)r[t+i]=r[t+i]||{},r[t+i][o]=1;if(r[t]){for(var a=o+1,p=0,f=0,i=0;i<=Math.max.apply(Math,Object.keys(r[t]))&&(r[t][i]?p=f>=o?p+r[t][i]:p:f++,f!==a);i++);return new Array(p).concat({v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))})}return{v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))}}}).get()]}}).get(),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.xlsx.mimeType,fileExtension:s.prototype.xlsx.fileExtension})),p=s.prototype.xlsx.buttonContent,f=s.prototype.xlsx.defaultClass;o(a,p,f)},xlsm:function(t,n){var r={},i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(d)){var n=e(o).find("th, td");return[n.map(function(o,n){if(!~y.indexOf(o)&&!e(n).is(d)){if(e(n).is(x))return" ";if(n.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][o+1]=n.getAttribute("colspan")-1),n.hasAttribute("rowspan"))for(var i=1;i<n.getAttribute("rowspan");i++)r[t+i]=r[t+i]||{},r[t+i][o]=1;if(r[t]){for(var a=o+1,p=0,f=0,i=0;i<=Math.max.apply(Math,Object.keys(r[t]))&&(r[t][i]?p=f>=o?p+r[t][i]:p:f++,f!==a);i++);return new Array(p).concat({v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))})}return{v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))}}}).get()]}}).get(),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.xls.mimeType,fileExtension:s.prototype.xls.fileExtension})),p=s.prototype.xls.buttonContent,f=s.prototype.xls.defaultClass;o(a,p,f)},xls:function(t,n){var r=s.prototype.xls.separator,i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(d)){var n=e(o).find("th, td");return n.map(function(t,o){if(!~y.indexOf(t)&&!e(o).is(d))return e(o).is(x)?" ":{v:s.prototype.formatValue(u,e(o).text()),t:s.prototype.getType(e(o).attr("class"))}}).get().join(r)}}).get().join(t),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.xls.mimeType,fileExtension:s.prototype.xls.fileExtension})),p=s.prototype.xls.buttonContent,f=s.prototype.xls.defaultClass;o(a,p,f)},csv:function(t,n){var r=s.prototype.csv.separator,i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(d)){var n=e(o).find("th, td");return n.map(function(t,o){if(!~y.indexOf(t)&&!e(o).is(d))return e(o).is(x)?" ":'"'+s.prototype.formatValue(u,e(o).text().replace(/"/g,'""'))+'"'}).get().join(r)}}).get().join(t),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.csv.mimeType,fileExtension:s.prototype.csv.fileExtension})),p=s.prototype.csv.buttonContent,f=s.prototype.csv.defaultClass;o(a,p,f)},txt:function(t,n){var r=s.prototype.txt.separator,i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(d)){var n=e(o).find("th, td");return n.map(function(t,o){if(!~y.indexOf(t)&&!e(o).is(d))return e(o).is(x)?" ":s.prototype.formatValue(u,e(o).text())}).get().join(r)}}).get().join(t),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.txt.mimeType,fileExtension:s.prototype.txt.fileExtension})),p=s.prototype.txt.buttonContent,f=s.prototype.txt.defaultClass;o(a,p,f)}};i.settings.formats.forEach(function(t){!(!r||"xls"!==t)&&(t="xlsm"),!r&&"xlsx"===t&&(t=null),t&&h[t](l,v)})}),e("button[data-fileblob]").off("click").on("click",function(){var t=e(this).data("fileblob"),o=t.data,n=t.fileName,r=t.mimeType,i=t.fileExtension;s.prototype.export2file(o,r,n,i)}),i};s.prototype={version:"3.3.11",defaults:{headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",trimWhitespace:!1},charset:"charset=utf-8",defaultFileName:"myDownload",defaultButton:"button-default",bootstrap:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},types:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t.replace(/,/g,""))}},"boolean":{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!isNaN(Date.parse(t))}}},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return s.prototype.entityMap[t]})},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=s.prototype.types;return~t.indexOf(e.string.defaultClass)?"s":~t.indexOf(e.number.defaultClass)?"n":~t.indexOf(e["boolean"].defaultClass)?"b":~t.indexOf(e.date.defaultClass)?"d":""},dateNum:function(t,e){e&&(t+=1462);var o=Date.parse(t);return(o-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},o={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=s.prototype.types,i=0;i!==t.length;++i)for(var a=0;a!==t[i].length;++a){o.s.r>i&&(o.s.r=i),o.s.c>a&&(o.s.c=a),o.e.r<i&&(o.e.r=i),o.e.c<a&&(o.e.c=a);var p=t[i][a];if(p&&p.v){var f=r.utils.encode_cell({c:a,r:i});p.t||(n.number.assert(p.v)?p.t="n":n["boolean"].assert(p.v)?p.t="b":n.date.assert(p.v)?p.t="d":p.t="s"),"d"===p.t&&(p.t="n",p.z=r.SSF._table[14],p.v=this.dateNum(p.v)),e[f]=p}}return o.s.c<1e7&&(e["!ref"]=r.utils.encode_range(o)),e},Workbook:function(){this.SheetNames=[],this.Sheets={}},string2ArrayBuffer:function(t){for(var e=new ArrayBuffer(t.length),o=new Uint8Array(e),n=0;n!==t.length;++n)o[n]=255&t.charCodeAt(n);return e},export2file:function(t,e,s,i){if(r&&".xls"===i.substr(0,4)){var a=new this.Workbook,p=this.createSheet(t);a.SheetNames.push(s),a.Sheets[s]=p;var f={bookType:i.substr(1,3)+(i.substr(4)||"m"),bookSST:!1,type:"binary"},l=r.write(a,f);t=this.string2ArrayBuffer(l)}var u=new o([t],{type:e+";"+this.charset});"undefined"==typeof n&&"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?window.navigator.msSaveOrOpenBlob(u,s+i):n(u,s+i,!0)},update:function(t){return new s(this.selectors,e.extend({},this.settings,t),(!0))},reset:function(){return new s(this.selectors,this.settings,(!0))},remove:function(){this.selectors.each(function(){e(this).find("caption:not(.head)").remove()})}},e.fn.tableExport=function(t,e){return new s(this,t,e)};for(var i in s.prototype)e.fn.tableExport[i]=s.prototype[i];return t["default"]=t.TableExport=s}); |
@@ -92,2 +92,8 @@ /** | ||
/** | ||
* Cell-types override and assertion configuration | ||
* @memberof TableExport.prototype | ||
*/ | ||
types: Types; | ||
/** | ||
* Escapes special characters with HTML entities | ||
@@ -101,2 +107,19 @@ * @memberof TableExport.prototype | ||
/** | ||
* Removes leading/trailing whitespace from cell string | ||
* @memberof TableExport.prototype | ||
* @param isTrimWhitespace {Boolean} | ||
* @param string {String} | ||
* @returns {String} trimmed string | ||
*/ | ||
formatValue: (string: string) => string; | ||
/** | ||
* Get cell data-type | ||
* @memberof TableExport.prototype | ||
* @param string {String} | ||
* @returns {String} data-type | ||
*/ | ||
getType: (string: string) => string; | ||
/** | ||
* Formats datetimes for compatibility with Excel | ||
@@ -116,3 +139,3 @@ * @memberof TableExport.prototype | ||
*/ | ||
createSheet: (data: string) => number; | ||
createSheet: (data: string) => void; | ||
@@ -231,2 +254,18 @@ /** | ||
/** | ||
* Cell-types override and assertion configuration | ||
* @memberof TableExport.prototype | ||
*/ | ||
export interface Types { | ||
string: Type; | ||
number: Type; | ||
boolean: Type; | ||
date: Type; | ||
} | ||
export interface Type { | ||
defaultClass: string; | ||
assert: (v: any) => boolean; | ||
} | ||
interface JQuery { | ||
@@ -233,0 +272,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7515048
52168