Comparing version 0.5.9 to 0.5.10
{ | ||
"name": "ssf", | ||
"version": "0.5.9", | ||
"version": "0.5.10", | ||
"author": "SheetJS", | ||
@@ -5,0 +5,0 @@ "description": "pure-JS library to format data using ECMA-376 spreadsheet Format Codes", |
11
ssf.js
@@ -8,3 +8,3 @@ /* ssf.js (C) 2013-2014 SheetJS -- http://sheetjs.com */ | ||
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.9'; | ||
SSF.version = '0.5.10'; | ||
/* Options */ | ||
@@ -209,2 +209,4 @@ var opts_fmt = {}; | ||
if(mul !== 0) return write_num(type, fmt, val * Math.pow(10,2*mul)) + fill("%",mul); | ||
fmt = fmt.replace(/(\.0+)(,+)$/g,function($$,$1,$2) { mul=$2.length; return $1; }); | ||
if(mul !== 0) return write_num(type, fmt, val / Math.pow(10,3*mul)); | ||
if(fmt.indexOf("E") > -1) { | ||
@@ -243,7 +245,8 @@ var idx = fmt.indexOf("E") - fmt.indexOf(".") - 1; | ||
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); }); | ||
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); }); | ||
return fmt.match(/0\./) ? rr : rr.replace(/^0\./,"."); | ||
} | ||
fmt = fmt.replace(/^#+0/, "0"); | ||
fmt = fmt.replace(/^#+([0.])/, "$1"); | ||
if((r = fmt.match(/^(0*)\.(#*)$/))) { | ||
@@ -250,0 +253,0 @@ o = Math.round(aval*Math.pow(10,r[2].length)); |
17
ssf.md
@@ -369,2 +369,10 @@ # SSF | ||
Formats with multiple commas after the decimal point should be shifted by the | ||
appropiate multiple of 1000 (more magic): | ||
```js>tmp/60_number.js | ||
fmt = fmt.replace(/(\.0+)(,+)$/g,function($$,$1,$2) { mul=$2.length; return $1; }); | ||
if(mul !== 0) return write_num(type, fmt, val / Math.pow(10,3*mul)); | ||
``` | ||
For exponents, get the exponent and mantissa and format them separately: | ||
@@ -431,5 +439,6 @@ | ||
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); }); | ||
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); }); | ||
return fmt.match(/0\./) ? rr : rr.replace(/^0\./,"."); | ||
} | ||
@@ -441,3 +450,3 @@ ``` | ||
``` | ||
fmt = fmt.replace(/^#+0/, "0"); | ||
fmt = fmt.replace(/^#+([0.])/, "$1"); | ||
if((r = fmt.match(/^(0*)\.(#*)$/))) { | ||
@@ -1008,3 +1017,3 @@ o = Math.round(aval*Math.pow(10,r[2].length)); | ||
"name": "ssf", | ||
"version": "0.5.9", | ||
"version": "0.5.10", | ||
"author": "SheetJS", | ||
@@ -1011,0 +1020,0 @@ "description": "pure-JS library to format data using ECMA-376 spreadsheet Format Codes", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105659
22
1939
8