version bump 1.1.0

- pinned devDependencies
- added missing tests for dynamic specifiers
This commit is contained in:
SheetJS 2017-07-23 15:18:58 -04:00
parent 045b316b67
commit d3f373079c
9 changed files with 64 additions and 17 deletions

View File

@ -396,12 +396,12 @@ printf("|%-*.*d|", -4, 2, 1); // |01 | width=4 prec=2 value=1 flags='-'
A negative precision is discarded:
```C
printf("|%*s|\n", 4, "sheetjs"); // |sheetjs| width=4
printf("|%*.*s|\n", 4, 3, "sheetjs"); // | she| width=4 prec=3
printf("|%*.*s|\n", 4, 2, "sheetjs"); // | sh| width=4 prec=2
printf("|%*.*s|\n", 4, 1, "sheetjs"); // | s| width=4 prec=1
printf("|%*.*s|\n", 4, 0, "sheetjs"); // | | width=4 prec=0
printf("|%*.*s|\n", 4, -1, "sheetjs"); // |sheetjs| width=4 (prec ignored)
printf("|%*s|", 4, "sheetjs"); // |sheetjs| width=4
printf("|%*.*s|", 4, 3, "sheetjs"); // | she| width=4 prec=3
printf("|%*.*s|", 4, 2, "sheetjs"); // | sh| width=4 prec=2
printf("|%*.*s|", 4, 1, "sheetjs"); // | s| width=4 prec=1
printf("|%*.*s|", 4, 0, "sheetjs"); // | | width=4 prec=0
printf("|%*.*s|", 4, -1, "sheetjs"); // |sheetjs| width=4 (prec ignored)
```
@ -544,9 +544,9 @@ When a length specifier implies a certain size (such as `hh` for a single-byte
integer), the number will be converted before rendering strings. For example:
```C
printf("%1$02hhx %1$02hx %1$02lx %1$02llx\n", 256); // 00 100 100 100
printf("%1$02hhx %1$02hx %1$02lx %1$02llx\n", 4096); // 00 1000 1000 1000
printf("%1$02hhx %1$02hx %1$02lx %1$02llx\n", 65536); // 00 00 10000 10000
printf("%1$02hhx %1$02hx %1$02lx %1$02llx", 256); // |00 100 100 100|
printf("%1$02hhx %1$02hx %1$02lx %1$02llx", 4096); // |00 1000 1000 1000|
printf("%1$02hhx %1$02hx %1$02lx %1$02llx", 65536); // |00 00 10000 10000|
```
Values are restricted by first limiting the result to a specified number of

View File

@ -1 +1 @@
PRINTJ.version = '1.0.1';
PRINTJ.version = '1.1.0';

View File

@ -70,6 +70,8 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
#include "54_convmisc.js"
}
if(width < 0) { width = -width; flags += "-"; }
if(isnum == -1) {
#include "60_integer.js"
} else if(isnum > 0) {

View File

@ -23,7 +23,7 @@ var PRINTJ;
/*jshint ignore:end */
}(function(PRINTJ) {
PRINTJ.version = '1.0.1';
PRINTJ.version = '1.1.0';
function tokenize(fmt) {
var out = [];
@ -314,6 +314,8 @@ function doit(t, args) {
}
if(width < 0) { width = -width; flags += "-"; }
if(isnum == -1) {
Vnum = Number(arg);

View File

@ -171,4 +171,23 @@ describe('special cases', function() {
assert.equal(sprintf("|%1$b|%1$B|%1$d|%1$D|%1$i|%1$o|%1$O|%1$u|%1$U|%1$x|%1$X|", undefined), "|0|0|0|0|0|0|0|0|0|0|0|");
assert.equal(sprintf("|%1$b|%1$B|%1$d|%1$D|%1$i|%1$o|%1$O|%1$u|%1$U|%1$x|%1$X|", null), "|0|0|0|0|0|0|0|0|0|0|0|");
});
it('handles dynamic specifiers', function() {
assert.equal(sprintf("|%5s|", "sheetjs"), "|sheetjs|");
assert.equal(sprintf("|%*s|", 5, "sheetjs"), "|sheetjs|");
assert.equal(sprintf("|%2$*1$s|", 5, "sheetjs", 10), "|sheetjs|");
assert.equal(sprintf("|%10s|", "sheetjs"), "| sheetjs|");
assert.equal(sprintf("|%2$*3$s|", 5, "sheetjs", 10), "| sheetjs|");
assert.equal(sprintf("|%0*.*d|", 4, 2, 1), "| 01|");
assert.equal(sprintf("|%1$0*3$.*2$d|", 1, 2, 4), "| 01|");
assert.equal(sprintf("|%*.*d|", 4, 2, 1), "| 01|");
assert.equal(sprintf("|%-*.*d|", 4, 2, 1), "|01 |");
assert.equal(sprintf("|%*.*d|", -4, 2, 1), "|01 |");
assert.equal(sprintf("|%-*.*d|", -4, 2, 1), "|01 |");
assert.equal(sprintf("|%*s|", 4, "sheetjs"), "|sheetjs|");
assert.equal(sprintf("|%*.*s|", 4, 3, "sheetjs"), "| she|");
assert.equal(sprintf("|%*.*s|", 4, 2, "sheetjs"), "| sh|");
assert.equal(sprintf("|%*.*s|", 4, 1, "sheetjs"), "| s|");
assert.equal(sprintf("|%*.*s|", 4, 0, "sheetjs"), "| |");
assert.equal(sprintf("|%*.*s|", 4, -1, "sheetjs"), "|sheetjs|");
});
});

View File

@ -1,6 +1,6 @@
{
"name": "printj",
"version": "1.0.2",
"version": "1.1.0",
"author": "sheetjs",
"description": "Pure-JS printf",
"keywords": [ "printf", "sprintf", "format", "string" ],
@ -12,9 +12,10 @@
"dependencies": {
},
"devDependencies": {
"mocha":"",
"@sheetjs/uglify-js":"",
"@types/node":"",
"mocha":"~2.5.3",
"blanket": "~1.2.3",
"@sheetjs/uglify-js":"~2.7.3",
"@types/node":"^8.0.7",
"dtslint": "^0.1.2",
"typescript": "2.2.0"
},

View File

@ -25,7 +25,7 @@ var PRINTJ/*:PRINTJModule*/;
/*jshint ignore:end */
}(function(PRINTJ/*:PRINTJModule*/) {
PRINTJ.version = '1.0.1';
PRINTJ.version = '1.1.0';
function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
var out/*:ParsedFmt*/ = [];
@ -317,6 +317,8 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
}
if(width < 0) { width = -width; flags += "-"; }
if(isnum == -1) {
Vnum = Number(arg);

View File

@ -23,7 +23,7 @@ var PRINTJ;
/*jshint ignore:end */
}(function(PRINTJ) {
PRINTJ.version = '1.0.1';
PRINTJ.version = '1.1.0';
function tokenize(fmt) {
var out = [];
@ -314,6 +314,8 @@ function doit(t, args) {
}
if(width < 0) { width = -width; flags += "-"; }
if(isnum == -1) {
Vnum = Number(arg);

19
test.js
View File

@ -171,4 +171,23 @@ describe('special cases', function() {
assert.equal(sprintf("|%1$b|%1$B|%1$d|%1$D|%1$i|%1$o|%1$O|%1$u|%1$U|%1$x|%1$X|", undefined), "|0|0|0|0|0|0|0|0|0|0|0|");
assert.equal(sprintf("|%1$b|%1$B|%1$d|%1$D|%1$i|%1$o|%1$O|%1$u|%1$U|%1$x|%1$X|", null), "|0|0|0|0|0|0|0|0|0|0|0|");
});
it('handles dynamic specifiers', function() {
assert.equal(sprintf("|%5s|", "sheetjs"), "|sheetjs|");
assert.equal(sprintf("|%*s|", 5, "sheetjs"), "|sheetjs|");
assert.equal(sprintf("|%2$*1$s|", 5, "sheetjs", 10), "|sheetjs|");
assert.equal(sprintf("|%10s|", "sheetjs"), "| sheetjs|");
assert.equal(sprintf("|%2$*3$s|", 5, "sheetjs", 10), "| sheetjs|");
assert.equal(sprintf("|%0*.*d|", 4, 2, 1), "| 01|");
assert.equal(sprintf("|%1$0*3$.*2$d|", 1, 2, 4), "| 01|");
assert.equal(sprintf("|%*.*d|", 4, 2, 1), "| 01|");
assert.equal(sprintf("|%-*.*d|", 4, 2, 1), "|01 |");
assert.equal(sprintf("|%*.*d|", -4, 2, 1), "|01 |");
assert.equal(sprintf("|%-*.*d|", -4, 2, 1), "|01 |");
assert.equal(sprintf("|%*s|", 4, "sheetjs"), "|sheetjs|");
assert.equal(sprintf("|%*.*s|", 4, 3, "sheetjs"), "| she|");
assert.equal(sprintf("|%*.*s|", 4, 2, "sheetjs"), "| sh|");
assert.equal(sprintf("|%*.*s|", 4, 1, "sheetjs"), "| s|");
assert.equal(sprintf("|%*.*s|", 4, 0, "sheetjs"), "| |");
assert.equal(sprintf("|%*.*s|", 4, -1, "sheetjs"), "|sheetjs|");
});
});