Comparing version 0.5.5 to 0.5.6
{ | ||
"name": "ssf", | ||
"version": "0.5.5", | ||
"version": "0.5.6", | ||
"author": "SheetJS", | ||
@@ -5,0 +5,0 @@ "description": "pure-JS library to format data using ECMA-376 spreadsheet Format Codes", |
17
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.5'; | ||
SSF.version = '0.5.6'; | ||
/* Options */ | ||
@@ -216,4 +216,5 @@ var opts_fmt = {}; | ||
if(fmt == '##0.0E+0') { | ||
var period = fmt.length - 5; | ||
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E'); | ||
var ee = (Number(val.toExponential(0).substr(2+(val<0))))%period; | ||
if(ee < 0) ee += period; | ||
o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period); | ||
@@ -223,3 +224,8 @@ if(!o.match(/[Ee]/)) { | ||
if(o.indexOf(".") === -1) o = o[0] + "." + o.substr(1) + "E+" + (fakee - o.length+ee); | ||
else throw "missing E |" + o; | ||
else o += "E+" + (fakee - ee); | ||
while(o.substr(0,2) === "0.") { | ||
o = o[0] + o.substr(2,period) + "." + o.substr(2+period); | ||
o = o.replace(/^0+([1-9])/,"$1").replace(/^0+\./,"0."); | ||
} | ||
o = o.replace(/\+-/,"-"); | ||
} | ||
@@ -239,2 +245,3 @@ o = o.replace(/^([+-]?)([0-9]*)\.([0-9]*)[Ee]/,function($$,$1,$2,$3) { return $1 + $2 + $3.substr(0,(period+ee)%period) + "." + $3.substr(ee) + "E"; }); | ||
} | ||
if(fmt.match(/^#+0+$/)) fmt = fmt.replace(/#/g,""); | ||
if(fmt.match(/^00+$/)) return (val<0?"-":"")+pad(Math.round(aval),fmt.length); | ||
@@ -350,3 +357,3 @@ if(fmt.match(/^[#?]+$/)) return String(Math.round(val)).replace(/^0$/,""); | ||
default: | ||
if(",$-+/():!^&'~{}<>=".indexOf(c) === -1) | ||
if(",$-+/():!^&'~{}<>=€".indexOf(c) === -1) | ||
throw 'unrecognized character ' + fmt[i] + ' in ' + fmt; | ||
@@ -375,3 +382,3 @@ out.push({t:'t', v:c}); ++i; break; | ||
var jj = i+1; | ||
while(out[jj] && ("?D".indexOf(out[jj].t) > -1 || (" t".indexOf(out[jj].t) > -1 && "?t".indexOf((out[jj+1]||{}).t)>-1 && (out[jj+1].t == '?' || out[jj+1].v == '/')) || out[i].t == '(' && (out[jj].t == ')' || out[jj].t == 'n') || out[jj].t == 't' && (out[jj].v == '/' || out[jj].v == '$' || (out[jj].v == ' ' && (out[jj+1]||{}).t == '?')))) { | ||
while(out[jj] && ("?D".indexOf(out[jj].t) > -1 || (" t".indexOf(out[jj].t) > -1 && "?t".indexOf((out[jj+1]||{}).t)>-1 && (out[jj+1].t == '?' || out[jj+1].v == '/')) || out[i].t == '(' && (out[jj].t == ')' || out[jj].t == 'n') || out[jj].t == 't' && (out[jj].v == '/' || '$€'.indexOf(out[jj].v) > -1 || (out[jj].v == ' ' && (out[jj+1]||{}).t == '?')))) { | ||
out[i].v += out[jj].v; | ||
@@ -378,0 +385,0 @@ delete out[jj]; ++jj; |
17
ssf.md
@@ -380,4 +380,5 @@ # SSF | ||
if(fmt == '##0.0E+0') { | ||
var period = fmt.length - 5; | ||
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E'); | ||
var ee = (Number(val.toExponential(0).substr(2+(val<0))))%period; | ||
if(ee < 0) ee += period; | ||
o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period); | ||
@@ -392,3 +393,8 @@ if(!o.match(/[Ee]/)) { | ||
if(o.indexOf(".") === -1) o = o[0] + "." + o.substr(1) + "E+" + (fakee - o.length+ee); | ||
else throw "missing E |" + o; | ||
else o += "E+" + (fakee - ee); | ||
while(o.substr(0,2) === "0.") { | ||
o = o[0] + o.substr(2,period) + "." + o.substr(2+period); | ||
o = o.replace(/^0+([1-9])/,"$1").replace(/^0+\./,"0."); | ||
} | ||
o = o.replace(/\+-/,"-"); | ||
} | ||
@@ -423,2 +429,3 @@ o = o.replace(/^([+-]?)([0-9]*)\.([0-9]*)[Ee]/,function($$,$1,$2,$3) { return $1 + $2 + $3.substr(0,(period+ee)%period) + "." + $3.substr(ee) + "E"; }); | ||
``` | ||
if(fmt.match(/^#+0+$/)) fmt = fmt.replace(/#/g,""); | ||
if(fmt.match(/^00+$/)) return (val<0?"-":"")+pad(Math.round(aval),fmt.length); | ||
@@ -644,3 +651,3 @@ if(fmt.match(/^[#?]+$/)) return String(Math.round(val)).replace(/^0$/,""); | ||
default: | ||
if(",$-+/():!^&'~{}<>=".indexOf(c) === -1) | ||
if(",$-+/():!^&'~{}<>=€".indexOf(c) === -1) | ||
throw 'unrecognized character ' + fmt[i] + ' in ' + fmt; | ||
@@ -669,3 +676,3 @@ out.push({t:'t', v:c}); ++i; break; | ||
var jj = i+1; | ||
while(out[jj] && ("?D".indexOf(out[jj].t) > -1 || (" t".indexOf(out[jj].t) > -1 && "?t".indexOf((out[jj+1]||{}).t)>-1 && (out[jj+1].t == '?' || out[jj+1].v == '/')) || out[i].t == '(' && (out[jj].t == ')' || out[jj].t == 'n') || out[jj].t == 't' && (out[jj].v == '/' || out[jj].v == '$' || (out[jj].v == ' ' && (out[jj+1]||{}).t == '?')))) { | ||
while(out[jj] && ("?D".indexOf(out[jj].t) > -1 || (" t".indexOf(out[jj].t) > -1 && "?t".indexOf((out[jj+1]||{}).t)>-1 && (out[jj+1].t == '?' || out[jj+1].v == '/')) || out[i].t == '(' && (out[jj].t == ')' || out[jj].t == 'n') || out[jj].t == 't' && (out[jj].v == '/' || '$€'.indexOf(out[jj].v) > -1 || (out[jj].v == ' ' && (out[jj+1]||{}).t == '?')))) { | ||
out[i].v += out[jj].v; | ||
@@ -968,3 +975,3 @@ delete out[jj]; ++jj; | ||
"name": "ssf", | ||
"version": "0.5.5", | ||
"version": "0.5.6", | ||
"author": "SheetJS", | ||
@@ -971,0 +978,0 @@ "description": "pure-JS library to format data using ECMA-376 spreadsheet Format Codes", |
[ | ||
[1234567890000, [ | ||
[0, "1.23457E+12", true], | ||
[0, "1.23457E+12"], | ||
[1, "1234567890000"], | ||
@@ -30,3 +30,3 @@ [2, "1234567890000.00"], | ||
[48, "1.2E+12"], | ||
[49, "1.23457E+12", true] | ||
[49, "1.23457E+12"] | ||
]], | ||
@@ -61,4 +61,4 @@ | ||
[47, ""], | ||
[48, "123.5E+9", true], | ||
[49, "1.23457E+11", true] | ||
[48, "123.5E+9"], | ||
[49, "1.23457E+11"] | ||
]], | ||
@@ -341,3 +341,3 @@ | ||
[47, "5746.6"], | ||
[48, "123.5E+0", true], | ||
[48, "123.5E+0"], | ||
[49, "123.456789"] | ||
@@ -373,3 +373,3 @@ ]], | ||
[47, "1746.7"], | ||
[48, "12.3E+0", true], | ||
[48, "12.3E+0"], | ||
[49, "12.3456789"] | ||
@@ -405,3 +405,3 @@ ]], | ||
[47, "3746.7"], | ||
[48, "1.2E+0", true], | ||
[48, "1.2E+0"], | ||
[49, "1.23456789"] | ||
@@ -437,4 +437,4 @@ ]], | ||
[47, "5746.7"], | ||
[48, "123.5E-3", true], | ||
[49, "0.123456789", true] | ||
[48, "123.5E-3"], | ||
[49, "0.123456789"] | ||
]], | ||
@@ -469,4 +469,4 @@ | ||
[47, "1746.7"], | ||
[48, "12.3E-3", true], | ||
[49, "0.012345679", true] | ||
[48, "12.3E-3"], | ||
[49, "0.012345679"] | ||
]], | ||
@@ -501,4 +501,4 @@ | ||
[47, "0146.7"], | ||
[48, "1.2E-3", true], | ||
[49, "0.001234568", true] | ||
[48, "1.2E-3"], | ||
[49, "0.001234568"] | ||
]], | ||
@@ -533,4 +533,4 @@ | ||
[47, "0010.7"], | ||
[48, "123.5E-6", true], | ||
[49, "0.000123457", true] | ||
[48, "123.5E-6"], | ||
[49, "0.000123457"] | ||
]], | ||
@@ -565,4 +565,4 @@ | ||
[47, "0001.1"], | ||
[48, "12.3E-6", true], | ||
[49, "1.23457E-05", true] | ||
[48, "12.3E-6"], | ||
[49, "1.23457E-05"] | ||
]], | ||
@@ -597,4 +597,4 @@ | ||
[47, "0000.1"], | ||
[48, "1.2E-6", true], | ||
[49, "1.23457E-06", true] | ||
[48, "1.2E-6"], | ||
[49, "1.23457E-06"] | ||
]], | ||
@@ -629,4 +629,4 @@ | ||
[47, "0000.0"], | ||
[48, "123.5E-9", true], | ||
[49, "1.23457E-07", true] | ||
[48, "123.5E-9"], | ||
[49, "1.23457E-07"] | ||
]], | ||
@@ -661,4 +661,4 @@ | ||
[47, "0000.0"], | ||
[48, "12.3E-9", true], | ||
[49, "1.23457E-08", true] | ||
[48, "12.3E-9"], | ||
[49, "1.23457E-08"] | ||
]], | ||
@@ -693,4 +693,4 @@ | ||
[47, "0000.0"], | ||
[48, "1.2E-9", true], | ||
[49, "1.23457E-09", true] | ||
[48, "1.2E-9"], | ||
[49, "1.23457E-09"] | ||
]], | ||
@@ -725,4 +725,4 @@ | ||
[47, "0000.0"], | ||
[48, "123.5E-12", true], | ||
[49, "1.23457E-10", true] | ||
[48, "123.5E-12"], | ||
[49, "1.23457E-10"] | ||
]], | ||
@@ -729,0 +729,0 @@ |
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
105124
21
1911