Skip to content

Commit 88225f5

Browse files
committed
esm support and deno demo
1 parent dd6bb02 commit 88225f5

27 files changed

+1869
-23385
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ tmp
2020
*.[oO][dD][sS]
2121
*.[fF][oO][dD][sS]
2222
*.[xX][mM][lL]
23+
*.[xX][lL][mM][lL]
2324
*.[uU][oO][sS]
2425
*.[wW][kKqQbB][S1234567890]
2526
*.[qQ][pP][wW]

.spelling

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ tooltips
3535
Browserify
3636
CDNjs
3737
CommonJS
38+
Deno
3839
Ethercalc
3940
ExtendScript
4041
IndexedDB

Makefile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ MINITGT=xlsx.mini.js
1111
MINIFLOW=xlsx.mini.flow.js
1212
MINIDEPS=$(shell cat mini.lst)
1313

14-
NODESMTGT=xlsx.esm.mjs
15-
NODESMDEPS=$(shell cat misc/esm.lst)
1614
ESMJSTGT=xlsx.mjs
1715
ESMJSDEPS=$(shell cat misc/mjs.lst)
1816

@@ -31,7 +29,7 @@ CLOSURE=/usr/local/lib/node_modules/google-closure-compiler/compiler.jar
3129
## Main Targets
3230

3331
.PHONY: all
34-
all: $(TARGET) $(AUXTARGETS) $(AUXSCPTS) $(MINITGT) $(NODESMTGT) $(ESMJSTGT) ## Build library and auxiliary scripts
32+
all: $(TARGET) $(AUXTARGETS) $(AUXSCPTS) $(MINITGT) $(ESMJSTGT) ## Build library and auxiliary scripts
3533

3634
$(FLOWTGTS): %.js : %.flow.js
3735
node -e 'process.stdout.write(require("fs").readFileSync("$<","utf8").replace(/^[ \t]*\/\*[:#][^*]*\*\/\s*(\n)?/gm,"").replace(/\/\*[:#][^*]*\*\//gm,""))' > $@
@@ -42,9 +40,6 @@ $(FLOWTARGET): $(DEPS)
4240
$(MINIFLOW): $(MINIDEPS)
4341
cat $^ | tr -d '\15\32' > $@
4442

45-
$(NODESMTGT): $(NODESMDEPS)
46-
cat $^ | tr -d '\15\32' > $@
47-
4843
$(ESMJSTGT): $(ESMJSDEPS)
4944
cat $^ | tr -d '\15\32' > $@
5045

README.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ port calculations to web apps; automate common spreadsheet tasks, and much more!
118118

119119
### Installation
120120

121+
**Standalone Browser Scripts**
122+
121123
The complete browser standalone build is saved to `dist/xlsx.full.min.js` and
122124
can be directly added to a page with a `script` tag:
123125

@@ -167,18 +169,50 @@ be configured to remove support with `resolve.alias`:
167169
</details>
168170

169171

172+
With [bower](https://bower.io/search/?q=js-xlsx):
173+
174+
```bash
175+
$ bower install js-xlsx
176+
```
177+
178+
**Deno**
179+
180+
The [`sheetjs`](https://deno.land/x/sheetjs) package is available on deno:
181+
182+
```ts
183+
import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs'
184+
```
185+
186+
**NodeJS**
187+
170188
With [npm](https://www.npmjs.org/package/xlsx):
171189

172190
```bash
173191
$ npm install xlsx
174192
```
175193

176-
With [bower](https://bower.io/search/?q=js-xlsx):
194+
By default, the module supports `require`:
177195

178-
```bash
179-
$ bower install js-xlsx
196+
```js
197+
var XLSX = require("xlsx");
198+
```
199+
200+
The module also ships with `xlsx.mjs` for use with `import`:
201+
202+
```js
203+
import * as XLSX from 'xlsx/xlsx.mjs';
204+
205+
/* load 'fs' for readFile and writeFile support */
206+
import * as fs from 'fs';
207+
XLSX.set_fs(fs);
208+
209+
/* load the codepage support library for extended support with older formats */
210+
import * as cpexcel from 'xlsx/dist/cpexcel.full.mjs';
211+
XLSX.set_cptable(cpexcel);
180212
```
181213

214+
**PhotoShop and InDesign**
215+
182216
`dist/xlsx.extendscript.js` is an ExtendScript build for Photoshop and InDesign
183217
that is included in the `npm` package. It can be directly referenced with a
184218
`#include` directive:
@@ -1650,7 +1684,9 @@ data grid for previewing and modifying structured data in the web browser. The
16501684
[`react-data-grid`](https://npm.im/react-data-grid) is a data grid tailored for
16511685
react. It expects two properties: `rows` of data objects and `columns` which
16521686
describe the columns. For the purposes of massaging the data to fit the react
1653-
data grid API it is easiest to start from an array of arrays:
1687+
data grid API it is easiest to start from an array of arrays.
1688+
1689+
This demo starts by fetching a remote file and using `XLSX.read` to extract:
16541690

16551691
```js
16561692
import { useEffect, useState } from "react";

bits/19_fsutils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ function blobify(data) {
1111
function write_dl(fname/*:string*/, payload/*:any*/, enc/*:?string*/) {
1212
/*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
1313
if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
14+
if(typeof Deno !== 'undefined') {
15+
/* in this spot, it's safe to assume typed arrays and TextEncoder/TextDecoder exist */
16+
if(enc) switch(enc) {
17+
case "utf8": payload = new TextEncoder(enc).encode(payload); break;
18+
case "binary": payload = s2ab(payload); break;
19+
/* TODO: binary equivalent */
20+
default: throw new Error("Unsupported encoding " + enc);
21+
}
22+
return Deno.writeFileSync(fname, payload);
23+
}
1424
var data = (enc == "utf8") ? utf8write(payload) : payload;
1525
/*:: declare var IE_SaveFile: any; */
1626
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
@@ -50,6 +60,7 @@ function write_dl(fname/*:string*/, payload/*:any*/, enc/*:?string*/) {
5060
/* read binary data from file */
5161
function read_binary(path/*:string*/) {
5262
if(typeof _fs !== 'undefined') return _fs.readFileSync(path);
63+
if(typeof Deno !== 'undefined') return Deno.readFileSync(path);
5364
// $FlowIgnore
5465
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
5566
// $FlowIgnore

bits/20_jsutils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function fuzzydate(s/*:string*/)/*:Date*/ {
146146
if(isNaN(d)) return n;
147147
var lower = s.toLowerCase();
148148
if(lower.match(/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/)) {
149-
lower = lower.replace(/[^a-z]/g,"");
149+
lower = lower.replace(/[^a-z]/g,"").replace(/([^a-z]|^)[ap]m?([^a-z]|$)/,"");
150150
if(lower.length > 3 && lower_months.indexOf(lower) == -1) return n;
151151
} else if(lower.match(/[a-z]/)) return n;
152152
if(y < 0 || y > 8099) return n;

bits/40_harb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ var SYLK = (function() {
508508
case 'b': o += cell.v ? "TRUE" : "FALSE"; break;
509509
case 'e': o += cell.w || cell.v; break;
510510
case 'd': o += '"' + (cell.w || cell.v) + '"'; break;
511-
case 's': o += '"' + cell.v.replace(/"/g,"") + '"'; break;
511+
case 's': o += '"' + cell.v.replace(/"/g,"").replace(/;/g, ";;") + '"'; break;
512512
}
513513
return o;
514514
}

bits/87_read.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
7272
_ssfopts = {};
7373
if(o.dateNF) _ssfopts.dateNF = o.dateNF;
7474
if(!o.type) o.type = (has_buf && Buffer.isBuffer(data)) ? "buffer" : "base64";
75-
if(o.type == "file") { o.type = has_buf ? "buffer" : "binary"; d = read_binary(data); }
75+
if(o.type == "file") { o.type = has_buf ? "buffer" : "binary"; d = read_binary(data); if(typeof Uint8Array !== 'undefined' && !has_buf) o.type = "array"; }
7676
if(o.type == "string") { str = true; o.type = "binary"; o.codepage = 65001; d = bstrify(data); }
7777
if(o.type == 'array' && typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && typeof ArrayBuffer !== 'undefined') {
7878
// $FlowIgnore

bits/88_write.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function write_zip_type(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
4848
default: throw new Error("Unrecognized type " + o.type);
4949
}
5050
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: /*::(*/{"nodebuffer": "buffer", "string": "binary"}/*:: :any)*/[oopts.type] || oopts.type}) : z.generate(oopts);
51+
if(typeof Deno !== "undefined" && typeof out == "string") out = new Uint8Array(s2ab(out));
5152
/*jshint -W083 */
5253
if(o.password && typeof encrypt_agile !== 'undefined') return write_cfb_ctr(encrypt_agile(out, o.password), o); // eslint-disable-line no-undef
5354
/*jshint +W083 */

demos/deno/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
TESTS= x mjs jspm
2+
UNSTABLE= node
3+
.PHONY: test
4+
test: $(UNSTABLE) $(TESTS)
5+
6+
$(TESTS): %: %.ts doit.ts
7+
deno run --allow-read --allow-write $<
8+
9+
# --unstable is required, see https://github.com/denoland/deno_std/issues/1900
10+
$(UNSTABLE): %: %.ts doit.ts
11+
deno run --allow-read --allow-write --unstable $<

0 commit comments

Comments
 (0)