Comparing version 0.5.6 to 0.5.7
{ | ||
"name": "ssf", | ||
"version": "0.5.6", | ||
"version": "0.5.7", | ||
"author": "SheetJS", | ||
@@ -5,0 +5,0 @@ "description": "pure-JS library to format data using ECMA-376 spreadsheet Format Codes", |
22
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.6'; | ||
SSF.version = '0.5.7'; | ||
/* Options */ | ||
@@ -150,4 +150,3 @@ var opts_fmt = {}; | ||
case 'y': case 'yy': return pad(val.y % 100,2); | ||
case 'yyy': case 'yyyy': return pad(val.y % 10000,4); | ||
default: throw 'bad year format: ' + fmt; | ||
default: return pad(val.y % 10000,4); | ||
} | ||
@@ -158,5 +157,4 @@ case 'm': switch(fmt) { /* month */ | ||
case 'mmm': return months[val.m-1][1]; | ||
case 'mmmm': return months[val.m-1][2]; | ||
case 'mmmmm': return months[val.m-1][0]; | ||
default: throw 'bad month format: ' + fmt; | ||
default: return months[val.m-1][2]; | ||
} | ||
@@ -167,4 +165,3 @@ case 'd': switch(fmt) { /* day */ | ||
case 'ddd': return days[val.q][0]; | ||
case 'dddd': return days[val.q][1]; | ||
default: throw 'bad day format: ' + fmt; | ||
default: return days[val.q][1]; | ||
} | ||
@@ -202,3 +199,2 @@ case 'h': switch(fmt) { /* 12-hour */ | ||
case 'e': { return val.y; } break; | ||
default: throw 'bad format type ' + type + ' in ' + fmt; | ||
} | ||
@@ -219,3 +215,3 @@ }; | ||
var idx = fmt.indexOf("E") - fmt.indexOf(".") - 1; | ||
if(fmt == '##0.0E+0') { | ||
if(fmt.match(/^#+0.0E\+0$/)) { | ||
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E'); | ||
@@ -338,3 +334,4 @@ var ee = (Number(val.toExponential(0).substr(2+(val<0))))%period; | ||
o = c; | ||
while(fmt[i++] !== ']') o += fmt[i]; | ||
while(fmt[i++] !== ']' && i < fmt.length) o += fmt[i]; | ||
if(o.substr(-1) !== ']') throw 'unterminated "[" block: |' + o + '|'; | ||
if(o.match(/\[[HhMmSs]*\]/)) { | ||
@@ -378,4 +375,4 @@ if(!dt) dt = parse_date_code(v, opts); | ||
switch(out[i].t) { | ||
case 't': case 'T': case ' ': break; | ||
case 'd': case 'm': case 'y': case 'h': case 'H': case 'M': case 's': case 'A': case 'e': case 'Z': | ||
case 't': case 'T': case ' ': case 'D': break; | ||
case 'd': case 'm': case 'y': case 'h': case 'H': case 'M': case 's': case 'e': case 'Z': | ||
out[i].v = write_date(out[i].t, out[i].v, dt); | ||
@@ -393,3 +390,2 @@ out[i].t = 't'; break; | ||
case 'G': out[i].t = 't'; out[i].v = general_fmt(v,opts); break; | ||
default: console.error(out); throw "unrecognized type " + out[i].t; | ||
} | ||
@@ -396,0 +392,0 @@ } |
71
ssf.md
@@ -379,3 +379,3 @@ # SSF | ||
``` | ||
if(fmt == '##0.0E+0') { | ||
if(fmt.match(/^#+0.0E\+0$/)) { | ||
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E'); | ||
@@ -593,3 +593,4 @@ var ee = (Number(val.toExponential(0).substr(2+(val<0))))%period; | ||
o = c; | ||
while(fmt[i++] !== ']') o += fmt[i]; | ||
while(fmt[i++] !== ']' && i < fmt.length) o += fmt[i]; | ||
if(o.substr(-1) !== ']') throw 'unterminated "[" block: |' + o + '|'; | ||
if(o.match(/\[[HhMmSs]*\]/)) { | ||
@@ -668,4 +669,4 @@ if(!dt) dt = parse_date_code(v, opts); | ||
switch(out[i].t) { | ||
case 't': case 'T': case ' ': break; | ||
case 'd': case 'm': case 'y': case 'h': case 'H': case 'M': case 's': case 'A': case 'e': case 'Z': | ||
case 't': case 'T': case ' ': case 'D': break; | ||
case 'd': case 'm': case 'y': case 'h': case 'H': case 'M': case 's': case 'e': case 'Z': | ||
out[i].v = write_date(out[i].t, out[i].v, dt); | ||
@@ -689,3 +690,8 @@ out[i].t = 't'; break; | ||
case 'G': out[i].t = 't'; out[i].v = general_fmt(v,opts); break; | ||
default: console.error(out); throw "unrecognized type " + out[i].t; | ||
``` | ||
The default case should not be reachable. In testing, add the line | ||
`default: console.error(out); throw "unrecognized type " + out[i].t;` | ||
``` | ||
} | ||
@@ -713,4 +719,8 @@ } | ||
case 'y': case 'yy': return pad(val.y % 100,2); | ||
case 'yyy': case 'yyyy': return pad(val.y % 10000,4); | ||
default: throw 'bad year format: ' + fmt; | ||
``` | ||
Apparently, even `yyyyyyyyyyyyyyyyyyyy` is a 4 digit year | ||
``` | ||
default: return pad(val.y % 10000,4); | ||
} | ||
@@ -721,5 +731,9 @@ case 'm': switch(fmt) { /* month */ | ||
case 'mmm': return months[val.m-1][1]; | ||
case 'mmmm': return months[val.m-1][2]; | ||
case 'mmmmm': return months[val.m-1][0]; | ||
default: throw 'bad month format: ' + fmt; | ||
``` | ||
Strangely enough, `mmmmmmmmmmmmmmmmmmmm` is treated as the full month name: | ||
``` | ||
default: return months[val.m-1][2]; | ||
} | ||
@@ -730,4 +744,8 @@ case 'd': switch(fmt) { /* day */ | ||
case 'ddd': return days[val.q][0]; | ||
case 'dddd': return days[val.q][1]; | ||
default: throw 'bad day format: ' + fmt; | ||
``` | ||
Strangely enough, `dddddddddddddddddddd` is treated as the full day name: | ||
``` | ||
default: return days[val.q][1]; | ||
} | ||
@@ -776,3 +794,8 @@ case 'h': switch(fmt) { /* 12-hour */ | ||
case 'e': { return val.y; } break; | ||
default: throw 'bad format type ' + type + ' in ' + fmt; | ||
``` | ||
There is no input to the function that ends up triggering the default behavior: | ||
it is not exported and is only called when the type is in `ymdhHMsZe` | ||
``` | ||
} | ||
@@ -950,2 +973,5 @@ }; | ||
test_min: | ||
MINTEST=1 npm test | ||
.PHONY: lint | ||
@@ -963,4 +989,8 @@ lint: | ||
tmp/coverage.html: ssf.md | ||
tmp/coverage.html: ssf | ||
mocha --require blanket -R html-cov > tmp/coverage.html | ||
.PHONY: cov_min | ||
cov_min: | ||
MINTEST=1 make cov | ||
``` | ||
@@ -980,3 +1010,3 @@ | ||
"name": "ssf", | ||
"version": "0.5.6", | ||
"version": "0.5.7", | ||
"author": "SheetJS", | ||
@@ -1119,5 +1149,5 @@ "description": "pure-JS library to format data using ECMA-376 spreadsheet Format Codes", | ||
describe('date formats', function() { | ||
doit(dates); | ||
doit(process.env.MINTEST ? dates.slice(0,1000) : dates); | ||
it('should fail for bad formats', function() { | ||
var bad = ['yyyyy', 'mmmmmm', 'ddddd']; | ||
var bad = []; | ||
var chk = function(fmt){ return function(){ SSF.format(fmt,0); }; }; | ||
@@ -1139,3 +1169,3 @@ bad.forEach(function(fmt){assert.throws(chk(fmt));}); | ||
it(d[0], function() { | ||
for(var w = 2; w < 3 /*TODO: 1:headers.length */; ++w) { | ||
for(var w = 1; w < headers.length; ++w) { | ||
var expected = d[w].replace("|", ""), actual; | ||
@@ -1149,3 +1179,3 @@ try { actual = SSF.format(headers[w], Number(d[0]), {}); } catch(e) { } | ||
var headers = data[0].split("\t"); | ||
for(var j=14/* TODO: start from 1 */;j<data.length;++j) { | ||
for(var j=1;j<data.length;++j) { | ||
if(!data[j]) return; | ||
@@ -1176,2 +1206,7 @@ doit(data[j].replace(/#{255}/g,"").split("\t"), headers); | ||
}); | ||
it('should fail for bad formats', function() { | ||
var bad = ['##,##']; | ||
var chk = function(fmt){ return function(){ SSF.format(fmt,0); }; }; | ||
bad.forEach(function(fmt){assert.throws(chk(fmt));}); | ||
}); | ||
}); | ||
@@ -1178,0 +1213,0 @@ ``` |
@@ -26,5 +26,5 @@ /* vim: set ts=2: */ | ||
describe('date formats', function() { | ||
doit(dates); | ||
doit(process.env.MINTEST ? dates.slice(0,1000) : dates); | ||
it('should fail for bad formats', function() { | ||
var bad = ['yyyyy', 'mmmmmm', 'ddddd']; | ||
var bad = []; | ||
var chk = function(fmt){ return function(){ SSF.format(fmt,0); }; }; | ||
@@ -31,0 +31,0 @@ bad.forEach(function(fmt){assert.throws(chk(fmt));}); |
@@ -8,3 +8,3 @@ /* vim: set ts=2: */ | ||
it(d[0], function() { | ||
for(var w = 2; w < 3 /*TODO: 1:headers.length */; ++w) { | ||
for(var w = 1; w < headers.length; ++w) { | ||
var expected = d[w].replace("|", ""), actual; | ||
@@ -18,3 +18,3 @@ try { actual = SSF.format(headers[w], Number(d[0]), {}); } catch(e) { } | ||
var headers = data[0].split("\t"); | ||
for(var j=14/* TODO: start from 1 */;j<data.length;++j) { | ||
for(var j=1;j<data.length;++j) { | ||
if(!data[j]) return; | ||
@@ -21,0 +21,0 @@ doit(data[j].replace(/#{255}/g,"").split("\t"), headers); |
@@ -17,2 +17,7 @@ /* vim: set ts=2: */ | ||
}); | ||
it('should fail for bad formats', function() { | ||
var bad = ['##,##']; | ||
var chk = function(fmt){ return function(){ SSF.format(fmt,0); }; }; | ||
bad.forEach(function(fmt){assert.throws(chk(fmt));}); | ||
}); | ||
}); |
@@ -44,5 +44,7 @@ [ | ||
["[hhh]", [0.7]], | ||
["[", [0.7]], | ||
["A/P", [0.7, "P"]], | ||
["e", [0.7, "1900"]], | ||
["123", [0.7, "123"], [0, "123"], ["sheetjs", "sheetjs"]], | ||
["\"foo\";\"bar\";\"baz\";\"qux\";\"foobar\"", [1], [0], [-1], ["sheetjs"]] | ||
] |
Sorry, the diff of this file is not supported yet
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
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
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
105887
1914
7