diff --git a/bits/83_numbers.js b/bits/83_numbers.js index 06a0b9d..eff0997 100644 --- a/bits/83_numbers.js +++ b/bits/83_numbers.js @@ -1,22 +1,7 @@ /*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */ -var subarray = function() { - try { - if (typeof Uint8Array == "undefined") - return "slice"; - if (typeof Uint8Array.prototype.subarray == "undefined") - return "slice"; - if (typeof Buffer !== "undefined") { - if (typeof Buffer.prototype.subarray == "undefined") - return "slice"; - if ((typeof Buffer.from == "function" ? Buffer.from([72, 62]) : new Buffer([72, 62])) instanceof Uint8Array) - return "subarray"; - return "slice"; - } - return "subarray"; - } catch (e) { - return "slice"; - } -}(); +var subarray = typeof Uint8Array !== "undefined" && typeof Uint8Array.prototype.subarray != "undefined" ? "subarray" : "slice"; +if (typeof Buffer !== "undefined" && typeof Buffer.prototype.subarray == "undefined") + subarray = "slice"; function u8_to_dataview(array) { return new DataView(array.buffer, array.byteOffset, array.byteLength); } @@ -332,10 +317,10 @@ function parse_snappy_chunk(type, buf) { throw new Error("Invalid offset beyond length"); } if (length < off) - chunks.push(chunks[j][subarray](chunks[j].length - off, chunks[j].length - off + length)); + chunks.push(chunks[j][subarray](-off, -off + length)); else { if (off > 0) { - chunks.push(chunks[j][subarray](chunks[j].length - off)); + chunks.push(chunks[j][subarray](-off)); length -= off; } ++j; diff --git a/bits/85_parsezip.js b/bits/85_parsezip.js index 5760daf..a1db4e7 100644 --- a/bits/85_parsezip.js +++ b/bits/85_parsezip.js @@ -84,8 +84,6 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ { opts = dup(opts); delete opts.type; if(typeof index_zip.content == "string") opts.type = "binary"; - // TODO: Bun buffer bug - if(typeof Bun !== "undefined" && Buffer.isBuffer(index_zip.content)) return readSync(new Uint8Array(index_zip.content), opts); return readSync(index_zip.content, opts); } throw new Error('Unsupported ZIP file'); diff --git a/hotcross.mjs b/hotcross.mjs index 9962b14..bc7eeb3 100644 --- a/hotcross.mjs +++ b/hotcross.mjs @@ -1,7 +1,7 @@ -var pdizzle = 0, fails = 0, passes = 0; +var pdizzle = 0, fails = 0; var describe = function(m,cb){console.log(" ".repeat(pdizzle) + m); ++pdizzle; if(cb) cb(); --pdizzle; }; describe.skip = function(m,cb){}; -var it = function(m,cb){console.log(" ".repeat(pdizzle) + m); ++pdizzle; if(cb) try { cb(); ++passes } catch(e) { ++fails, console.log("\x1b[31mFAILED: " + (e.message || e) + "\x1b[0m"); } --pdizzle;}; +var it = function(m,cb){console.log(" ".repeat(pdizzle) + m); ++pdizzle; if(cb) try { cb(); } catch(e) { ++fails, console.log("FAILED: " + (e.message || e)); } --pdizzle;}; it.skip = function(m,cb){}; var before = function(cb){if(cb) cb();}; var afterEach = function(cb){if(cb) cb();}; @@ -691,20 +691,22 @@ describe('parse options', function() { }); }); }); }); +console.log(`${fails} FAILED`); +process.exit(fails > 0); describe('input formats', function() { - if(false) it('should read binary strings', function() { artifax.forEach(function(p) { + it('should read binary strings', function() { artifax.forEach(function(p) { X.read(fs.readFileSync(p, 'binary'), {type: 'binary'}); }); }); - if(false) it('should read base64 strings', function() { artifax.forEach(function(p) { + it('should read base64 strings', function() { artifax.forEach(function(p) { X.read(fs.readFileSync(p, 'base64'), {type: 'base64'}); }); }); - if(false) if(typeof Uint8Array !== 'undefined') it('should read array', function() { artifax.forEach(function(p) { + if(typeof Uint8Array !== 'undefined') it('should read array', function() { artifax.forEach(function(p) { X.read(fs.readFileSync(p, 'binary').split("").map(function(x) { return x.charCodeAt(0); }), {type:'array'}); }); }); ((browser || typeof Buffer === 'undefined') ? it.skip : it)('should read Buffers', function() { artifax.forEach(function(p) { X.read(fs.readFileSync(p), {type: 'buffer'}); }); }); - if(false) if(typeof Uint8Array !== 'undefined') it('should read ArrayBuffer / Uint8Array', function() { artifax.forEach(function(p) { + if(typeof Uint8Array !== 'undefined') it('should read ArrayBuffer / Uint8Array', function() { artifax.forEach(function(p) { var payload = fs.readFileSync(p, browser ? 'buffer' : null); var ab = new ArrayBuffer(payload.length), vu = new Uint8Array(ab); for(var i = 0; i < payload.length; ++i) vu[i] = payload[i]; @@ -716,13 +718,13 @@ describe('input formats', function() { }); }); var T = browser ? 'base64' : 'buffer'; - if(false) it('should default to "' + T + '" type', function() { artifax.forEach(function(p) { + it('should default to "' + T + '" type', function() { artifax.forEach(function(p) { X.read(fs.readFileSync.apply(fs, browser ? [p, 'base64'] : [p])); }); }); if(!browser) it('should read files', function() { artifax.forEach(function(p) { X.readFile(p); }); }); }); -if(false) describe('output formats', function() { +describe('output formats', function() { var fmts = [ /* fmt unicode str */ ["xlsx", true, false], @@ -952,7 +954,7 @@ describe('parse features', function() { }); }); }); - if(false) describe('should parse core properties and custom properties', function() { + describe('should parse core properties and custom properties', function() { var wbs=[]; var bef = (function() { wbs = [ @@ -1021,7 +1023,7 @@ describe('parse features', function() { }); }); - if(false) describe('column properties', function() { + describe('column properties', function() { var wbs = [], wbs_no_slk = []; var bef = (function() { wbs = CWPaths.map(function(n) { return X.read(fs.readFileSync(n), {type:TYPE, cellStyles:true}); }); @@ -1062,7 +1064,7 @@ describe('parse features', function() { }); }); - if(false) describe('row properties', function() { + describe('row properties', function() { var wbs = [], ols = []; var ol = fs.existsSync(paths.olxls); var bef = (function() { @@ -1135,15 +1137,15 @@ describe('parse features', function() { if(typeof before != 'undefined') before(bef); else it('before', bef); - ['xlsx', 'xlsb', /* 'xls', 'xml'*/].forEach(function(x, i) { + ['xlsx', 'xlsb', 'xls', 'xml'].forEach(function(x, i) { it(x + " external", function() { hlink1(wb1[i].Sheets["Sheet1"]); }); }); - ['xlsx', 'xlsb', /* 'xls', 'xml', 'ods'*/].forEach(function(x, i) { + ['xlsx', 'xlsb', 'xls', 'xml', 'ods'].forEach(function(x, i) { it(x + " internal", function() { hlink2(wb2[i].Sheets["Sheet1"]); }); }); }); - if(false) describe('should parse cells with date type (XLSX/XLSM)', function() { + describe('should parse cells with date type (XLSX/XLSM)', function() { it('Must have read the date', function() { var wb, ws; var sheetName = 'Sheet1'; @@ -1210,7 +1212,7 @@ describe('parse features', function() { assert.equal(names[i].Ref, "Sheet1!$A$2"); }); }); }); - if(false) describe('defined names unicode', function() {[ + describe('defined names unicode', function() {[ /* desc path RT */ ['xlsx', paths.dnuxlsx, true], ['xlsb', paths.dnuxlsb, true], @@ -1244,7 +1246,7 @@ describe('parse features', function() { }); }); }); }); }); - if(false) describe('workbook codename unicode', function() { + describe('workbook codename unicode', function() { var ws, wb; var bef = (function() { wb = X.utils.book_new(); @@ -1297,7 +1299,7 @@ describe('parse features', function() { }); }); }); - if(false) describe('page margins', function() { + describe('page margins', function() { var wbs=[]; var bef = (function() { if(!fs.existsSync(paths.pmxls)) return; @@ -1410,7 +1412,7 @@ describe('parse features', function() { assert.equal(data[5][1], '7,890'); }); }); }); - if(false) it('date system', function() {[ + it('date system', function() {[ "biff5", "ods", "slk", "xls", "xlsb", "xlsx", "xml" ].forEach(function(ext) { // TODO: verify actual date values @@ -1435,7 +1437,7 @@ describe('parse features', function() { ].join("\n")); }); }); - if(false) it('bookType metadata', function() { + it('bookType metadata', function() { [ // TODO: keep in sync with BookType, support other formats "xlsx"/*, "xlsm" */, "xlsb"/* xls / xla / biff# */, "xlml", "ods", "fods"/*, "csv", "txt", */, "sylk", "html", "dif", "rtf"/*, "prn", "eth"*/, "dbf", "numbers" @@ -1446,7 +1448,6 @@ describe('parse features', function() { assert.equal(X.read(data, {type: TYPE, WTF: true}).bookType, r); }); }); }); -console.log(`${fails} FAILED ${passes} PASSED`); process.exit(fails > 0); describe('write features', function() { describe('props', function() { diff --git a/modules/83_numbers.js b/modules/83_numbers.js index 06a0b9d..eff0997 100644 --- a/modules/83_numbers.js +++ b/modules/83_numbers.js @@ -1,22 +1,7 @@ /*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */ -var subarray = function() { - try { - if (typeof Uint8Array == "undefined") - return "slice"; - if (typeof Uint8Array.prototype.subarray == "undefined") - return "slice"; - if (typeof Buffer !== "undefined") { - if (typeof Buffer.prototype.subarray == "undefined") - return "slice"; - if ((typeof Buffer.from == "function" ? Buffer.from([72, 62]) : new Buffer([72, 62])) instanceof Uint8Array) - return "subarray"; - return "slice"; - } - return "subarray"; - } catch (e) { - return "slice"; - } -}(); +var subarray = typeof Uint8Array !== "undefined" && typeof Uint8Array.prototype.subarray != "undefined" ? "subarray" : "slice"; +if (typeof Buffer !== "undefined" && typeof Buffer.prototype.subarray == "undefined") + subarray = "slice"; function u8_to_dataview(array) { return new DataView(array.buffer, array.byteOffset, array.byteLength); } @@ -332,10 +317,10 @@ function parse_snappy_chunk(type, buf) { throw new Error("Invalid offset beyond length"); } if (length < off) - chunks.push(chunks[j][subarray](chunks[j].length - off, chunks[j].length - off + length)); + chunks.push(chunks[j][subarray](-off, -off + length)); else { if (off > 0) { - chunks.push(chunks[j][subarray](chunks[j].length - off)); + chunks.push(chunks[j][subarray](-off)); length -= off; } ++j; diff --git a/modules/83_numbers.ts b/modules/83_numbers.ts index f3b00ed..be8f2ce 100644 --- a/modules/83_numbers.ts +++ b/modules/83_numbers.ts @@ -17,19 +17,8 @@ declare var CFB: typeof _CFB; //< { - try { - if(typeof Uint8Array == "undefined") return "slice"; - if(typeof Uint8Array.prototype.subarray == "undefined") return "slice"; - // NOTE: feature tests are for node < 6.x - if(typeof Buffer !== "undefined") { - if(typeof Buffer.prototype.subarray == "undefined") return "slice"; - if((typeof Buffer.from == "function" ? Buffer.from([72,62]) : new Buffer([72,62])) instanceof Uint8Array) return "subarray"; - return "slice"; - } - return "subarray"; - } catch(e) { return "slice"; } -})(); +var subarray = typeof Uint8Array !== "undefined" && typeof Uint8Array.prototype.subarray != "undefined" ? "subarray" : "slice"; +if(typeof Buffer !== "undefined" && typeof Buffer.prototype.subarray == "undefined") subarray = "slice"; function u8_to_dataview(array: Uint8Array): DataView { return new DataView(array.buffer, array.byteOffset, array.byteLength); } //< 0) { chunks.push(chunks[j][subarray](chunks[j].length-off)); length -= off; } ++j; + if(off > 0) { chunks.push(chunks[j][subarray](-off)); length -= off; } ++j; while(length >= chunks[j].length) { chunks.push(chunks[j]); length -= chunks[j].length; ++j; } if(length) chunks.push(chunks[j][subarray](0, length)); } diff --git a/package.json b/package.json index 03de5a0..12d72ea 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,12 @@ "unpkg": "dist/xlsx.full.min.js", "jsdelivr": "dist/xlsx.full.min.js", "types": "types/index.d.ts", + "exports": { + ".": { + "import": "./xlsx.mjs", + "require": "./xlsx.js" + } + }, "browser": { "buffer": false, "crypto": false, diff --git a/xlsx.flow.js b/xlsx.flow.js index c3616ef..92c4bb2 100644 --- a/xlsx.flow.js +++ b/xlsx.flow.js @@ -23066,24 +23066,9 @@ function write_ods(wb/*:any*/, opts/*:any*/) { } /*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */ -var subarray = function() { - try { - if (typeof Uint8Array == "undefined") - return "slice"; - if (typeof Uint8Array.prototype.subarray == "undefined") - return "slice"; - if (typeof Buffer !== "undefined") { - if (typeof Buffer.prototype.subarray == "undefined") - return "slice"; - if ((typeof Buffer.from == "function" ? Buffer.from([72, 62]) : new Buffer([72, 62])) instanceof Uint8Array) - return "subarray"; - return "slice"; - } - return "subarray"; - } catch (e) { - return "slice"; - } -}(); +var subarray = typeof Uint8Array !== "undefined" && typeof Uint8Array.prototype.subarray != "undefined" ? "subarray" : "slice"; +if (typeof Buffer !== "undefined" && typeof Buffer.prototype.subarray == "undefined") + subarray = "slice"; function u8_to_dataview(array) { return new DataView(array.buffer, array.byteOffset, array.byteLength); } @@ -23399,10 +23384,10 @@ function parse_snappy_chunk(type, buf) { throw new Error("Invalid offset beyond length"); } if (length < off) - chunks.push(chunks[j][subarray](chunks[j].length - off, chunks[j].length - off + length)); + chunks.push(chunks[j][subarray](-off, -off + length)); else { if (off > 0) { - chunks.push(chunks[j][subarray](chunks[j].length - off)); + chunks.push(chunks[j][subarray](-off)); length -= off; } ++j; @@ -24459,8 +24444,6 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ { opts = dup(opts); delete opts.type; if(typeof index_zip.content == "string") opts.type = "binary"; - // TODO: Bun buffer bug - if(typeof Bun !== "undefined" && Buffer.isBuffer(index_zip.content)) return readSync(new Uint8Array(index_zip.content), opts); return readSync(index_zip.content, opts); } throw new Error('Unsupported ZIP file'); diff --git a/xlsx.js b/xlsx.js index 155678a..9d7f4a5 100644 --- a/xlsx.js +++ b/xlsx.js @@ -22956,24 +22956,9 @@ function write_ods(wb, opts) { } /*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */ -var subarray = function() { - try { - if (typeof Uint8Array == "undefined") - return "slice"; - if (typeof Uint8Array.prototype.subarray == "undefined") - return "slice"; - if (typeof Buffer !== "undefined") { - if (typeof Buffer.prototype.subarray == "undefined") - return "slice"; - if ((typeof Buffer.from == "function" ? Buffer.from([72, 62]) : new Buffer([72, 62])) instanceof Uint8Array) - return "subarray"; - return "slice"; - } - return "subarray"; - } catch (e) { - return "slice"; - } -}(); +var subarray = typeof Uint8Array !== "undefined" && typeof Uint8Array.prototype.subarray != "undefined" ? "subarray" : "slice"; +if (typeof Buffer !== "undefined" && typeof Buffer.prototype.subarray == "undefined") + subarray = "slice"; function u8_to_dataview(array) { return new DataView(array.buffer, array.byteOffset, array.byteLength); } @@ -23289,10 +23274,10 @@ function parse_snappy_chunk(type, buf) { throw new Error("Invalid offset beyond length"); } if (length < off) - chunks.push(chunks[j][subarray](chunks[j].length - off, chunks[j].length - off + length)); + chunks.push(chunks[j][subarray](-off, -off + length)); else { if (off > 0) { - chunks.push(chunks[j][subarray](chunks[j].length - off)); + chunks.push(chunks[j][subarray](-off)); length -= off; } ++j; @@ -24349,8 +24334,6 @@ function parse_zip(zip, opts) { opts = dup(opts); delete opts.type; if(typeof index_zip.content == "string") opts.type = "binary"; - // TODO: Bun buffer bug - if(typeof Bun !== "undefined" && Buffer.isBuffer(index_zip.content)) return readSync(new Uint8Array(index_zip.content), opts); return readSync(index_zip.content, opts); } throw new Error('Unsupported ZIP file'); diff --git a/xlsx.mjs b/xlsx.mjs index 85c9e96..8da653a 100644 --- a/xlsx.mjs +++ b/xlsx.mjs @@ -23061,24 +23061,9 @@ function write_ods(wb/*:any*/, opts/*:any*/) { } /*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */ -var subarray = function() { - try { - if (typeof Uint8Array == "undefined") - return "slice"; - if (typeof Uint8Array.prototype.subarray == "undefined") - return "slice"; - if (typeof Buffer !== "undefined") { - if (typeof Buffer.prototype.subarray == "undefined") - return "slice"; - if ((typeof Buffer.from == "function" ? Buffer.from([72, 62]) : new Buffer([72, 62])) instanceof Uint8Array) - return "subarray"; - return "slice"; - } - return "subarray"; - } catch (e) { - return "slice"; - } -}(); +var subarray = typeof Uint8Array !== "undefined" && typeof Uint8Array.prototype.subarray != "undefined" ? "subarray" : "slice"; +if (typeof Buffer !== "undefined" && typeof Buffer.prototype.subarray == "undefined") + subarray = "slice"; function u8_to_dataview(array) { return new DataView(array.buffer, array.byteOffset, array.byteLength); } @@ -23394,10 +23379,10 @@ function parse_snappy_chunk(type, buf) { throw new Error("Invalid offset beyond length"); } if (length < off) - chunks.push(chunks[j][subarray](chunks[j].length - off, chunks[j].length - off + length)); + chunks.push(chunks[j][subarray](-off, -off + length)); else { if (off > 0) { - chunks.push(chunks[j][subarray](chunks[j].length - off)); + chunks.push(chunks[j][subarray](-off)); length -= off; } ++j; @@ -24454,8 +24439,6 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ { opts = dup(opts); delete opts.type; if(typeof index_zip.content == "string") opts.type = "binary"; - // TODO: Bun buffer bug - if(typeof Bun !== "undefined" && Buffer.isBuffer(index_zip.content)) return readSync(new Uint8Array(index_zip.content), opts); return readSync(index_zip.content, opts); } throw new Error('Unsupported ZIP file');