Skip to content

Commit

Permalink
version bump 0.8.7: bundlers
Browse files Browse the repository at this point in the history
demos for browserify/requirejs/webpack
  • Loading branch information
SheetJSDev committed Mar 5, 2017
1 parent 5ae6b19 commit 3d1f0f7
Show file tree
Hide file tree
Showing 58 changed files with 1,179 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tmp
*.[pP][rR][nN]
*.[sS][lL][kK]
*.socialcalc
*.[xX][lL][sSwW]
*.[xX][lL][sSwWcC]
*.[xX][lL][sS][xXmMbB]
*.[oO][dD][sS]
*.[fF][oO][dD][sS]
Expand Down
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test_files/
tests/files/
demos/
index.html
misc/
node_modules
Expand All @@ -10,7 +11,7 @@ tmp
*.[pP][rR][nN]
*.[sS][lL][kK]
*.socialcalc
*.[xX][lL][sSwW]
*.[xX][lL][sSwWcC]
*.[xX][lL][sS][xXmMbB]
*.[oO][dD][sS]
*.[fF][oO][dD][sS]
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ before_install:
- "npm install coveralls mocha-lcov-reporter"
before_script:
- "make init"
- "cd test_files; make all; cd -"
- "cd test_files; make all; cd -"
after_success:
- "make coveralls-spin"
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ dist: dist-deps $(TARGET) bower.json ## Prepare JS files for distribution
misc/strip_sourcemap.sh dist/$(LIB).min.js
uglifyjs $(UGLIFYOPTS) $(REQS) $(TARGET) -o dist/$(LIB).core.min.js --source-map dist/$(LIB).core.min.map --preamble "$$(head -n 1 bits/00_header.js)"
misc/strip_sourcemap.sh dist/$(LIB).core.min.js
uglifyjs $(UGLIFYOPTS) $(REQS) $(ADDONS) $(TARGET) -o dist/$(LIB).full.min.js --source-map dist/$(LIB).full.min.map --preamble "$$(head -n 1 bits/00_header.js)"
uglifyjs $(UGLIFYOPTS) $(REQS) $(ADDONS) $(TARGET) $(AUXTARGETS) -o dist/$(LIB).full.min.js --source-map dist/$(LIB).full.min.map --preamble "$$(head -n 1 bits/00_header.js)"
misc/strip_sourcemap.sh dist/$(LIB).full.min.js
cat <(head -n 1 bits/00_header.js) $(REQS) $(ADDONS) $(TARGET) $(AUXTARGETS) > demos/requirejs/$(LIB).full.js

.PHONY: dist-deps
dist-deps: ods.js ## Copy dependencies for distribution
Expand Down Expand Up @@ -91,6 +92,15 @@ TESTFMT=$(patsubst %,test_%,$(FMT))
$(TESTFMT): test_%:
FMTS=$* make test

.PHONY: demo-browserify
demo-browserify: ## Run browserify demo build
make -C demos/browserify
@echo "start a local server and go to demos/browserify/browserify.html"

.PHONY: demo-webpack
demo-webpack: ## Run webpack demo build
make -C demos/webpack
@echo "start a local server and go to demos/webpack/webpack.html"

## Code Checking

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ An appropriate version for each dependency is included in the dist/ directory.

The complete single-file version is generated at `dist/xlsx.full.min.js`

### JS Ecosystem Demos

The `demos` directory includes sample projects for:

- [`browserify`](http://browserify.org/)
- [`requirejs`](http://requirejs.org/)
- [`webpack`](https://webpack.js.org/)

### ECMAScript 5 Compatibility

Since xlsx.js uses ES5 functions like `Array#forEach`, older browsers require
Expand Down Expand Up @@ -338,7 +346,7 @@ Utilities are available in the `XLSX.utils` object:

Exporting:

- `sheet_to_json` converts a workbook object to an array of JSON objects.
- `sheet_to_json` converts a worksheet object to an array of JSON objects.
`sheet_to_row_object_array` is an alias that will be removed in the future.
- `sheet_to_csv` generates delimiter-separated-values output.
- `sheet_to_formulae` generates a list of the formulae (with value fallbacks).
Expand Down
10 changes: 8 additions & 2 deletions bin/xlsx.njs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ program
.usage('[options] <file> [sheetname]')
.option('-f, --file <file>', 'use specified workbook')
.option('-s, --sheet <sheet>', 'print specified sheet (default first sheet)')
.option('-N, --sheet-index <idx>', 'use specified sheet index (0-based)')
.option('-p, --password <pw>', 'if file is encrypted, try with specified pw')
.option('-l, --list-sheets', 'list sheet names and exit')
.option('-o, --output <file>', 'output to specified file')
Expand All @@ -25,6 +26,7 @@ program
.option('-j, --json', 'emit formatted JSON (all fields text)')
.option('-J, --raw-js', 'emit raw JS object (raw numbers)')
.option('-A, --arrays', 'emit rows as JS objects (raw numbers)')

.option('-F, --field-sep <sep>', 'CSV field separator', ",")
.option('-R, --row-sep <sep>', 'CSV row separator', "\n")
.option('-n, --sheet-rows <num>', 'Number of rows to process (0=all rows)')
Expand Down Expand Up @@ -80,6 +82,7 @@ if(program.listSheets) opts.bookSheets = true;
if(program.sheetRows) opts.sheetRows = program.sheetRows;
if(program.password) opts.password = program.password;
if(program.xlsx || program.xlsm || program.xlsb) {
opts.cellFormula = true;
opts.cellNF = true;
if(program.output) sheetname = program.output;
}
Expand Down Expand Up @@ -109,7 +112,7 @@ if(program.read) process.exit(0);

/*:: if(wb) { */
if(program.listSheets) {
console.log(wb.SheetNames.join("\n"));
console.log((wb.SheetNames||[]).join("\n"));
process.exit(0);
}

Expand All @@ -123,7 +126,10 @@ workbook_formats.forEach(function(m) { if(program[m]) {
} });

var target_sheet = sheetname || '';
if(target_sheet === '') target_sheet = wb.SheetNames[0];
if(target_sheet === '') {
if(program.sheetIndex < (wb.SheetNames||[]).length) target_sheet = wb.SheetNames[program.sheetIndex];
else target_sheet = (wb.SheetNames||[""])[0];
}

var ws;
try {
Expand Down
2 changes: 1 addition & 1 deletion bits/01_version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
XLSX.version = '0.8.6';
XLSX.version = '0.8.7';
2 changes: 1 addition & 1 deletion bits/02_codepage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var current_codepage = 1200, current_cptable;
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel');
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel.js');
current_cptable = cptable[current_codepage];
}
function reset_cp() { set_cp(1200); }
Expand Down
4 changes: 2 additions & 2 deletions bits/21_ziputils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var _fs, jszip;
if(typeof JSZip !== 'undefined') jszip = JSZip;
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
if(typeof jszip === 'undefined') jszip = require('./js'+'zip');
_fs = require('f'+'s');
if(typeof jszip === 'undefined') jszip = require('./jszip.js');
_fs = require('fs');
}
}
2 changes: 1 addition & 1 deletion bits/26_crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var make_offcrypto = function(O, _crypto) {
var crypto;
if(typeof _crypto !== 'undefined') crypto = _crypto;
else if(typeof require !== 'undefined') {
try { crypto = require('cry'+'pto'); }
try { crypto = require('crypto'); }
catch(e) { crypto = null; }
}

Expand Down
4 changes: 2 additions & 2 deletions bits/38_xlstypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function parse_VtVecHeadingPair(blob) {
/* [MS-OLEPS] 2.18.1 Dictionary (uses 2.17, 2.16) */
function parse_dictionary(blob,CodePage) {
var cnt = blob.read_shift(4);
var dict/*{[number]:string}*/ = ({}/*:any*/);
var dict/*:{[number]:string}*/ = ({}/*:any*/);
for(var j = 0; j != cnt; ++j) {
var pid = blob.read_shift(4);
var len = blob.read_shift(4);
Expand Down Expand Up @@ -149,7 +149,7 @@ function parse_PropertySet(blob, PIDSI) {
var NumProps = blob.read_shift(4);
var Props = [], i = 0;
var CodePage = 0;
var Dictionary = -1, DictObj/*{[number]:string}*/ = ({}/*:any*/);
var Dictionary = -1, DictObj/*:{[number]:string}*/ = ({}/*:any*/);
for(i = 0; i != NumProps; ++i) {
var PropID = blob.read_shift(4);
var Offset = blob.read_shift(4);
Expand Down
3 changes: 2 additions & 1 deletion bits/62_fxls.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ function parse_FormulaValue(blob) {

/* 2.5.198.103 */
function parse_RgbExtra(blob, length, rgce, opts) {
if(opts.biff < 8) return parsenoop(blob, length);
var target = blob.l + length;
var o = [];
for(var i = 0; i !== rgce.length; ++i) {
Expand Down Expand Up @@ -624,7 +625,6 @@ function parse_ArrayParsedFormula(blob, length, opts, ref) {
}

/* 2.5.198.104 */
var gcnt = 0;
function parse_Rgce(blob, length, opts) {
var target = blob.l + length;
var R, id, ptgs = [];
Expand Down Expand Up @@ -892,6 +892,7 @@ function stringify_formula(formula, range, cell, supbooks, opts) {

/* 2.5.198.38 */
case 'PtgAttrSpace':
/* 2.5.198.39 */
case 'PtgAttrSpaceSemi':
last_sp = ff;
break;
Expand Down
2 changes: 1 addition & 1 deletion bits/75_xlml.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ function parse_xlml_xml(d, opts) {
}
if(opts.WTF) throw 'Unrecognized tag: ' + Rn[3] + "|" + state.join("|");
}
var out = ({}/*:Any*/);
var out = ({}/*:any*/);
if(!opts.bookSheets && !opts.bookProps) out.Sheets = sheets;
out.SheetNames = sheetnames;
out.SSF = SSF.get_table();
Expand Down
8 changes: 5 additions & 3 deletions bits/76_xls.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function parse_workbook(blob, options/*:ParseOpts*/)/*:Workbook*/ {
var length = (blob.l === blob.length ? 0 : blob.read_shift(2)), y;
var R = XLSRecordEnum[RecordType];
//console.log(RecordType.toString(16), RecordType, R, blob.l, length, blob.length);
//if(!R) console.log(blob.slice(blob.l, blob.l + length));
if(R && R.f) {
if(options.bookSheets) {
if(last_Rn === 'BoundSheet8' && R.n !== 'BoundSheet8') break;
Expand Down Expand Up @@ -253,12 +254,13 @@ function parse_workbook(blob, options/*:ParseOpts*/)/*:Workbook*/ {
} break;
case 'BOF': {
if(opts.biff !== 8){}
else if(val.BIFFVer === 0x0500) opts.biff = 5;
else if(val.BIFFVer === 0x0002) opts.biff = 2;
else if(val.BIFFVer === 0x0007) opts.biff = 2;
else if(RecordType === 0x0009) opts.biff = 2;
else if(RecordType === 0x0209) opts.biff = 3;
else if(RecordType === 0x0409) opts.biff = 4;
else if(val.BIFFVer === 0x0500) opts.biff = 5;
else if(val.BIFFVer === 0x0600) opts.biff = 8;
else if(val.BIFFVer === 0x0002) opts.biff = 2;
else if(val.BIFFVer === 0x0007) opts.biff = 2;
if(file_depth++) break;
cell_valid = true;
out = {};
Expand Down
11 changes: 8 additions & 3 deletions bits/83_ods.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
/* Helper functions to call out to ODS */

function get_ods() {
if(typeof module !== "undefined" && typeof require !== 'undefined' && typeof ODS === 'undefined') ODS = require('./ods.js');
return ODS;
}
function parse_ods(zip, opts) {
if(typeof module !== "undefined" && typeof require !== 'undefined' && typeof ODS === 'undefined') ODS = require('./od' + 's');
get_ods();
if(typeof ODS === 'undefined' || !ODS.parse_ods) throw new Error("Unsupported ODS");
return ODS.parse_ods(zip, opts);
}
function write_ods(wb, opts) {
if(typeof module !== "undefined" && typeof require !== 'undefined' && typeof ODS === 'undefined') ODS = require('./od' + 's');
get_ods();
if(typeof ODS === 'undefined' || !ODS.write_ods) throw new Error("Unsupported ODS");
return ODS.write_ods(wb, opts);
}
function parse_fods(data, opts) {
if(typeof module !== "undefined" && typeof require !== 'undefined' && typeof ODS === 'undefined') ODS = require('./od' + 's');
get_ods();
if(typeof ODS === 'undefined' || !ODS.parse_fods) throw new Error("Unsupported ODS");
return ODS.parse_fods(data, opts);
}
13 changes: 10 additions & 3 deletions bits/90_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ function unfix_col(cstr/*:string*/)/*:string*/ { return cstr.replace(/^\$([A-Z])

function split_cell(cstr/*:string*/)/*:Array<string>*/ { return cstr.replace(/(\$?[A-Z]*)(\$?\d*)/,"$1,$2").split(","); }
function decode_cell(cstr/*:string*/)/*:CellAddress*/ { var splt = split_cell(cstr); return { c:decode_col(splt[0]), r:decode_row(splt[1]) }; }
function encode_cell(cell/*:Cell*/)/*:string*/ { return encode_col(cell.c) + encode_row(cell.r); }
function encode_cell(cell/*:CellAddress*/)/*:string*/ { return encode_col(cell.c) + encode_row(cell.r); }
function fix_cell(cstr/*:string*/)/*:string*/ { return fix_col(fix_row(cstr)); }
function unfix_cell(cstr/*:string*/)/*:string*/ { return unfix_col(unfix_row(cstr)); }
function decode_range(range/*:string*/)/*:Range*/ { var x =range.split(":").map(decode_cell); return {s:x[0],e:x[x.length-1]}; }
function encode_range(cs/*:any*/,ce/*:?any*/)/*:string*/ {
if(ce === undefined || typeof ce === 'number') return encode_range(cs.s, cs.e);
if(typeof cs !== 'string') cs = encode_cell(cs); if(typeof ce !== 'string') ce = encode_cell(ce);
if(typeof ce === 'undefined' || typeof ce === 'number') {
/*:: if(!(cs instanceof Range)) throw "unreachable"; */
return encode_range(cs.s, cs.e);
}
/*:: if((cs instanceof Range)) throw "unreachable"; */
if(typeof cs !== 'string') cs = encode_cell((cs/*:any*/));
if(typeof ce !== 'string') ce = encode_cell((ce/*:any*/));
/*:: if(typeof cs !== 'string') throw "unreachable"; */
/*:: if(typeof ce !== 'string') throw "unreachable"; */
return cs == ce ? cs : cs + ":" + ce;
}

Expand Down
2 changes: 2 additions & 0 deletions demos/browserify/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
browserify.js
browserify.min.js
10 changes: 10 additions & 0 deletions demos/browserify/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TOOL=browserify
.PHONY: all
all: $(TOOL).min.js

$(TOOL).min.js: $(TOOL).js
uglifyjs $< > $@

.PHONY: $(TOOL).js
$(TOOL).js:
browserify -r './main.js:xlsx' > $@
Loading

0 comments on commit 3d1f0f7

Please sign in to comment.