Comparing version 0.11.1 to 0.11.2
{ | ||
"name": "ssf", | ||
"version": "0.11.1", | ||
"version": "0.11.2", | ||
"author": "sheetjs", | ||
@@ -11,5 +11,2 @@ "description": "Format data using ECMA-376 spreadsheet Format Codes", | ||
], | ||
"bin": { | ||
"ssf": "./bin/ssf.njs" | ||
}, | ||
"main": "./ssf", | ||
@@ -16,0 +13,0 @@ "types": "types", |
@@ -91,2 +91,7 @@ # [SheetJS SSF](http://sheetjs.com) | ||
## Related Packages | ||
[`ssf-cli`](https://www.npmjs.com/package/ssf-cli) is a simple NodeJS command | ||
line tool for formatting numbers. | ||
## License | ||
@@ -93,0 +98,0 @@ |
@@ -7,3 +7,3 @@ /* ssf.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||
var make_ssf = function make_ssf(SSF/*:SSFModule*/){ | ||
SSF.version = '0.11.1'; | ||
SSF.version = '0.11.2'; | ||
function _strrev(x/*:string*/)/*:string*/ { var o = "", i = x.length-1; while(i>=0) o += x.charAt(i--); return o; } | ||
@@ -194,33 +194,60 @@ function fill(c/*:string*/,l/*:number*/)/*:string*/ { var o = ""; while(o.length < l) o+=c; return o; } | ||
} | ||
/* The longest 32-bit integer text is "-4294967296", exactly 11 chars */ | ||
function general_fmt_int(v/*:number*/)/*:string*/ { return v.toString(10); } | ||
SSF._general_int = general_fmt_int; | ||
/* ECMA-376 18.8.30 numFmt*/ | ||
/* Note: `toPrecision` uses standard form when prec > E and E >= -6 */ | ||
var general_fmt_num = (function make_general_fmt_num() { | ||
var gnr1 = /\.(\d*[1-9])0+$/, gnr2 = /\.0*$/, gnr4 = /\.(\d*[1-9])0+/, gnr5 = /\.0*[Ee]/, gnr6 = /(E[+-])(\d)$/; | ||
function gfn2(v) { | ||
var w = (v<0?12:11); | ||
var o = gfn5(v.toFixed(12)); if(o.length <= w) return o; | ||
o = v.toPrecision(10); if(o.length <= w) return o; | ||
return v.toExponential(5); | ||
} | ||
function gfn3(v) { | ||
var o = v.toFixed(11).replace(gnr1,".$1"); | ||
if(o.length > (v<0?12:11)) o = v.toPrecision(6); | ||
return o; | ||
} | ||
function gfn4(o) { | ||
for(var i = 0; i != o.length; ++i) if((o.charCodeAt(i) | 0x20) === 101) return o.replace(gnr4,".$1").replace(gnr5,"E").replace("e","E").replace(gnr6,"$10$2"); | ||
return o; | ||
} | ||
function gfn5(o) { | ||
return o.indexOf(".") > -1 ? o.replace(gnr2,"").replace(gnr1,".$1") : o; | ||
} | ||
return function general_fmt_num(v/*:number*/)/*:string*/ { | ||
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o; | ||
if(V >= -4 && V <= -1) o = v.toPrecision(10+V); | ||
else if(Math.abs(V) <= 9) o = gfn2(v); | ||
else if(V === 10) o = v.toFixed(10).substr(0,12); | ||
else o = gfn3(v); | ||
return gfn5(gfn4(o)); | ||
};})(); | ||
var trailing_zeroes_and_decimal = /(?:\.0*|(\.\d*[1-9])0+)$/; | ||
function strip_decimal(o/*:string*/)/*:string*/ { | ||
return (o.indexOf(".") == -1) ? o : o.replace(trailing_zeroes_and_decimal, "$1"); | ||
} | ||
/* General Exponential always shows 2 digits exp and trims the mantissa */ | ||
var mantissa_zeroes_and_decimal = /(?:\.0*|(\.\d*[1-9])0+)[Ee]/; | ||
var exp_with_single_digit = /(E[+-])(\d)$/; | ||
function normalize_exp(o/*:string*/)/*:string*/ { | ||
if(o.indexOf("E") == -1) return o; | ||
return o.replace(mantissa_zeroes_and_decimal,"$1E").replace(exp_with_single_digit,"$10$2"); | ||
} | ||
/* exponent >= -9 and <= 9 */ | ||
function small_exp(v/*:number*/)/*:string*/ { | ||
var w = (v<0?12:11); | ||
var o = strip_decimal(v.toFixed(12)); if(o.length <= w) return o; | ||
o = v.toPrecision(10); if(o.length <= w) return o; | ||
return v.toExponential(5); | ||
} | ||
/* exponent >= 11 or <= -10 likely exponential */ | ||
function large_exp(v/*:number*/)/*:string*/ { | ||
var o = strip_decimal(v.toFixed(11)); | ||
return (o.length > (v<0?12:11) || o === "0" || o === "-0") ? v.toPrecision(6) : o; | ||
} | ||
function general_fmt_num_base(v/*:number*/)/*:string*/ { | ||
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o; | ||
if(V >= -4 && V <= -1) o = v.toPrecision(10+V); | ||
else if(Math.abs(V) <= 9) o = small_exp(v); | ||
else if(V === 10) o = v.toFixed(10).substr(0,12); | ||
else o = large_exp(v); | ||
return strip_decimal(normalize_exp(o.toUpperCase())); | ||
} | ||
return general_fmt_num_base; | ||
})(); | ||
SSF._general_num = general_fmt_num; | ||
/* | ||
"General" rules: | ||
- text is passed through ("@") | ||
- booleans are rendered as TRUE/FALSE | ||
- "up to 11 characters" displayed for numbers | ||
- Default date format (code 14) used for Dates | ||
TODO: technically the display depends on the width of the cell | ||
*/ | ||
function general_fmt(v/*:any*/, opts/*:any*/) { | ||
@@ -307,5 +334,6 @@ switch(typeof v) { | ||
case 101: /* 'e' era */ | ||
out = y; outl = 1; | ||
out = y; outl = 1; break; | ||
} | ||
if(outl > 0) return pad0(out, outl); else return ""; | ||
var outstr = outl > 0 ? pad0(out, outl) : ""; | ||
return outstr; | ||
} | ||
@@ -381,6 +409,5 @@ /*jshint +W086 */ | ||
function dec(val/*:number*/, d/*:number*/)/*:number*/ { | ||
if (d < ('' + Math.round((val-Math.floor(val))*Math.pow(10,d))).length) { | ||
return 0; | ||
} | ||
return Math.round((val-Math.floor(val))*Math.pow(10,d)); | ||
var _frac = val - Math.floor(val), dd = Math.pow(10,d); | ||
if (d < ('' + Math.round(_frac * dd)).length) return 0; | ||
return Math.round(_frac * dd); | ||
} | ||
@@ -387,0 +414,0 @@ function carry(val/*:number*/, d/*:number*/)/*:number*/ { |
95
ssf.js
@@ -6,3 +6,3 @@ /* ssf.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||
var make_ssf = function make_ssf(SSF){ | ||
SSF.version = '0.11.1'; | ||
SSF.version = '0.11.2'; | ||
function _strrev(x) { var o = "", i = x.length-1; while(i>=0) o += x.charAt(i--); return o; } | ||
@@ -190,33 +190,60 @@ function fill(c,l) { var o = ""; while(o.length < l) o+=c; return o; } | ||
} | ||
/* The longest 32-bit integer text is "-4294967296", exactly 11 chars */ | ||
function general_fmt_int(v) { return v.toString(10); } | ||
SSF._general_int = general_fmt_int; | ||
/* ECMA-376 18.8.30 numFmt*/ | ||
/* Note: `toPrecision` uses standard form when prec > E and E >= -6 */ | ||
var general_fmt_num = (function make_general_fmt_num() { | ||
var gnr1 = /\.(\d*[1-9])0+$/, gnr2 = /\.0*$/, gnr4 = /\.(\d*[1-9])0+/, gnr5 = /\.0*[Ee]/, gnr6 = /(E[+-])(\d)$/; | ||
function gfn2(v) { | ||
var w = (v<0?12:11); | ||
var o = gfn5(v.toFixed(12)); if(o.length <= w) return o; | ||
o = v.toPrecision(10); if(o.length <= w) return o; | ||
return v.toExponential(5); | ||
} | ||
function gfn3(v) { | ||
var o = v.toFixed(11).replace(gnr1,".$1"); | ||
if(o.length > (v<0?12:11)) o = v.toPrecision(6); | ||
return o; | ||
} | ||
function gfn4(o) { | ||
for(var i = 0; i != o.length; ++i) if((o.charCodeAt(i) | 0x20) === 101) return o.replace(gnr4,".$1").replace(gnr5,"E").replace("e","E").replace(gnr6,"$10$2"); | ||
return o; | ||
} | ||
function gfn5(o) { | ||
return o.indexOf(".") > -1 ? o.replace(gnr2,"").replace(gnr1,".$1") : o; | ||
} | ||
return function general_fmt_num(v) { | ||
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o; | ||
if(V >= -4 && V <= -1) o = v.toPrecision(10+V); | ||
else if(Math.abs(V) <= 9) o = gfn2(v); | ||
else if(V === 10) o = v.toFixed(10).substr(0,12); | ||
else o = gfn3(v); | ||
return gfn5(gfn4(o)); | ||
};})(); | ||
var trailing_zeroes_and_decimal = /(?:\.0*|(\.\d*[1-9])0+)$/; | ||
function strip_decimal(o) { | ||
return (o.indexOf(".") == -1) ? o : o.replace(trailing_zeroes_and_decimal, "$1"); | ||
} | ||
/* General Exponential always shows 2 digits exp and trims the mantissa */ | ||
var mantissa_zeroes_and_decimal = /(?:\.0*|(\.\d*[1-9])0+)[Ee]/; | ||
var exp_with_single_digit = /(E[+-])(\d)$/; | ||
function normalize_exp(o) { | ||
if(o.indexOf("E") == -1) return o; | ||
return o.replace(mantissa_zeroes_and_decimal,"$1E").replace(exp_with_single_digit,"$10$2"); | ||
} | ||
/* exponent >= -9 and <= 9 */ | ||
function small_exp(v) { | ||
var w = (v<0?12:11); | ||
var o = strip_decimal(v.toFixed(12)); if(o.length <= w) return o; | ||
o = v.toPrecision(10); if(o.length <= w) return o; | ||
return v.toExponential(5); | ||
} | ||
/* exponent >= 11 or <= -10 likely exponential */ | ||
function large_exp(v) { | ||
var o = strip_decimal(v.toFixed(11)); | ||
return (o.length > (v<0?12:11) || o === "0" || o === "-0") ? v.toPrecision(6) : o; | ||
} | ||
function general_fmt_num_base(v) { | ||
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o; | ||
if(V >= -4 && V <= -1) o = v.toPrecision(10+V); | ||
else if(Math.abs(V) <= 9) o = small_exp(v); | ||
else if(V === 10) o = v.toFixed(10).substr(0,12); | ||
else o = large_exp(v); | ||
return strip_decimal(normalize_exp(o.toUpperCase())); | ||
} | ||
return general_fmt_num_base; | ||
})(); | ||
SSF._general_num = general_fmt_num; | ||
/* | ||
"General" rules: | ||
- text is passed through ("@") | ||
- booleans are rendered as TRUE/FALSE | ||
- "up to 11 characters" displayed for numbers | ||
- Default date format (code 14) used for Dates | ||
TODO: technically the display depends on the width of the cell | ||
*/ | ||
function general_fmt(v, opts) { | ||
@@ -302,5 +329,6 @@ switch(typeof v) { | ||
case 101: /* 'e' era */ | ||
out = y; outl = 1; | ||
out = y; outl = 1; break; | ||
} | ||
if(outl > 0) return pad0(out, outl); else return ""; | ||
var outstr = outl > 0 ? pad0(out, outl) : ""; | ||
return outstr; | ||
} | ||
@@ -376,6 +404,5 @@ /*jshint +W086 */ | ||
function dec(val, d) { | ||
if (d < ('' + Math.round((val-Math.floor(val))*Math.pow(10,d))).length) { | ||
return 0; | ||
} | ||
return Math.round((val-Math.floor(val))*Math.pow(10,d)); | ||
var _frac = val - Math.floor(val), dd = Math.pow(10,d); | ||
if (d < ('' + Math.round(_frac * dd)).length) return 0; | ||
return Math.round(_frac * dd); | ||
} | ||
@@ -382,0 +409,0 @@ function carry(val, d) { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
120
0
97727
7
1957
1