Permalink
Browse files

version bump 0.7.6: IE compatibility

- jscs linting to check for trailing comma issues (h/t @altkatz)
- IE: phased out lazy string indexing in favor of charCodeAt
- XLSX: replaced certain operations in hot functions with faster alternatives
- updated SSF to 0.7.1
- improved coverage in tests
1 parent a96b723 commit 44b55c5c568fb5c5fe39a48efec999b54f07ffe8 @SheetJSDev SheetJSDev committed Jun 5, 2014
View
@@ -1,3 +1,4 @@
node_modules
misc/coverage.html
tmp
+*.xlsx
View
@@ -0,0 +1,6 @@
+{
+ "requireCommaBeforeLineBreak": true,
+ "disallowTrailingWhitespace": true,
+ "disallowTrailingComma": true
+}
+
View
@@ -1,5 +1,6 @@
language: node_js
node_js:
+ - "0.11"
- "0.10"
- "0.8"
before_install:
View
@@ -13,7 +13,11 @@ bits/01_version.js: package.json
.PHONY: clean
clean:
- rm $(TARGET)
+ rm -f $(TARGET)
+
+.PHONY: clean-data
+clean-data:
+ rm -f *.xlsx *.xlsm *.xlsb *.xls *.xml
.PHONY: init
init:
@@ -37,6 +41,13 @@ $(TESTFMT): test_%:
.PHONY: lint
lint: $(TARGET)
jshint --show-non-errors $(TARGET)
+ jscs $(TARGET)
+
+.PHONY: test-osx
+test-osx:
+ node tests/write.js
+ open -a Numbers sheetjs.xlsx
+ open -a "Microsoft Excel" sheetjs.xlsx
.PHONY: cov cov-spin
cov: misc/coverage.html
View
@@ -1 +1 @@
-XLSX.version = '0.7.5';
+XLSX.version = '0.7.6';
View
@@ -13,7 +13,7 @@ if(typeof cptable !== 'undefined') _getchar = function(x) {
return cptable.utils.decode(current_codepage, [x%256,x>>8])[0];
};
-function char_codes(data) { return data.split("").map(function(x) { return x.charCodeAt(0); }); }
+function char_codes(data) { var o = []; for(var i = 0; i != data.length; ++i) o[i] = data.charCodeAt(i); return o; }
function debom_xml(data) {
if(typeof cptable !== 'undefined') {
if(data.charCodeAt(0) === 0xFF && data.charCodeAt(1) === 0xFE) { return cptable.utils.decode(1200, char_codes(data.substr(2))); }
View
@@ -5,7 +5,7 @@ var _strrev = function(x) { return String(x).split("").reverse().join("");};
function fill(c,l) { return new Array(l+1).join(c); }
function pad(v,d,c){var t=String(v);return t.length>=d?t:(fill(c||0,d-t.length)+t);}
function rpad(v,d,c){var t=String(v);return t.length>=d?t:(t+fill(c||0,d-t.length));}
-SSF.version = '0.7.0';
+SSF.version = '0.7.1';
/* Options */
var opts_fmt = {
date1904:0,
@@ -252,7 +252,10 @@ var write_num = function(type, fmt, val) {
}
if(fmt.match(/^#+0+$/)) fmt = fmt.replace(/#/g,"");
if(fmt.match(/^00+$/)) return (val<0?"-":"")+pad(Math.round(aval),fmt.length);
- if(fmt.match(/^[#?]+$/)) return String(Math.round(val)).replace(/^0$/,"");
+ if(fmt.match(/^[#?]+$/)) {
+ o = String(Math.round(val)).replace(/^0$/,"");
+ return o.length > fmt.length ? o : fmt.substr(0,fmt.length-o.length).replace(/#/g,"").replace(/[?]/g," ") + o;
+ }
if((r = fmt.match(/^#*0*\.(0+)/))) {
o = Math.round(val * Math.pow(10,r[1].length));
rr = String(o/Math.pow(10,r[1].length)).replace(/^([^\.]+)$/,"$1."+r[1]).replace(/\.$/,"."+r[1]).replace(/\.([0-9]*)$/,function($$, $1) { return "." + $1 + fill("0", r[1].length-$1.length); });
@@ -278,20 +281,32 @@ var write_num = function(type, fmt, val) {
ff = write_num(type, "##########", val);
return "(" + ff.substr(0,3) + ") " + ff.substr(3, 3) + "-" + ff.substr(6);
}
- if((r = fmt.match(/^([?]+)([ ]?)\/([ ]?)([?]+)/))) {
- rr = Math.min(Math.max(r[1].length, r[4].length),7);
+ var oa = "";
+ if((r = fmt.match(/^([#0?]+)([ ]?)\/([ ]?)([#0?]+)/))) {
+ o="";
+ rr = Math.min(r[4].length,7);
ff = frac(aval, Math.pow(10,rr)-1, false);
- return sign + (ff[0]||(ff[1] ? "" : "0")) + (ff[1] ? pad(ff[1],rr," ") + r[2] + "/" + r[3] + rpad(ff[2],rr," "): fill(" ", 2*rr+1 + r[2].length + r[3].length));
+ o += sign;
+ oa = write_num("n", r[1], ff[1]);
+ if(oa[oa.length-1] == " ") oa = oa.substr(0,oa.length-1) + "0";
+ o += oa;
+ o += r[2];
+ o += "/";
+ o += r[3];
+ oa = rpad(ff[2],rr," ");
+ if(oa.length < r[4].length) oa = r[4].substr(r[4].length-oa.length).replace(/[?]/g," ").replace(/#/g,"") + oa;
+ o += oa;
+ return o;
}
- if((r = fmt.match(/^# ([?]+)([ ]?)\/([ ]?)([?]+)/))) {
+ if((r = fmt.match(/^# ([#0?]+)([ ]?)\/([ ]?)([#0?]+)/))) {
rr = Math.min(Math.max(r[1].length, r[4].length),7);
ff = frac(aval, Math.pow(10,rr)-1, true);
return sign + (ff[0]||(ff[1] ? "" : "0")) + " " + (ff[1] ? pad(ff[1],rr," ") + r[2] + "/" + r[3] + rpad(ff[2],rr," "): fill(" ", 2*rr+1 + r[2].length + r[3].length));
}
- if((r = fmt.match(/^[#0]+$/))) {
+ if((r = fmt.match(/^[#0?]+$/))) {
o = "" + Math.round(val);
if(fmt.length <= o.length) return o;
- return fmt.substr(0,fmt.length - o.length).replace(/#/g,"") + o;
+ return fmt.substr(0,fmt.length-o.length).replace(/#/g,"").replace(/\?/g," ") + o;
}
if((r = fmt.match(/^([#0]+)\.([#0]+)$/))) {
o = "" + val.toFixed(Math.min(r[2].length,10)).replace(/([^0])0+$/,"$1");
@@ -507,7 +522,9 @@ function eval_fmt(fmt, v, opts, flen) {
out[i].v = write_num(out[i].t, out[i].v, (flen >1 && v < 0 && i>0 && out[i-1].v == "-" ? -v:v));
out[i].t = 't';
}
- return out.map(function(x){return x.v;}).join("");
+ var retval = "";
+ for(i=0; i != out.length; ++i) if(out[i]) retval += out[i].v;
+ return retval;
}
SSF._eval = eval_fmt;
function choose_fmt(fmt, v, o) {
View
@@ -2,9 +2,9 @@ var _chr = function(c) { return String.fromCharCode(c); };
var _ord = function(c) { return c.charCodeAt(0); };
var attregexg=/([\w:]+)=((?:")([^"]*)(?:")|(?:')([^']*)(?:'))/g;
var attregex=/([\w:]+)=((?:")(?:[^"]*)(?:")|(?:')(?:[^']*)(?:'))/;
-function parsexmltag(tag) {
+function parsexmltag(tag, skip_root) {
var words = tag.split(/\s+/);
- var z = {'0': words[0]};
+ var z = []; if(!skip_root) z[0] = words[0];
if(words.length === 1) return z;
var m = tag.match(attregexg), y, j, w, i;
if(m) for(i = 0; i != m.length; ++i) {
View
@@ -140,7 +140,7 @@ var parse_si = function(x, opts) {
if(!x) return null;
var y;
/* 18.4.12 t ST_Xstring (Plaintext String) */
- if(x[1] === 't') {
+ if(x.charCodeAt(1) === 116) {
z.t = utf8read(unescapexml(x.substr(x.indexOf(">")+1).split(/<\/t>/)[0]));
z.r = x;
if(html) z.h = z.t;
View
@@ -20,23 +20,23 @@ function parse_fills(t, opts) {
/* 18.8.3 bgColor CT_Color */
case '<bgColor':
if(!fill.bgColor) fill.bgColor = {};
- if(y.indexed) fill.bgColor.indexed = parseInt(y.indexed);
- if(y.theme) fill.bgColor.theme = parseInt(y.theme);
+ if(y.indexed) fill.bgColor.indexed = Number(y.indexed);
+ if(y.theme) fill.bgColor.theme = Number(y.theme);
if(y.tint) fill.bgColor.tint = Number(y.tint);
/* Excel uses ARGB strings */
if(y.rgb) fill.bgColor.rgb = y.rgb.substring(y.rgb.length - 6);
break;
- case '</bgColor>': break;
+ case '<bgColor/>': case '</bgColor>': break;
/* 18.8.19 fgColor CT_Color */
case '<fgColor':
if(!fill.fgColor) fill.fgColor = {};
- if(y.theme) fill.fgColor.theme = parseInt(y.theme);
+ if(y.theme) fill.fgColor.theme = Number(y.theme);
if(y.tint) fill.fgColor.tint = Number(y.tint);
/* Excel uses ARGB strings */
if(y.rgb) fill.fgColor.rgb = y.rgb.substring(y.rgb.length - 6);
break;
- case '</fgColor>': break;
+ case '<bgColor/>': case '</fgColor>': break;
default: if(opts.WTF) throw 'unrecognized ' + y[0] + ' in fills';
}
View
@@ -66,6 +66,7 @@ function parse_clrScheme(t, opts) {
/* 14.2.7 Theme Part */
function parse_theme_xml(data, opts) {
+ if(!data || data.length === 0) return themes;
themes.themeElements = {};
var t;
Oops, something went wrong.

0 comments on commit 44b55c5

Please sign in to comment.