Comparing version 0.9.1 to 0.9.2
{ | ||
"name": "ssf", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"author": "SheetJS", | ||
@@ -5,0 +5,0 @@ "description": "Format data using ECMA-376 spreadsheet Format Codes", |
@@ -5,3 +5,3 @@ /* ssf.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||
var make_ssf = function make_ssf(SSF){ | ||
SSF.version = '0.9.1'; | ||
SSF.version = '0.9.2'; | ||
function _strrev(x/*:string*/)/*:string*/ { var o = "", i = x.length-1; while(i>=0) o += x.charAt(i--); return o; } | ||
@@ -274,8 +274,10 @@ function fill(c/*:string*/,l/*:number*/)/*:string*/ { var o = ""; while(o.length < l) o+=c; return o; } | ||
if(fmt.match(/^#+0.0E\+0$/)) { | ||
if(val == 0) return "0.0E+0"; | ||
else if(val < 0) return "-" + write_num_exp(fmt, -val); | ||
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E'); | ||
var ee = Math.floor(Math.log(Math.abs(val))*Math.LOG10E)%period; | ||
var ee = Math.floor(Math.log(val)*Math.LOG10E)%period; | ||
if(ee < 0) ee += period; | ||
o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period); | ||
if(o.indexOf("e") === -1) { | ||
var fakee = Math.floor(Math.log(Math.abs(val))*Math.LOG10E); | ||
var fakee = Math.floor(Math.log(val)*Math.LOG10E); | ||
if(o.indexOf(".") === -1) o = o.charAt(0) + "." + o.substr(1) + "E+" + (fakee - o.length+ee); | ||
@@ -358,3 +360,3 @@ else o += "E+" + (fakee - ee); | ||
} | ||
if((r = fmt.match(/^#,##0(\.?)$/))) return sign + commaify(pad0r(aval,0)); | ||
if((r = fmt.match(/^#{1,3},##0(\.?)$/))) return sign + commaify(pad0r(aval,0)); | ||
if((r = fmt.match(/^#,##0\.([#0]*0)$/))) { | ||
@@ -407,3 +409,8 @@ return val < 0 ? "-" + write_num_flt(type, fmt, -val) : commaify(""+(Math.floor(val) + carry(val, r[1].length))) + "." + pad0(dec(val, r[1].length),r[1].length); | ||
switch(fmt) { | ||
case "###,##0.00": return write_num_flt(type, "#,##0.00", val); | ||
case "###,###": | ||
case "##,###": | ||
case "#,###": var x = commaify(pad0r(aval,0)); return x !== "0" ? sign + x : ""; | ||
case "###,###.00": return write_num_flt(type, "###,##0.00",val).replace(/^0\./,"."); | ||
case "#,###.00": return write_num_flt(type, "#,##0.00",val).replace(/^0\./,"."); | ||
default: | ||
@@ -426,8 +433,10 @@ } | ||
if(fmt.match(/^#+0.0E\+0$/)) { | ||
if(val == 0) return "0.0E+0"; | ||
else if(val < 0) return "-" + write_num_exp2(fmt, -val); | ||
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E'); | ||
var ee = Math.floor(Math.log(Math.abs(val))*Math.LOG10E)%period; | ||
var ee = Math.floor(Math.log(val)*Math.LOG10E)%period; | ||
if(ee < 0) ee += period; | ||
o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period); | ||
if(!o.match(/[Ee]/)) { | ||
var fakee = Math.floor(Math.log(Math.abs(val))*Math.LOG10E); | ||
var fakee = Math.floor(Math.log(val)*Math.LOG10E); | ||
if(o.indexOf(".") === -1) o = o.charAt(0) + "." + o.substr(1) + "E+" + (fakee - o.length+ee); | ||
@@ -454,3 +463,3 @@ else o += "E+" + (fakee - ee); | ||
var o; | ||
var r, ri, ff, aval = Math.abs(val), sign = val < 0 ? "-" : ""; | ||
var r/*:?Array<string>*/, ri, ff, aval = Math.abs(val), sign = val < 0 ? "-" : ""; | ||
if(fmt.match(/^00+$/)) return sign + pad0(aval,fmt.length); | ||
@@ -475,3 +484,3 @@ if(fmt.match(/^[#?]+$/)) { | ||
} | ||
if((r = fmt.match(/^#,##0(\.?)$/))) return sign + commaify((""+aval)); | ||
if((r = fmt.match(/^#{1,3},##0(\.?)$/))) return sign + commaify((""+aval)); | ||
if((r = fmt.match(/^#,##0\.([#0]*0)$/))) { | ||
@@ -492,8 +501,8 @@ return val < 0 ? "-" + write_num_int(type, fmt, -val) : commaify((""+val)) + "." + fill('0',r[1].length); | ||
if((r = fmt.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/))) { | ||
ri = Math.min(r[4].length,7); | ||
ri = Math.min(/*::String(*/r[4]/*::)*/.length,7); | ||
ff = frac(aval, Math.pow(10,ri)-1, false); | ||
o = "" + sign; | ||
oa = write_num("n", r[1], ff[1]); | ||
oa = write_num("n", /*::String(*/r[1]/*::)*/, ff[1]); | ||
if(oa.charAt(oa.length-1) == " ") oa = oa.substr(0,oa.length-1) + "0"; | ||
o += oa + r[2] + "/" + r[3]; | ||
o += oa + /*::String(*/r[2]/*::)*/ + "/" + /*::String(*/r[3]/*::)*/; | ||
oa = rpad_(ff[2],ri); | ||
@@ -524,4 +533,8 @@ if(oa.length < r[4].length) oa = hashq(r[4].substr(r[4].length-oa.length)) + oa; | ||
switch(fmt) { | ||
case "###,###": | ||
case "##,###": | ||
case "#,###": var x = commaify(""+aval); return x !== "0" ? sign + x : ""; | ||
default: | ||
if(fmt.slice(-3) == ".00") return write_num_int(type, fmt.slice(0,-3), val) + ".00"; | ||
if(fmt.slice(-2) == ".0") return write_num_int(type, fmt.slice(0,-2), val) + ".0"; | ||
} | ||
@@ -622,3 +635,3 @@ throw new Error("unsupported format |" + fmt + "|"); | ||
o = c; while(++i<fmt.length && fmt.charAt(i).toLowerCase() === c) o+=c; | ||
if(c === 'm' && lst.toLowerCase() === 'h') c = 'M'; /* m = minute */ | ||
if(c === 'm' && lst.toLowerCase() === 'h') c = 'M'; | ||
if(c === 'h') c = hr; | ||
@@ -641,2 +654,3 @@ out[out.length] = {t:c, v:o}; lst = c; break; | ||
out[out.length] = {t:'Z', v:o.toLowerCase()}; | ||
lst = o.charAt(1); | ||
} else if(o.indexOf("$") > -1) { | ||
@@ -655,3 +669,3 @@ o = (o.match(/\$([^-\[\]]*)/)||[])[1]||"$"; | ||
case '0': case '#': | ||
o = c; while(++i < fmt.length && "0#?.,E+-%".indexOf(c=fmt.charAt(i)) > -1 || c=='\\' && fmt.charAt(i+1) == "-" && "0#".indexOf(fmt.charAt(i+2))>-1) o += c; | ||
o = c; while(++i < fmt.length && "0#?.,E+-%".indexOf(c=fmt.charAt(i)) > -1 || c=='\\' && fmt.charAt(i+1) == "-" && i < fmt.length - 2 && "0#".indexOf(fmt.charAt(i+2))>-1) o += c; | ||
out[out.length] = {t:'n', v:o}; break; | ||
@@ -720,3 +734,3 @@ case '?': | ||
out[i].t === '(' && (c === ' ' || c === 'n' || c === ')') || | ||
c === 't' && (out[jj].v === '/' || '$€'.indexOf(out[jj].v) > -1 || out[jj].v === ' ' && out[jj+1] != null && out[jj+1].t == '?') | ||
c === 't' && (out[jj].v === '/' || out[jj].v === ' ' && out[jj+1] != null && out[jj+1].t == '?') | ||
)) { | ||
@@ -835,3 +849,2 @@ out[i].v += out[jj].v; | ||
if(o == null) o = {}; | ||
//fixopts(o != null ? o : (o=[])); | ||
var sfmt = ""; | ||
@@ -838,0 +851,0 @@ switch(typeof fmt) { |
35
ssf.js
@@ -5,3 +5,3 @@ /* ssf.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||
var make_ssf = function make_ssf(SSF){ | ||
SSF.version = '0.9.1'; | ||
SSF.version = '0.9.2'; | ||
function _strrev(x) { var o = "", i = x.length-1; while(i>=0) o += x.charAt(i--); return o; } | ||
@@ -273,8 +273,10 @@ function fill(c,l) { var o = ""; while(o.length < l) o+=c; return o; } | ||
if(fmt.match(/^#+0.0E\+0$/)) { | ||
if(val == 0) return "0.0E+0"; | ||
else if(val < 0) return "-" + write_num_exp(fmt, -val); | ||
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E'); | ||
var ee = Math.floor(Math.log(Math.abs(val))*Math.LOG10E)%period; | ||
var ee = Math.floor(Math.log(val)*Math.LOG10E)%period; | ||
if(ee < 0) ee += period; | ||
o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period); | ||
if(o.indexOf("e") === -1) { | ||
var fakee = Math.floor(Math.log(Math.abs(val))*Math.LOG10E); | ||
var fakee = Math.floor(Math.log(val)*Math.LOG10E); | ||
if(o.indexOf(".") === -1) o = o.charAt(0) + "." + o.substr(1) + "E+" + (fakee - o.length+ee); | ||
@@ -357,3 +359,3 @@ else o += "E+" + (fakee - ee); | ||
} | ||
if((r = fmt.match(/^#,##0(\.?)$/))) return sign + commaify(pad0r(aval,0)); | ||
if((r = fmt.match(/^#{1,3},##0(\.?)$/))) return sign + commaify(pad0r(aval,0)); | ||
if((r = fmt.match(/^#,##0\.([#0]*0)$/))) { | ||
@@ -406,3 +408,8 @@ return val < 0 ? "-" + write_num_flt(type, fmt, -val) : commaify(""+(Math.floor(val) + carry(val, r[1].length))) + "." + pad0(dec(val, r[1].length),r[1].length); | ||
switch(fmt) { | ||
case "###,##0.00": return write_num_flt(type, "#,##0.00", val); | ||
case "###,###": | ||
case "##,###": | ||
case "#,###": var x = commaify(pad0r(aval,0)); return x !== "0" ? sign + x : ""; | ||
case "###,###.00": return write_num_flt(type, "###,##0.00",val).replace(/^0\./,"."); | ||
case "#,###.00": return write_num_flt(type, "#,##0.00",val).replace(/^0\./,"."); | ||
default: | ||
@@ -425,8 +432,10 @@ } | ||
if(fmt.match(/^#+0.0E\+0$/)) { | ||
if(val == 0) return "0.0E+0"; | ||
else if(val < 0) return "-" + write_num_exp2(fmt, -val); | ||
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E'); | ||
var ee = Math.floor(Math.log(Math.abs(val))*Math.LOG10E)%period; | ||
var ee = Math.floor(Math.log(val)*Math.LOG10E)%period; | ||
if(ee < 0) ee += period; | ||
o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period); | ||
if(!o.match(/[Ee]/)) { | ||
var fakee = Math.floor(Math.log(Math.abs(val))*Math.LOG10E); | ||
var fakee = Math.floor(Math.log(val)*Math.LOG10E); | ||
if(o.indexOf(".") === -1) o = o.charAt(0) + "." + o.substr(1) + "E+" + (fakee - o.length+ee); | ||
@@ -471,3 +480,3 @@ else o += "E+" + (fakee - ee); | ||
} | ||
if((r = fmt.match(/^#,##0(\.?)$/))) return sign + commaify((""+aval)); | ||
if((r = fmt.match(/^#{1,3},##0(\.?)$/))) return sign + commaify((""+aval)); | ||
if((r = fmt.match(/^#,##0\.([#0]*0)$/))) { | ||
@@ -519,4 +528,8 @@ return val < 0 ? "-" + write_num_int(type, fmt, -val) : commaify((""+val)) + "." + fill('0',r[1].length); | ||
switch(fmt) { | ||
case "###,###": | ||
case "##,###": | ||
case "#,###": var x = commaify(""+aval); return x !== "0" ? sign + x : ""; | ||
default: | ||
if(fmt.slice(-3) == ".00") return write_num_int(type, fmt.slice(0,-3), val) + ".00"; | ||
if(fmt.slice(-2) == ".0") return write_num_int(type, fmt.slice(0,-2), val) + ".0"; | ||
} | ||
@@ -617,3 +630,3 @@ throw new Error("unsupported format |" + fmt + "|"); | ||
o = c; while(++i<fmt.length && fmt.charAt(i).toLowerCase() === c) o+=c; | ||
if(c === 'm' && lst.toLowerCase() === 'h') c = 'M'; /* m = minute */ | ||
if(c === 'm' && lst.toLowerCase() === 'h') c = 'M'; | ||
if(c === 'h') c = hr; | ||
@@ -636,2 +649,3 @@ out[out.length] = {t:c, v:o}; lst = c; break; | ||
out[out.length] = {t:'Z', v:o.toLowerCase()}; | ||
lst = o.charAt(1); | ||
} else if(o.indexOf("$") > -1) { | ||
@@ -650,3 +664,3 @@ o = (o.match(/\$([^-\[\]]*)/)||[])[1]||"$"; | ||
case '0': case '#': | ||
o = c; while(++i < fmt.length && "0#?.,E+-%".indexOf(c=fmt.charAt(i)) > -1 || c=='\\' && fmt.charAt(i+1) == "-" && "0#".indexOf(fmt.charAt(i+2))>-1) o += c; | ||
o = c; while(++i < fmt.length && "0#?.,E+-%".indexOf(c=fmt.charAt(i)) > -1 || c=='\\' && fmt.charAt(i+1) == "-" && i < fmt.length - 2 && "0#".indexOf(fmt.charAt(i+2))>-1) o += c; | ||
out[out.length] = {t:'n', v:o}; break; | ||
@@ -712,3 +726,3 @@ case '?': | ||
out[i].t === '(' && (c === ' ' || c === 'n' || c === ')') || | ||
c === 't' && (out[jj].v === '/' || '$€'.indexOf(out[jj].v) > -1 || out[jj].v === ' ' && out[jj+1] != null && out[jj+1].t == '?') | ||
c === 't' && (out[jj].v === '/' || out[jj].v === ' ' && out[jj+1] != null && out[jj+1].t == '?') | ||
)) { | ||
@@ -827,3 +841,2 @@ out[i].v += out[jj].v; | ||
if(o == null) o = {}; | ||
//fixopts(o != null ? o : (o=[])); | ||
var sfmt = ""; | ||
@@ -830,0 +843,0 @@ switch(typeof fmt) { |
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
124751
1721