From e3301e1ff1b793576809f473821b82f71e06a9dd Mon Sep 17 00:00:00 2001 From: SheetJS Date: Sat, 6 Apr 2013 17:56:20 -0400 Subject: [PATCH] version bump 0.2.3: refactoring - internally renamed count->Count and uniqueCount->Unique like xlsjs - factored out xml bool parsing --- bits/70_xlsx.js | 15 +++++++++------ package.json | 2 +- xlsx.js | 15 +++++++++------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/bits/70_xlsx.js b/bits/70_xlsx.js index 2409ccc..2172c4c 100644 --- a/bits/70_xlsx.js +++ b/bits/70_xlsx.js @@ -117,6 +117,13 @@ function parsexmltag(tag) { return z; } +function parsexmlbool(value, tag) { + switch(value) { + case '0': case 0: case 'false': case 'FALSE': return false; + case '1': case 1: case 'true': case 'TRUE': return true; + default: throw "bad boolean value " + value + " in "+(tag||"?"); + } +} var strs = {}; // shared strings var styles = {}; // shared styles @@ -238,7 +245,7 @@ function parseStrs(data) { s = sst[2].replace(//g,"").split(/<\/si>/).map(function(x) { var z = {}; var y=x.match(/<(.*)>([\s\S]*)<\/.*/); if(y) z[y[1].split(" ")[0]]=utf8read(unescapexml(y[2])); return z;}); - sst = parsexmltag(sst[1]); s.count = sst.count; s.uniqueCount = sst.uniqueCount; + sst = parsexmltag(sst[1]); s.Count = sst.count; s.Unique = sst.uniqueCount; } return s; } @@ -440,11 +447,7 @@ function parseWB(data) { wb.WBView.forEach(function(w){for(var z in WBViewDef) if(null==w[z]) w[z]=WBViewDef[z]; }); wb.Sheets.forEach(function(w){for(var z in SheetDef) if(null==w[z]) w[z]=SheetDef[z]; }); - switch(wb.WBProps.date1904) { - case '0': case 0: case 'false': case 'FALSE': _ssfopts.date1904=false;break; - case '1': case 1: case 'true': case 'TRUE': _ssfopts.date1904 = true; break; - default: throw "unrecognized date1904: " + wb.WBProps.date1904; - } + _ssfopts.date1904 = parsexmlbool(wb.WBProps.date1904, 'date1904'); return wb; } diff --git a/package.json b/package.json index 03f0db7..84280d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xlsx", - "version": "0.2.2", + "version": "0.2.3", "author": "Niggler", "description": "(one day) a full-featured XLSX parser and writer. For now, primitive parser", "keywords": [ diff --git a/xlsx.js b/xlsx.js index 29c06d9..02082d8 100644 --- a/xlsx.js +++ b/xlsx.js @@ -341,6 +341,13 @@ function parsexmltag(tag) { return z; } +function parsexmlbool(value, tag) { + switch(value) { + case '0': case 0: case 'false': case 'FALSE': return false; + case '1': case 1: case 'true': case 'TRUE': return true; + default: throw "bad boolean value " + value + " in "+(tag||"?"); + } +} var strs = {}; // shared strings var styles = {}; // shared styles @@ -462,7 +469,7 @@ function parseStrs(data) { s = sst[2].replace(//g,"").split(/<\/si>/).map(function(x) { var z = {}; var y=x.match(/<(.*)>([\s\S]*)<\/.*/); if(y) z[y[1].split(" ")[0]]=utf8read(unescapexml(y[2])); return z;}); - sst = parsexmltag(sst[1]); s.count = sst.count; s.uniqueCount = sst.uniqueCount; + sst = parsexmltag(sst[1]); s.Count = sst.count; s.Unique = sst.uniqueCount; } return s; } @@ -664,11 +671,7 @@ function parseWB(data) { wb.WBView.forEach(function(w){for(var z in WBViewDef) if(null==w[z]) w[z]=WBViewDef[z]; }); wb.Sheets.forEach(function(w){for(var z in SheetDef) if(null==w[z]) w[z]=SheetDef[z]; }); - switch(wb.WBProps.date1904) { - case '0': case 0: case 'false': case 'FALSE': _ssfopts.date1904=false;break; - case '1': case 1: case 'true': case 'TRUE': _ssfopts.date1904 = true; break; - default: throw "unrecognized date1904: " + wb.WBProps.date1904; - } + _ssfopts.date1904 = parsexmlbool(wb.WBProps.date1904, 'date1904'); return wb; }