From e5fe3853350b300d5718bf94fb2a90bfdffb9dc7 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Tue, 28 Jan 2014 20:02:46 -0500 Subject: [PATCH] version bump 0.5.4: empty text is empty --- .travis.yml | 2 +- package.json | 2 +- ssf.js | 7 ++++--- ssf.md | 15 +++++++++------ test/oddities.json | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1575131..dc9e596 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,5 @@ before_install: - "npm install -g mocha" - "npm install blanket" - "npm install coveralls mocha-lcov-reporter" -after_success: +after_success: - "make coveralls" diff --git a/package.json b/package.json index 3a6509f..65f3c71 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ssf", - "version": "0.5.3", + "version": "0.5.4", "author": "SheetJS", "description": "pure-JS library to format data using ECMA-376 spreadsheet Format Codes", "keywords": [ "format", "sprintf", "spreadsheet" ], diff --git a/ssf.js b/ssf.js index f3a151c..34c770a 100644 --- a/ssf.js +++ b/ssf.js @@ -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.5.3'; +SSF.version = '0.5.4'; /* Options */ var opts_fmt = {}; function fixopts(o){for(var y in opts_fmt) if(o[y]===undefined) o[y]=opts_fmt[y];} @@ -235,11 +235,11 @@ var write_num = function(type, fmt, val) { } if(fmt.match(/^00+$/)) return (val<0?"-":"")+pad(Math.round(aval),fmt.length); if(fmt.match(/^[#?]+$/)) return String(Math.round(val)).replace(/^0$/,""); - if(r = fmt.match(/^#*0+\.(0+)/)) { + if((r = fmt.match(/^#*0+\.(0+)/))) { o = Math.round(val * Math.pow(10,r[1].length)); return 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); }); } - if(r = fmt.match(/^# ([?]+)([ ]?)\/([ ]?)([?]+)/)) { + if((r = fmt.match(/^# ([?]+)([ ]?)\/([ ]?)([?]+)/))) { var 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)); @@ -402,6 +402,7 @@ var format = function format(fmt,v,o) { var f = choose_fmt(fmt, v, o); if(f[1].toLowerCase() === "general") return general_fmt(v,o); if(v === true) v = "TRUE"; if(v === false) v = "FALSE"; + if(v === "" || typeof v === "undefined") return ""; return eval_fmt(f[1], v, o, f[0]); }; diff --git a/ssf.md b/ssf.md index b6f56bb..77aec3b 100644 --- a/ssf.md +++ b/ssf.md @@ -420,7 +420,7 @@ A few special general cases can be handled in a very dumb manner: ``` if(fmt.match(/^00+$/)) return (val<0?"-":"")+pad(Math.round(aval),fmt.length); if(fmt.match(/^[#?]+$/)) return String(Math.round(val)).replace(/^0$/,""); - if(r = fmt.match(/^#*0+\.(0+)/)) { + if((r = fmt.match(/^#*0+\.(0+)/))) { o = Math.round(val * Math.pow(10,r[1].length)); return 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); }); } @@ -429,7 +429,7 @@ A few special general cases can be handled in a very dumb manner: The frac helper function is used for fraction formats (defined below). ``` - if(r = fmt.match(/^# ([?]+)([ ]?)\/([ ]?)([?]+)/)) { + if((r = fmt.match(/^# ([?]+)([ ]?)\/([ ]?)([?]+)/))) { var 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)); @@ -576,7 +576,7 @@ the HH/hh jazz. TODO: investigate this further. out.push(q); lst = c; break; ``` -Conditional and color blocks should be handled at one point (TODO). The +Conditional and color blocks should be handled at one point (TODO). The pseudo-type `Z` is used to capture absolute time blocks: ``` @@ -770,7 +770,7 @@ function choose_fmt(fmt, v, o) { switch(fmt.length) { ``` -In the case of one format, if it contains an "@" then it is a text format. +In the case of one format, if it contains an "@" then it is a text format. There is a big TODO here regarding how to best handle this case. ``` @@ -813,7 +813,10 @@ The boolean TRUE and FALSE are formatted as if they are the uppercase text: if(v === true) v = "TRUE"; if(v === false) v = "FALSE"; ``` +Empty string should always emit empty, even if there are other characters: + ``` + if(v === "" || typeof v === "undefined") return ""; return eval_fmt(f[1], v, o, f[0]); }; @@ -950,7 +953,7 @@ coveralls: ```json>package.json { "name": "ssf", - "version": "0.5.3", + "version": "0.5.4", "author": "SheetJS", "description": "pure-JS library to format data using ECMA-376 spreadsheet Format Codes", "keywords": [ "format", "sprintf", "spreadsheet" ], @@ -994,7 +997,7 @@ before_install: - "npm install -g mocha" - "npm install blanket" - "npm install coveralls mocha-lcov-reporter" -after_success: +after_success: - "make coveralls" ``` diff --git a/test/oddities.json b/test/oddities.json index a862143..f2c8cce 100644 --- a/test/oddities.json +++ b/test/oddities.json @@ -18,7 +18,7 @@ ["r", [1], [-1], [0], ["TODO","TODO"]], ["((;@", [1], [-1], [0], ["TODO","TODO"]], ["\\r", [1, "r"], [-1, "r"], [0, "r"], ["TODO","TODO"]], - ["_($* #,##0_);_($* (#,##0);_($* \"-\"_);_(@_)", [1, " $1 "], [-1, " $(1)"], [0," $- "], ["TODO", " TODO "]], + ["_($* #,##0_);_($* (#,##0);_($* \"-\"_);_(@_)", [1, " $1 "], [-1, " $(1)"], [0," $- "], ["TODO", " TODO "], ["",""]], ["#,##0.0", [1,"1.0"], [-1,"-1.0"], [0,"0.0"], ["TODO","TODO"]], ["#,##0.00", [1,"1.00"], [-1,"-1.00"], [0,"0.00"], ["TODO","TODO"]], ["#,##0.000", [1,"1.000"], [-1,"-1.000"], [0,"0.000"], ["TODO","TODO"]],