Browser and Node ESM support
parent
326b7c0ca1
commit
3d35cebe9e
@ -0,0 +1,5 @@
|
||||
/*! xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
|
||||
/* vim: set ts=2: */
|
||||
/*exported XLSX */
|
||||
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
|
||||
var XLSX = {};
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,60 @@
|
||||
import * as _fs from 'fs';
|
||||
|
||||
/* normalize data for blob ctor */
|
||||
function blobify(data) {
|
||||
if(typeof data === "string") return s2ab(data);
|
||||
if(Array.isArray(data)) return a2u(data);
|
||||
return data;
|
||||
}
|
||||
/* write or download file */
|
||||
function write_dl(fname/*:string*/, payload/*:any*/, enc/*:?string*/) {
|
||||
/*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
|
||||
if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
|
||||
var data = (enc == "utf8") ? utf8write(payload) : payload;
|
||||
/*:: declare var IE_SaveFile: any; */
|
||||
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
|
||||
if(typeof Blob !== 'undefined') {
|
||||
var blob = new Blob([blobify(data)], {type:"application/octet-stream"});
|
||||
/*:: declare var navigator: any; */
|
||||
if(typeof navigator !== 'undefined' && navigator.msSaveBlob) return navigator.msSaveBlob(blob, fname);
|
||||
/*:: declare var saveAs: any; */
|
||||
if(typeof saveAs !== 'undefined') return saveAs(blob, fname);
|
||||
if(typeof URL !== 'undefined' && typeof document !== 'undefined' && document.createElement && URL.createObjectURL) {
|
||||
var url = URL.createObjectURL(blob);
|
||||
/*:: declare var chrome: any; */
|
||||
if(typeof chrome === 'object' && typeof (chrome.downloads||{}).download == "function") {
|
||||
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
|
||||
return chrome.downloads.download({ url: url, filename: fname, saveAs: true});
|
||||
}
|
||||
var a = document.createElement("a");
|
||||
if(a.download != null) {
|
||||
/*:: if(document.body == null) throw new Error("unreachable"); */
|
||||
a.download = fname; a.href = url; document.body.appendChild(a); a.click();
|
||||
/*:: if(document.body == null) throw new Error("unreachable"); */ document.body.removeChild(a);
|
||||
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
// $FlowIgnore
|
||||
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
|
||||
// $FlowIgnore
|
||||
var out = File(fname); out.open("w"); out.encoding = "binary";
|
||||
if(Array.isArray(payload)) payload = a2s(payload);
|
||||
out.write(payload); out.close(); return payload;
|
||||
} catch(e) { if(!e.message || !e.message.match(/onstruct/)) throw e; }
|
||||
throw new Error("cannot save file " + fname);
|
||||
}
|
||||
|
||||
/* read binary data from file */
|
||||
function read_binary(path/*:string*/) {
|
||||
if(typeof _fs !== 'undefined') return _fs.readFileSync(path);
|
||||
// $FlowIgnore
|
||||
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
|
||||
// $FlowIgnore
|
||||
var infile = File(path); infile.open("r"); infile.encoding = "binary";
|
||||
var data = infile.read(); infile.close();
|
||||
return data;
|
||||
} catch(e) { if(!e.message || !e.message.match(/onstruct/)) throw e; }
|
||||
throw new Error("Cannot access file " + path);
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
const _fs = void 0;
|
||||
|
||||
/* normalize data for blob ctor */
|
||||
function blobify(data) {
|
||||
if(typeof data === "string") return s2ab(data);
|
||||
if(Array.isArray(data)) return a2u(data);
|
||||
return data;
|
||||
}
|
||||
/* write or download file */
|
||||
function write_dl(fname/*:string*/, payload/*:any*/, enc/*:?string*/) {
|
||||
/*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
|
||||
if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
|
||||
var data = (enc == "utf8") ? utf8write(payload) : payload;
|
||||
/*:: declare var IE_SaveFile: any; */
|
||||
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
|
||||
if(typeof Blob !== 'undefined') {
|
||||
var blob = new Blob([blobify(data)], {type:"application/octet-stream"});
|
||||
/*:: declare var navigator: any; */
|
||||
if(typeof navigator !== 'undefined' && navigator.msSaveBlob) return navigator.msSaveBlob(blob, fname);
|
||||
/*:: declare var saveAs: any; */
|
||||
if(typeof saveAs !== 'undefined') return saveAs(blob, fname);
|
||||
if(typeof URL !== 'undefined' && typeof document !== 'undefined' && document.createElement && URL.createObjectURL) {
|
||||
var url = URL.createObjectURL(blob);
|
||||
/*:: declare var chrome: any; */
|
||||
if(typeof chrome === 'object' && typeof (chrome.downloads||{}).download == "function") {
|
||||
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
|
||||
return chrome.downloads.download({ url: url, filename: fname, saveAs: true});
|
||||
}
|
||||
var a = document.createElement("a");
|
||||
if(a.download != null) {
|
||||
/*:: if(document.body == null) throw new Error("unreachable"); */
|
||||
a.download = fname; a.href = url; document.body.appendChild(a); a.click();
|
||||
/*:: if(document.body == null) throw new Error("unreachable"); */ document.body.removeChild(a);
|
||||
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
// $FlowIgnore
|
||||
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
|
||||
// $FlowIgnore
|
||||
var out = File(fname); out.open("w"); out.encoding = "binary";
|
||||
if(Array.isArray(payload)) payload = a2s(payload);
|
||||
out.write(payload); out.close(); return payload;
|
||||
} catch(e) { if(!e.message || !e.message.match(/onstruct/)) throw e; }
|
||||
throw new Error("cannot save file " + fname);
|
||||
}
|
||||
|
||||
/* read binary data from file */
|
||||
function read_binary(path/*:string*/) {
|
||||
if(typeof _fs !== 'undefined') return _fs.readFileSync(path);
|
||||
// $FlowIgnore
|
||||
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
|
||||
// $FlowIgnore
|
||||
var infile = File(path); infile.open("r"); infile.encoding = "binary";
|
||||
var data = infile.read(); infile.close();
|
||||
return data;
|
||||
} catch(e) { if(!e.message || !e.message.match(/onstruct/)) throw e; }
|
||||
throw new Error("Cannot access file " + path);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
export const version = XLSX.version;
|
||||
export {
|
||||
parse_xlscfb,
|
||||
parse_zip,
|
||||
readSync as read,
|
||||
readFileSync as readFile,
|
||||
readFileSync,
|
||||
writeSync as write,
|
||||
writeFileSync as writeFile,
|
||||
writeFileSync,
|
||||
writeFileAsync,
|
||||
utils,
|
||||
SSF,
|
||||
CFB
|
||||
};
|
@ -0,0 +1,79 @@
|
||||
misc/00_esmheader.js
|
||||
bits/01_version.js
|
||||
misc/02_codepage.js
|
||||
bits/03_consts.js
|
||||
bits/04_base64.js
|
||||
bits/05_buf.js
|
||||
bits/09_types.js
|
||||
bits/10_ssf.js
|
||||
bits/11_ssfutils.js
|
||||
misc/18_esmcfb.js
|
||||
misc/19_esmfs.js
|
||||
bits/20_jsutils.js
|
||||
misc/21_ziputils.js
|
||||
bits/22_xmlutils.js
|
||||
bits/23_binutils.js
|
||||
bits/24_hoppers.js
|
||||
bits/25_cellutils.js
|
||||
bits/27_csfutils.js
|
||||
bits/28_binstructs.js
|
||||
bits/29_xlsenum.js
|
||||
bits/30_ctype.js
|
||||
bits/31_rels.js
|
||||
bits/32_odmanrdf.js
|
||||
bits/33_coreprops.js
|
||||
bits/34_extprops.js
|
||||
bits/35_custprops.js
|
||||
bits/36_xlsprops.js
|
||||
bits/38_xlstypes.js
|
||||
bits/39_xlsbiff.js
|
||||
bits/40_harb.js
|
||||
bits/41_lotus.js
|
||||
bits/42_sstxml.js
|
||||
bits/43_sstbin.js
|
||||
bits/44_offcrypto.js
|
||||
bits/45_rtf.js
|
||||
bits/46_stycommon.js
|
||||
bits/47_styxml.js
|
||||
bits/48_stybin.js
|
||||
bits/49_theme.js
|
||||
bits/50_styxls.js
|
||||
bits/52_calcchain.js
|
||||
bits/53_externlink.js
|
||||
bits/54_drawing.js
|
||||
bits/55_vml.js
|
||||
bits/56_cmntcommon.js
|
||||
bits/57_cmntxml.js
|
||||
bits/58_cmntbin.js
|
||||
bits/59_vba.js
|
||||
bits/60_macrovba.js
|
||||
bits/61_fcommon.js
|
||||
bits/62_fxls.js
|
||||
bits/63_fbin.js
|
||||
bits/64_ftab.js
|
||||
bits/65_fods.js
|
||||
bits/66_wscommon.js
|
||||
bits/67_wsxml.js
|
||||
bits/68_wsbin.js
|
||||
bits/69_chartxml.js
|
||||
bits/70_csheet.js
|
||||
bits/71_wbcommon.js
|
||||
bits/72_wbxml.js
|
||||
bits/73_wbbin.js
|
||||
bits/74_xmlbin.js
|
||||
bits/75_xlml.js
|
||||
bits/76_xls.js
|
||||
bits/77_parsetab.js
|
||||
bits/78_writebiff.js
|
||||
bits/79_html.js
|
||||
bits/80_parseods.js
|
||||
bits/81_writeods.js
|
||||
bits/82_sheeter.js
|
||||
bits/84_defaults.js
|
||||
bits/85_parsezip.js
|
||||
bits/86_writezip.js
|
||||
bits/87_read.js
|
||||
bits/88_write.js
|
||||
bits/90_utils.js
|
||||
bits/95_api.js
|
||||
misc/98_esmxport.js
|
@ -0,0 +1,79 @@
|
||||
misc/00_esmheader.js
|
||||
bits/01_version.js
|
||||
misc/02_codepage.js
|
||||
bits/03_consts.js
|
||||
bits/04_base64.js
|
||||
bits/05_buf.js
|
||||
bits/09_types.js
|
||||
bits/10_ssf.js
|
||||
bits/11_ssfutils.js
|
||||
misc/18_esmcfb.js
|
||||
misc/19_mjsfs.js
|
||||
bits/20_jsutils.js
|
||||
misc/21_ziputils.js
|
||||
bits/22_xmlutils.js
|
||||
bits/23_binutils.js
|
||||
bits/24_hoppers.js
|
||||
bits/25_cellutils.js
|
||||
bits/27_csfutils.js
|
||||
bits/28_binstructs.js
|
||||
bits/29_xlsenum.js
|
||||
bits/30_ctype.js
|
||||
bits/31_rels.js
|
||||
bits/32_odmanrdf.js
|
||||
bits/33_coreprops.js
|
||||
bits/34_extprops.js
|
||||
bits/35_custprops.js
|
||||
bits/36_xlsprops.js
|
||||
bits/38_xlstypes.js
|
||||
bits/39_xlsbiff.js
|
||||
bits/40_harb.js
|
||||
bits/41_lotus.js
|
||||
bits/42_sstxml.js
|
||||
bits/43_sstbin.js
|
||||
bits/44_offcrypto.js
|
||||
bits/45_rtf.js
|
||||
bits/46_stycommon.js
|
||||
bits/47_styxml.js
|
||||
bits/48_stybin.js
|
||||
bits/49_theme.js
|
||||
bits/50_styxls.js
|
||||
bits/52_calcchain.js
|
||||
bits/53_externlink.js
|
||||
bits/54_drawing.js
|
||||
bits/55_vml.js
|
||||
bits/56_cmntcommon.js
|
||||
bits/57_cmntxml.js
|
||||
bits/58_cmntbin.js
|
||||
bits/59_vba.js
|
||||
bits/60_macrovba.js
|
||||
bits/61_fcommon.js
|
||||
bits/62_fxls.js
|
||||
bits/63_fbin.js
|
||||
bits/64_ftab.js
|
||||
bits/65_fods.js
|
||||
bits/66_wscommon.js
|
||||
bits/67_wsxml.js
|
||||
bits/68_wsbin.js
|
||||
bits/69_chartxml.js
|
||||
bits/70_csheet.js
|
||||
bits/71_wbcommon.js
|
||||
bits/72_wbxml.js
|
||||
bits/73_wbbin.js
|
||||
bits/74_xmlbin.js
|
||||
bits/75_xlml.js
|
||||
bits/76_xls.js
|
||||
bits/77_parsetab.js
|
||||
bits/78_writebiff.js
|
||||
bits/79_html.js
|
||||
bits/80_parseods.js
|
||||
bits/81_writeods.js
|
||||
bits/82_sheeter.js
|
||||
bits/84_defaults.js
|
||||
bits/85_parsezip.js
|
||||
bits/86_writezip.js
|
||||
bits/87_read.js
|
||||
bits/88_write.js
|
||||
bits/90_utils.js
|
||||
bits/95_api.js
|
||||
misc/98_esmxport.js
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue