version bump 0.5.9: strip leading # before 0

This commit is contained in:
SheetJS 2014-03-18 20:58:45 -07:00
parent 02285784a7
commit 0b3732c443
4 changed files with 15 additions and 7 deletions

@ -1,6 +1,6 @@
{
"name": "ssf",
"version": "0.5.8",
"version": "0.5.9",
"author": "SheetJS",
"description": "pure-JS library to format data using ECMA-376 spreadsheet Format Codes",
"keywords": [ "format", "sprintf", "spreadsheet" ],

7
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.8';
SSF.version = '0.5.9';
/* Options */
var opts_fmt = {};
function fixopts(o){for(var y in opts_fmt) if(o[y]===undefined) o[y]=opts_fmt[y];}
@ -242,9 +242,10 @@ var write_num = function(type, fmt, val) {
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); });
}
fmt = fmt.replace(/^#+0/, "0");
if((r = fmt.match(/^(0*)\.(#*)$/))) {
o = Math.round(val*Math.pow(10,r[2].length));
return String(o * Math.pow(10,-r[2].length)).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^([-]?\d*)$/,"$1.").replace(/^0\./,r[1].length?"0.":".");
o = Math.round(aval*Math.pow(10,r[2].length));
return sign + String(o / Math.pow(10,r[2].length)).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^([-]?\d*)$/,"$1.").replace(/^0\./,r[1].length?"0.":".");
}
if((r = fmt.match(/^#,##0([.]?)$/))) return sign + commaify(String(Math.round(aval)));
if((r = fmt.match(/^#,##0\.([#0]*0)$/))) {

12
ssf.md

@ -431,9 +431,15 @@ A few special general cases can be handled in a very dumb manner:
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); });
}
```
The next few simplifications ignore leading optional sigils (`#`):
```
fmt = fmt.replace(/^#+0/, "0");
if((r = fmt.match(/^(0*)\.(#*)$/))) {
o = Math.round(val*Math.pow(10,r[2].length));
return String(o * Math.pow(10,-r[2].length)).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^([-]?\d*)$/,"$1.").replace(/^0\./,r[1].length?"0.":".");
o = Math.round(aval*Math.pow(10,r[2].length));
return sign + String(o / Math.pow(10,r[2].length)).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^([-]?\d*)$/,"$1.").replace(/^0\./,r[1].length?"0.":".");
}
if((r = fmt.match(/^#,##0([.]?)$/))) return sign + commaify(String(Math.round(aval)));
if((r = fmt.match(/^#,##0\.([#0]*0)$/))) {
@ -996,7 +1002,7 @@ coveralls:
```json>package.json
{
"name": "ssf",
"version": "0.5.8",
"version": "0.5.9",
"author": "SheetJS",
"description": "pure-JS library to format data using ECMA-376 spreadsheet Format Codes",
"keywords": [ "format", "sprintf", "spreadsheet" ],

@ -19,6 +19,7 @@
["((;@", [1,"(("], [0,"(("], ["foo","foo"]],
["\\r", [1, "r"], [-1, "r"], [0, "r"], ["TODO","TODO"]],
["_($* #,##0_);_($* (#,##0);_($* \"-\"_);_(@_)", [1, " $1 "], [-1, " $(1)"], [0," $- "], ["TODO", " TODO "], ["",""]],
["#0.#", [0,"0."], [1,"1."], [12,"12."], [12.34, "12.3"], [-1.23, "-1.2"]],
["#,##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"]],