version bump 1.2.1: cleanup

This commit is contained in:
SheetJS 2018-10-19 13:13:54 -04:00
parent 860f1ed9e6
commit f04791d1e7
17 changed files with 222 additions and 203 deletions

1
.gitignore vendored

@ -2,3 +2,4 @@ node_modules
misc/coverage.html
ctest/sauce*
*.sheetjs
*.tgz

@ -10,7 +10,6 @@ var PRINTJ/*:PRINTJModule*/ = /*::(*/{}/*:: :any)*/;
export const version = PRINTJ.version;
#else
var PRINTJ/*:PRINTJModule*/;
#include "05_polyfill.js"
(function (factory/*:(a:any)=>void*/)/*:void*/ {
/*jshint ignore:start */
/*eslint-disable */

@ -1 +1 @@
PRINTJ.version = '1.2.0';
PRINTJ.version = '1.2.1';

@ -1,38 +0,0 @@
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
if (!String.prototype.repeat) {
String.prototype.repeat = function(count) {
'use strict';
if (this == null) {
throw new TypeError('can\'t convert ' + this + ' to object');
}
var str = '' + this;
count = +count;
if (count != count) {
count = 0;
}
if (count < 0) {
throw new RangeError('repeat count must be non-negative');
}
if (count == Infinity) {
throw new RangeError('repeat count must be less than infinity');
}
count = Math.floor(count);
if (str.length == 0 || count == 0) {
return '';
}
// Ensuring count is a 31-bit integer allows us to heavily optimize the
// main part. But anyway, most current (August 2014) browsers can't handle
// strings 1 << 28 chars or longer, so:
if (str.length * count >= 1 << 28) {
throw new RangeError('repeat count must not overflow maximum string size');
}
var maxCount = str.length * count;
count = Math.floor(Math.log(count) / Math.log(2));
while (count) {
str += str;
count--;
}
str += str.substring(0, maxCount - str.length);
return str;
}
}

@ -25,7 +25,7 @@ var PRINTJ;
/*jshint ignore:end */
}(function(PRINTJ) {
PRINTJ.version = '1.1.2';
PRINTJ.version = '1.2.1';
function tokenize(fmt) {
var out = [];
@ -149,14 +149,6 @@ function tokenize(fmt) {
return out;
}
//#define PAD_(x,c) (x >= 0 ? new Array(((x)|0) + 1).join((c)) : "")
var padstr = {
" ": " ",
"0": "000000000000000000000000000000000",
"7": "777777777777777777777777777777777",
"f": "fffffffffffffffffffffffffffffffff"
};
/*global process:true, util:true, require:true */
if(typeof process !== 'undefined' && !!process.versions && !!process.versions.node) util=require("util");
var u_inspect = (typeof util != 'undefined') ? util.inspect : JSON.stringify;
@ -208,7 +200,7 @@ function doit(t, args) {
/* only valid flag is "-" for left justification */
O = String(arg);
if( prec >= 0) O = O.substr(0, prec);
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
/* first char of string or convert */
@ -223,7 +215,7 @@ function doit(t, args) {
case "string": O = arg.charAt(0); break;
default: O = String(arg).charAt(0);
}
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
/* int diDuUoOxXbB */
@ -308,10 +300,10 @@ function doit(t, args) {
/* boolean (extension) */
case /*Y*/ 89:
case /*y*/ 121:
O = Boolean(arg) ? (alt ? "yes" : "true") : (alt ? "no" : "false");
O = (arg) ? (alt ? "yes" : "true") : (alt ? "no" : "false");
if(c == /*Y*/ 89) O = O.toUpperCase();
if( prec >= 0) O = O.substr(0, prec);
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
}
@ -373,16 +365,16 @@ function doit(t, args) {
if(radix == 16 || radix == -16) {
O = (Vnum>>>0).toString(16);
Vnum = Math.floor((Vnum - (Vnum >>> 0)) / Math.pow(2,32));
O = (Vnum>>>0).toString(16) + (8 - O.length >= 0 ? padstr[ "0"].substr(0,8 - O.length) : "") + O;
O = (16 - O.length >= 0 ? padstr[ "f"].substr(0,16 - O.length) : "") + O;
O = (Vnum>>>0).toString(16) + (8 - O.length >= 0 ? "0".repeat(8 - O.length) : "") + O;
O = (16 - O.length >= 0 ? "f".repeat(16 - O.length) : "") + O;
if(radix == 16) O = O.toUpperCase();
} else if(radix == 8) {
O = (Vnum>>>0).toString(8);
O = (10 - O.length >= 0 ? padstr[ "0"].substr(0,10 - O.length) : "") + O;
O = (10 - O.length >= 0 ? "0".repeat(10 - O.length) : "") + O;
Vnum = Math.floor((Vnum - ((Vnum >>> 0)&0x3FFFFFFF)) / Math.pow(2,30));
O = (Vnum>>>0).toString(8) + O.substr(O.length - 10);
O = O.substr(O.length - 20);
O = "1" + (21 - O.length >= 0 ? padstr[ "7"].substr(0,21 - O.length) : "") + O;
O = "1" + (21 - O.length >= 0 ? "7".repeat(21 - O.length) : "") + O;
} else {
Vnum = (-Vnum) % 1e16;
var d1 = [1,8,4,4,6,7,4,4,0,7,3,7,0,9,5,5,1,6,1,6];
@ -403,8 +395,8 @@ function doit(t, args) {
if(prec ===0 && O == "0" && !(radix == 8 && alt)) O = ""; /* bail out */
else {
if(O.length < prec + (O.substr(0,1) == "-" ? 1 : 0)) {
if(O.substr(0,1) != "-") O = (prec - O.length >= 0 ? padstr[ "0"].substr(0,prec - O.length) : "") + O;
else O = O.substr(0,1) + (prec + 1 - O.length >= 0 ? padstr[ "0"].substr(0,prec + 1 - O.length) : "") + O.substr(1);
if(O.substr(0,1) != "-") O = (prec - O.length >= 0 ? "0".repeat(prec - O.length) : "") + O;
else O = O.substr(0,1) + (prec + 1 - O.length >= 0 ? "0".repeat(prec + 1 - O.length) : "") + O.substr(1);
}
/* add prefix for # form */
@ -425,10 +417,10 @@ function doit(t, args) {
if(width > 0) {
if(O.length < width) {
if(flags.indexOf("-") > -1) {
O = O + ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "");
O = O + ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "");
} else if(flags.indexOf("0") > -1 && prec < 0 && O.length > 0) {
if(prec > O.length) O = ((prec - O.length) >= 0 ? padstr[ "0"].substr(0,(prec - O.length)) : "") + O;
pad = ((width - O.length) >= 0 ? padstr[ (prec > 0 ? " " : "0")].substr(0,(width - O.length)) : "");
if(prec > O.length) O = ((prec - O.length) >= 0 ? "0".repeat((prec - O.length)) : "") + O;
pad = ((width - O.length) >= 0 ? (prec > 0 ? " " : "0").repeat((width - O.length)) : "");
if(O.charCodeAt(0) < 48) {
if(O.charAt(2).toLowerCase() == "x") O = O.substr(0,3) + pad + O.substring(3);
else O = O.substr(0,1) + pad + O.substring(1);
@ -436,7 +428,7 @@ function doit(t, args) {
else if(O.charAt(1).toLowerCase() == "x") O = O.substr(0,2) + pad + O.substring(2);
else O = pad + O;
} else {
O = ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "") + O;
O = ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "") + O;
}
}
}
@ -483,8 +475,8 @@ function doit(t, args) {
O = Vnum.toExponential(20);
E = +O.substr(O.indexOf("e")+1);
O = O.charAt(0) + O.substr(2,O.indexOf("e")-2);
O = O + (E - O.length + 1 >= 0 ? padstr[ "0"].substr(0,E - O.length + 1) : "");
if(alt || (prec > 0 && isnum !== 11)) O = O + "." + (prec >= 0 ? padstr[ "0"].substr(0,prec) : "");
O = O + (E - O.length + 1 >= 0 ? "0".repeat(E - O.length + 1) : "");
if(alt || (prec > 0 && isnum !== 11)) O = O + "." + (prec >= 0 ? "0".repeat(prec) : "");
break;
/* e/E exponential */
@ -498,7 +490,7 @@ function doit(t, args) {
/* a/A hex */
case 4:
if(Vnum===0){O= "0x0"+((alt||prec>0)?"."+(prec >= 0 ? padstr["0"].substr(0,prec) : ""):"")+"p+0"; break;}
if(Vnum===0){O= "0x0"+((alt||prec>0)?"."+(prec >= 0 ? "0".repeat(prec) : ""):"")+"p+0"; break;}
O = Vnum.toString(16);
/* First char 0-9 */
var ac = O.charCodeAt(0);
@ -545,11 +537,11 @@ function doit(t, args) {
if(prec > 0) {
O = O.substr(0, prec + 2);
if(O.length < prec + 2) {
if(O.charCodeAt(0) < 48) O = O.charAt(0) + ((prec + 2 - O.length) >= 0 ? padstr[ "0"].substr(0,(prec + 2 - O.length)) : "") + O.substr(1);
else O += ((prec + 2 - O.length) >= 0 ? padstr[ "0"].substr(0,(prec + 2 - O.length)) : "");
if(O.charCodeAt(0) < 48) O = O.charAt(0) + ((prec + 2 - O.length) >= 0 ? "0".repeat((prec + 2 - O.length)) : "") + O.substr(1);
else O += ((prec + 2 - O.length) >= 0 ? "0".repeat((prec + 2 - O.length)) : "");
}
} else if(prec === 0) O = O.charAt(0) + (alt ? "." : "");
} else if(prec > 0) O = O + "." + (prec >= 0 ? padstr["0"].substr(0,prec) : "");
} else if(prec > 0) O = O + "." + (prec >= 0 ? "0".repeat(prec) : "");
else if(alt) O = O + ".";
O = "0x" + O + "p" + (E>=0 ? "+" + E : E);
break;
@ -566,9 +558,9 @@ function doit(t, args) {
/* width */
if(width > O.length) {
if(flags.indexOf("-") > -1) {
O = O + ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "");
O = O + ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "");
} else if(flags.indexOf("0") > -1 && O.length > 0 && isf) {
pad = ((width - O.length) >= 0 ? padstr[ "0"].substr(0,(width - O.length)) : "");
pad = ((width - O.length) >= 0 ? "0".repeat((width - O.length)) : "");
if(O.charCodeAt(0) < 48) {
if(O.charAt(2).toLowerCase() == "x") O = O.substr(0,3) + pad + O.substring(3);
else O = O.substr(0,1) + pad + O.substring(1);
@ -576,7 +568,7 @@ function doit(t, args) {
else if(O.charAt(1).toLowerCase() == "x") O = O.substr(0,2) + pad + O.substring(2);
else O = pad + O;
} else {
O = ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "") + O;
O = ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "") + O;
}
}
if(c < 96) O = O.toUpperCase();

@ -235,3 +235,42 @@ if (typeof ArrayBuffer !== 'undefined' && !ArrayBuffer.prototype.slice) {
return target;
};
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
if (!String.prototype.repeat) {
String.prototype.repeat = function(count) {
'use strict';
if (this == null) {
throw new TypeError('can\'t convert ' + this + ' to object');
}
var str = '' + this;
count = +count;
if (count != count) {
count = 0;
}
if (count < 0) {
throw new RangeError('repeat count must be non-negative');
}
if (count == Infinity) {
throw new RangeError('repeat count must be less than infinity');
}
count = Math.floor(count);
if (str.length == 0 || count == 0) {
return '';
}
// Ensuring count is a 31-bit integer allows us to heavily optimize the
// main part. But anyway, most current (August 2014) browsers can't handle
// strings 1 << 28 chars or longer, so:
if (str.length * count >= 1 << 28) {
throw new RangeError('repeat count must not overflow maximum string size');
}
var maxCount = str.length * count;
count = Math.floor(Math.log(count) / Math.log(2));
while (count) {
str += str;
count--;
}
str += str.substring(0, maxCount - str.length);
return str;
};
}

@ -190,4 +190,7 @@ describe('special cases', function() {
assert.equal(sprintf("|%*.*s|", 4, 0, "sheetjs"), "| |");
assert.equal(sprintf("|%*.*s|", 4, -1, "sheetjs"), "|sheetjs|");
});
it('handles long strings', function() {
for(var i = 10; i <= 1000; i+= 10) assert.equal(sprintf("%" + i + "s", "abc").length, i);
});
});

@ -7,7 +7,7 @@
var PRINTJ/*:PRINTJModule*/ = /*::(*/{}/*:: :any)*/;
PRINTJ.version = '1.2.0';
PRINTJ.version = '1.2.1';
export const version = PRINTJ.version;
@ -133,14 +133,6 @@ function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
return out;
}
//#define PAD_(x,c) (x >= 0 ? new Array(((x)|0) + 1).join((c)) : "")
var padstr/*:{[s:string]:string}*/ = {
" ": " ",
"0": "000000000000000000000000000000000",
"7": "777777777777777777777777777777777",
"f": "fffffffffffffffffffffffffffffffff"
};
var u_inspect/*:(o:any)=>string*/ = JSON.stringify;
function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
@ -190,7 +182,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
/* only valid flag is "-" for left justification */
O = String(arg);
if( prec >= 0) O = O.substr(0, prec);
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
/* first char of string or convert */
@ -205,7 +197,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
case "string": O = /*::(*/arg/*:: :string)*/.charAt(0); break;
default: O = String(arg).charAt(0);
}
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
/* int diDuUoOxXbB */
@ -293,7 +285,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
O = (arg) ? (alt ? "yes" : "true") : (alt ? "no" : "false");
if(c == /*Y*/ 89) O = O.toUpperCase();
if( prec >= 0) O = O.substr(0, prec);
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
}
@ -355,16 +347,16 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
if(radix == 16 || radix == -16) {
O = (Vnum>>>0).toString(16);
Vnum = Math.floor((Vnum - (Vnum >>> 0)) / Math.pow(2,32));
O = (Vnum>>>0).toString(16) + (8 - O.length >= 0 ? padstr[ "0"].substr(0,8 - O.length) : "") + O;
O = (16 - O.length >= 0 ? padstr[ "f"].substr(0,16 - O.length) : "") + O;
O = (Vnum>>>0).toString(16) + (8 - O.length >= 0 ? "0".repeat(8 - O.length) : "") + O;
O = (16 - O.length >= 0 ? "f".repeat(16 - O.length) : "") + O;
if(radix == 16) O = O.toUpperCase();
} else if(radix == 8) {
O = (Vnum>>>0).toString(8);
O = (10 - O.length >= 0 ? padstr[ "0"].substr(0,10 - O.length) : "") + O;
O = (10 - O.length >= 0 ? "0".repeat(10 - O.length) : "") + O;
Vnum = Math.floor((Vnum - ((Vnum >>> 0)&0x3FFFFFFF)) / Math.pow(2,30));
O = (Vnum>>>0).toString(8) + O.substr(O.length - 10);
O = O.substr(O.length - 20);
O = "1" + (21 - O.length >= 0 ? padstr[ "7"].substr(0,21 - O.length) : "") + O;
O = "1" + (21 - O.length >= 0 ? "7".repeat(21 - O.length) : "") + O;
} else {
Vnum = (-Vnum) % 1e16;
var d1/*:Array<number>*/ = [1,8,4,4,6,7,4,4,0,7,3,7,0,9,5,5,1,6,1,6];
@ -385,8 +377,8 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
if(prec ===0 && O == "0" && !(radix == 8 && alt)) O = ""; /* bail out */
else {
if(O.length < prec + (O.substr(0,1) == "-" ? 1 : 0)) {
if(O.substr(0,1) != "-") O = (prec - O.length >= 0 ? padstr[ "0"].substr(0,prec - O.length) : "") + O;
else O = O.substr(0,1) + (prec + 1 - O.length >= 0 ? padstr[ "0"].substr(0,prec + 1 - O.length) : "") + O.substr(1);
if(O.substr(0,1) != "-") O = (prec - O.length >= 0 ? "0".repeat(prec - O.length) : "") + O;
else O = O.substr(0,1) + (prec + 1 - O.length >= 0 ? "0".repeat(prec + 1 - O.length) : "") + O.substr(1);
}
/* add prefix for # form */
@ -407,10 +399,10 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
if(width > 0) {
if(O.length < width) {
if(flags.indexOf("-") > -1) {
O = O + ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "");
O = O + ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "");
} else if(flags.indexOf("0") > -1 && prec < 0 && O.length > 0) {
if(prec > O.length) O = ((prec - O.length) >= 0 ? padstr[ "0"].substr(0,(prec - O.length)) : "") + O;
pad = ((width - O.length) >= 0 ? padstr[ (prec > 0 ? " " : "0")].substr(0,(width - O.length)) : "");
if(prec > O.length) O = ((prec - O.length) >= 0 ? "0".repeat((prec - O.length)) : "") + O;
pad = ((width - O.length) >= 0 ? (prec > 0 ? " " : "0").repeat((width - O.length)) : "");
if(O.charCodeAt(0) < 48) {
if(O.charAt(2).toLowerCase() == "x") O = O.substr(0,3) + pad + O.substring(3);
else O = O.substr(0,1) + pad + O.substring(1);
@ -418,7 +410,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
else if(O.charAt(1).toLowerCase() == "x") O = O.substr(0,2) + pad + O.substring(2);
else O = pad + O;
} else {
O = ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "") + O;
O = ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "") + O;
}
}
}
@ -465,8 +457,8 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
O = Vnum.toExponential(20);
E = +O.substr(O.indexOf("e")+1);
O = O.charAt(0) + O.substr(2,O.indexOf("e")-2);
O = O + (E - O.length + 1 >= 0 ? padstr[ "0"].substr(0,E - O.length + 1) : "");
if(alt || (prec > 0 && isnum !== 11)) O = O + "." + (prec >= 0 ? padstr[ "0"].substr(0,prec) : "");
O = O + (E - O.length + 1 >= 0 ? "0".repeat(E - O.length + 1) : "");
if(alt || (prec > 0 && isnum !== 11)) O = O + "." + (prec >= 0 ? "0".repeat(prec) : "");
break;
/* e/E exponential */
@ -480,7 +472,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
/* a/A hex */
case 4:
if(Vnum===0){O= "0x0"+((alt||prec>0)?"."+(prec >= 0 ? padstr["0"].substr(0,prec) : ""):"")+"p+0"; break;}
if(Vnum===0){O= "0x0"+((alt||prec>0)?"."+(prec >= 0 ? "0".repeat(prec) : ""):"")+"p+0"; break;}
O = Vnum.toString(16);
/* First char 0-9 */
var ac/*:number*/ = O.charCodeAt(0);
@ -527,11 +519,11 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
if(prec > 0) {
O = O.substr(0, prec + 2);
if(O.length < prec + 2) {
if(O.charCodeAt(0) < 48) O = O.charAt(0) + ((prec + 2 - O.length) >= 0 ? padstr[ "0"].substr(0,(prec + 2 - O.length)) : "") + O.substr(1);
else O += ((prec + 2 - O.length) >= 0 ? padstr[ "0"].substr(0,(prec + 2 - O.length)) : "");
if(O.charCodeAt(0) < 48) O = O.charAt(0) + ((prec + 2 - O.length) >= 0 ? "0".repeat((prec + 2 - O.length)) : "") + O.substr(1);
else O += ((prec + 2 - O.length) >= 0 ? "0".repeat((prec + 2 - O.length)) : "");
}
} else if(prec === 0) O = O.charAt(0) + (alt ? "." : "");
} else if(prec > 0) O = O + "." + (prec >= 0 ? padstr["0"].substr(0,prec) : "");
} else if(prec > 0) O = O + "." + (prec >= 0 ? "0".repeat(prec) : "");
else if(alt) O = O + ".";
O = "0x" + O + "p" + (E>=0 ? "+" + E : E);
break;
@ -548,9 +540,9 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
/* width */
if(width > O.length) {
if(flags.indexOf("-") > -1) {
O = O + ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "");
O = O + ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "");
} else if(flags.indexOf("0") > -1 && O.length > 0 && isf) {
pad = ((width - O.length) >= 0 ? padstr[ "0"].substr(0,(width - O.length)) : "");
pad = ((width - O.length) >= 0 ? "0".repeat((width - O.length)) : "");
if(O.charCodeAt(0) < 48) {
if(O.charAt(2).toLowerCase() == "x") O = O.substr(0,3) + pad + O.substring(3);
else O = O.substr(0,1) + pad + O.substring(1);
@ -558,7 +550,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
else if(O.charAt(1).toLowerCase() == "x") O = O.substr(0,2) + pad + O.substring(2);
else O = pad + O;
} else {
O = ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "") + O;
O = ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "") + O;
}
}
if(c < 96) O = O.toUpperCase();

@ -1,6 +1,6 @@
{
"name": "printj",
"version": "1.2.0",
"version": "1.2.1",
"author": "sheetjs",
"description": "Pure-JS printf",
"keywords": [

@ -28,7 +28,7 @@ var PRINTJ/*:PRINTJModule*/;
/*jshint ignore:end */
}(function(PRINTJ/*:PRINTJModule*/) {
PRINTJ.version = '1.2.0';
PRINTJ.version = '1.2.1';
function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
var out/*:ParsedFmt*/ = [];
@ -152,14 +152,6 @@ function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
return out;
}
//#define PAD_(x,c) (x >= 0 ? new Array(((x)|0) + 1).join((c)) : "")
var padstr/*:{[s:string]:string}*/ = {
" ": " ",
"0": "000000000000000000000000000000000",
"7": "777777777777777777777777777777777",
"f": "fffffffffffffffffffffffffffffffff"
};
/*:: var util = require('util'); */
/*global process:true, util:true, require:true */
if(typeof process !== 'undefined' && !!process.versions && !!process.versions.node) util=require("util");
@ -212,7 +204,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
/* only valid flag is "-" for left justification */
O = String(arg);
if( prec >= 0) O = O.substr(0, prec);
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
/* first char of string or convert */
@ -227,7 +219,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
case "string": O = /*::(*/arg/*:: :string)*/.charAt(0); break;
default: O = String(arg).charAt(0);
}
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
/* int diDuUoOxXbB */
@ -315,7 +307,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
O = (arg) ? (alt ? "yes" : "true") : (alt ? "no" : "false");
if(c == /*Y*/ 89) O = O.toUpperCase();
if( prec >= 0) O = O.substr(0, prec);
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
}
@ -377,16 +369,16 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
if(radix == 16 || radix == -16) {
O = (Vnum>>>0).toString(16);
Vnum = Math.floor((Vnum - (Vnum >>> 0)) / Math.pow(2,32));
O = (Vnum>>>0).toString(16) + (8 - O.length >= 0 ? padstr[ "0"].substr(0,8 - O.length) : "") + O;
O = (16 - O.length >= 0 ? padstr[ "f"].substr(0,16 - O.length) : "") + O;
O = (Vnum>>>0).toString(16) + (8 - O.length >= 0 ? "0".repeat(8 - O.length) : "") + O;
O = (16 - O.length >= 0 ? "f".repeat(16 - O.length) : "") + O;
if(radix == 16) O = O.toUpperCase();
} else if(radix == 8) {
O = (Vnum>>>0).toString(8);
O = (10 - O.length >= 0 ? padstr[ "0"].substr(0,10 - O.length) : "") + O;
O = (10 - O.length >= 0 ? "0".repeat(10 - O.length) : "") + O;
Vnum = Math.floor((Vnum - ((Vnum >>> 0)&0x3FFFFFFF)) / Math.pow(2,30));
O = (Vnum>>>0).toString(8) + O.substr(O.length - 10);
O = O.substr(O.length - 20);
O = "1" + (21 - O.length >= 0 ? padstr[ "7"].substr(0,21 - O.length) : "") + O;
O = "1" + (21 - O.length >= 0 ? "7".repeat(21 - O.length) : "") + O;
} else {
Vnum = (-Vnum) % 1e16;
var d1/*:Array<number>*/ = [1,8,4,4,6,7,4,4,0,7,3,7,0,9,5,5,1,6,1,6];
@ -407,8 +399,8 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
if(prec ===0 && O == "0" && !(radix == 8 && alt)) O = ""; /* bail out */
else {
if(O.length < prec + (O.substr(0,1) == "-" ? 1 : 0)) {
if(O.substr(0,1) != "-") O = (prec - O.length >= 0 ? padstr[ "0"].substr(0,prec - O.length) : "") + O;
else O = O.substr(0,1) + (prec + 1 - O.length >= 0 ? padstr[ "0"].substr(0,prec + 1 - O.length) : "") + O.substr(1);
if(O.substr(0,1) != "-") O = (prec - O.length >= 0 ? "0".repeat(prec - O.length) : "") + O;
else O = O.substr(0,1) + (prec + 1 - O.length >= 0 ? "0".repeat(prec + 1 - O.length) : "") + O.substr(1);
}
/* add prefix for # form */
@ -429,10 +421,10 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
if(width > 0) {
if(O.length < width) {
if(flags.indexOf("-") > -1) {
O = O + ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "");
O = O + ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "");
} else if(flags.indexOf("0") > -1 && prec < 0 && O.length > 0) {
if(prec > O.length) O = ((prec - O.length) >= 0 ? padstr[ "0"].substr(0,(prec - O.length)) : "") + O;
pad = ((width - O.length) >= 0 ? padstr[ (prec > 0 ? " " : "0")].substr(0,(width - O.length)) : "");
if(prec > O.length) O = ((prec - O.length) >= 0 ? "0".repeat((prec - O.length)) : "") + O;
pad = ((width - O.length) >= 0 ? (prec > 0 ? " " : "0").repeat((width - O.length)) : "");
if(O.charCodeAt(0) < 48) {
if(O.charAt(2).toLowerCase() == "x") O = O.substr(0,3) + pad + O.substring(3);
else O = O.substr(0,1) + pad + O.substring(1);
@ -440,7 +432,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
else if(O.charAt(1).toLowerCase() == "x") O = O.substr(0,2) + pad + O.substring(2);
else O = pad + O;
} else {
O = ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "") + O;
O = ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "") + O;
}
}
}
@ -487,8 +479,8 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
O = Vnum.toExponential(20);
E = +O.substr(O.indexOf("e")+1);
O = O.charAt(0) + O.substr(2,O.indexOf("e")-2);
O = O + (E - O.length + 1 >= 0 ? padstr[ "0"].substr(0,E - O.length + 1) : "");
if(alt || (prec > 0 && isnum !== 11)) O = O + "." + (prec >= 0 ? padstr[ "0"].substr(0,prec) : "");
O = O + (E - O.length + 1 >= 0 ? "0".repeat(E - O.length + 1) : "");
if(alt || (prec > 0 && isnum !== 11)) O = O + "." + (prec >= 0 ? "0".repeat(prec) : "");
break;
/* e/E exponential */
@ -502,7 +494,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
/* a/A hex */
case 4:
if(Vnum===0){O= "0x0"+((alt||prec>0)?"."+(prec >= 0 ? padstr["0"].substr(0,prec) : ""):"")+"p+0"; break;}
if(Vnum===0){O= "0x0"+((alt||prec>0)?"."+(prec >= 0 ? "0".repeat(prec) : ""):"")+"p+0"; break;}
O = Vnum.toString(16);
/* First char 0-9 */
var ac/*:number*/ = O.charCodeAt(0);
@ -549,11 +541,11 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
if(prec > 0) {
O = O.substr(0, prec + 2);
if(O.length < prec + 2) {
if(O.charCodeAt(0) < 48) O = O.charAt(0) + ((prec + 2 - O.length) >= 0 ? padstr[ "0"].substr(0,(prec + 2 - O.length)) : "") + O.substr(1);
else O += ((prec + 2 - O.length) >= 0 ? padstr[ "0"].substr(0,(prec + 2 - O.length)) : "");
if(O.charCodeAt(0) < 48) O = O.charAt(0) + ((prec + 2 - O.length) >= 0 ? "0".repeat((prec + 2 - O.length)) : "") + O.substr(1);
else O += ((prec + 2 - O.length) >= 0 ? "0".repeat((prec + 2 - O.length)) : "");
}
} else if(prec === 0) O = O.charAt(0) + (alt ? "." : "");
} else if(prec > 0) O = O + "." + (prec >= 0 ? padstr["0"].substr(0,prec) : "");
} else if(prec > 0) O = O + "." + (prec >= 0 ? "0".repeat(prec) : "");
else if(alt) O = O + ".";
O = "0x" + O + "p" + (E>=0 ? "+" + E : E);
break;
@ -570,9 +562,9 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
/* width */
if(width > O.length) {
if(flags.indexOf("-") > -1) {
O = O + ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "");
O = O + ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "");
} else if(flags.indexOf("0") > -1 && O.length > 0 && isf) {
pad = ((width - O.length) >= 0 ? padstr[ "0"].substr(0,(width - O.length)) : "");
pad = ((width - O.length) >= 0 ? "0".repeat((width - O.length)) : "");
if(O.charCodeAt(0) < 48) {
if(O.charAt(2).toLowerCase() == "x") O = O.substr(0,3) + pad + O.substring(3);
else O = O.substr(0,1) + pad + O.substring(1);
@ -580,7 +572,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
else if(O.charAt(1).toLowerCase() == "x") O = O.substr(0,2) + pad + O.substring(2);
else O = pad + O;
} else {
O = ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "") + O;
O = ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "") + O;
}
}
if(c < 96) O = O.toUpperCase();

@ -25,7 +25,7 @@ var PRINTJ;
/*jshint ignore:end */
}(function(PRINTJ) {
PRINTJ.version = '1.2.0';
PRINTJ.version = '1.2.1';
function tokenize(fmt) {
var out = [];
@ -149,14 +149,6 @@ function tokenize(fmt) {
return out;
}
//#define PAD_(x,c) (x >= 0 ? new Array(((x)|0) + 1).join((c)) : "")
var padstr = {
" ": " ",
"0": "000000000000000000000000000000000",
"7": "777777777777777777777777777777777",
"f": "fffffffffffffffffffffffffffffffff"
};
/*global process:true, util:true, require:true */
if(typeof process !== 'undefined' && !!process.versions && !!process.versions.node) util=require("util");
var u_inspect = (typeof util != 'undefined') ? util.inspect : JSON.stringify;
@ -208,7 +200,7 @@ function doit(t, args) {
/* only valid flag is "-" for left justification */
O = String(arg);
if( prec >= 0) O = O.substr(0, prec);
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
/* first char of string or convert */
@ -223,7 +215,7 @@ function doit(t, args) {
case "string": O = arg.charAt(0); break;
default: O = String(arg).charAt(0);
}
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
/* int diDuUoOxXbB */
@ -311,7 +303,7 @@ function doit(t, args) {
O = (arg) ? (alt ? "yes" : "true") : (alt ? "no" : "false");
if(c == /*Y*/ 89) O = O.toUpperCase();
if( prec >= 0) O = O.substr(0, prec);
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
}
@ -373,16 +365,16 @@ function doit(t, args) {
if(radix == 16 || radix == -16) {
O = (Vnum>>>0).toString(16);
Vnum = Math.floor((Vnum - (Vnum >>> 0)) / Math.pow(2,32));
O = (Vnum>>>0).toString(16) + (8 - O.length >= 0 ? padstr[ "0"].substr(0,8 - O.length) : "") + O;
O = (16 - O.length >= 0 ? padstr[ "f"].substr(0,16 - O.length) : "") + O;
O = (Vnum>>>0).toString(16) + (8 - O.length >= 0 ? "0".repeat(8 - O.length) : "") + O;
O = (16 - O.length >= 0 ? "f".repeat(16 - O.length) : "") + O;
if(radix == 16) O = O.toUpperCase();
} else if(radix == 8) {
O = (Vnum>>>0).toString(8);
O = (10 - O.length >= 0 ? padstr[ "0"].substr(0,10 - O.length) : "") + O;
O = (10 - O.length >= 0 ? "0".repeat(10 - O.length) : "") + O;
Vnum = Math.floor((Vnum - ((Vnum >>> 0)&0x3FFFFFFF)) / Math.pow(2,30));
O = (Vnum>>>0).toString(8) + O.substr(O.length - 10);
O = O.substr(O.length - 20);
O = "1" + (21 - O.length >= 0 ? padstr[ "7"].substr(0,21 - O.length) : "") + O;
O = "1" + (21 - O.length >= 0 ? "7".repeat(21 - O.length) : "") + O;
} else {
Vnum = (-Vnum) % 1e16;
var d1 = [1,8,4,4,6,7,4,4,0,7,3,7,0,9,5,5,1,6,1,6];
@ -403,8 +395,8 @@ function doit(t, args) {
if(prec ===0 && O == "0" && !(radix == 8 && alt)) O = ""; /* bail out */
else {
if(O.length < prec + (O.substr(0,1) == "-" ? 1 : 0)) {
if(O.substr(0,1) != "-") O = (prec - O.length >= 0 ? padstr[ "0"].substr(0,prec - O.length) : "") + O;
else O = O.substr(0,1) + (prec + 1 - O.length >= 0 ? padstr[ "0"].substr(0,prec + 1 - O.length) : "") + O.substr(1);
if(O.substr(0,1) != "-") O = (prec - O.length >= 0 ? "0".repeat(prec - O.length) : "") + O;
else O = O.substr(0,1) + (prec + 1 - O.length >= 0 ? "0".repeat(prec + 1 - O.length) : "") + O.substr(1);
}
/* add prefix for # form */
@ -425,10 +417,10 @@ function doit(t, args) {
if(width > 0) {
if(O.length < width) {
if(flags.indexOf("-") > -1) {
O = O + ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "");
O = O + ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "");
} else if(flags.indexOf("0") > -1 && prec < 0 && O.length > 0) {
if(prec > O.length) O = ((prec - O.length) >= 0 ? padstr[ "0"].substr(0,(prec - O.length)) : "") + O;
pad = ((width - O.length) >= 0 ? padstr[ (prec > 0 ? " " : "0")].substr(0,(width - O.length)) : "");
if(prec > O.length) O = ((prec - O.length) >= 0 ? "0".repeat((prec - O.length)) : "") + O;
pad = ((width - O.length) >= 0 ? (prec > 0 ? " " : "0").repeat((width - O.length)) : "");
if(O.charCodeAt(0) < 48) {
if(O.charAt(2).toLowerCase() == "x") O = O.substr(0,3) + pad + O.substring(3);
else O = O.substr(0,1) + pad + O.substring(1);
@ -436,7 +428,7 @@ function doit(t, args) {
else if(O.charAt(1).toLowerCase() == "x") O = O.substr(0,2) + pad + O.substring(2);
else O = pad + O;
} else {
O = ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "") + O;
O = ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "") + O;
}
}
}
@ -483,8 +475,8 @@ function doit(t, args) {
O = Vnum.toExponential(20);
E = +O.substr(O.indexOf("e")+1);
O = O.charAt(0) + O.substr(2,O.indexOf("e")-2);
O = O + (E - O.length + 1 >= 0 ? padstr[ "0"].substr(0,E - O.length + 1) : "");
if(alt || (prec > 0 && isnum !== 11)) O = O + "." + (prec >= 0 ? padstr[ "0"].substr(0,prec) : "");
O = O + (E - O.length + 1 >= 0 ? "0".repeat(E - O.length + 1) : "");
if(alt || (prec > 0 && isnum !== 11)) O = O + "." + (prec >= 0 ? "0".repeat(prec) : "");
break;
/* e/E exponential */
@ -498,7 +490,7 @@ function doit(t, args) {
/* a/A hex */
case 4:
if(Vnum===0){O= "0x0"+((alt||prec>0)?"."+(prec >= 0 ? padstr["0"].substr(0,prec) : ""):"")+"p+0"; break;}
if(Vnum===0){O= "0x0"+((alt||prec>0)?"."+(prec >= 0 ? "0".repeat(prec) : ""):"")+"p+0"; break;}
O = Vnum.toString(16);
/* First char 0-9 */
var ac = O.charCodeAt(0);
@ -545,11 +537,11 @@ function doit(t, args) {
if(prec > 0) {
O = O.substr(0, prec + 2);
if(O.length < prec + 2) {
if(O.charCodeAt(0) < 48) O = O.charAt(0) + ((prec + 2 - O.length) >= 0 ? padstr[ "0"].substr(0,(prec + 2 - O.length)) : "") + O.substr(1);
else O += ((prec + 2 - O.length) >= 0 ? padstr[ "0"].substr(0,(prec + 2 - O.length)) : "");
if(O.charCodeAt(0) < 48) O = O.charAt(0) + ((prec + 2 - O.length) >= 0 ? "0".repeat((prec + 2 - O.length)) : "") + O.substr(1);
else O += ((prec + 2 - O.length) >= 0 ? "0".repeat((prec + 2 - O.length)) : "");
}
} else if(prec === 0) O = O.charAt(0) + (alt ? "." : "");
} else if(prec > 0) O = O + "." + (prec >= 0 ? padstr["0"].substr(0,prec) : "");
} else if(prec > 0) O = O + "." + (prec >= 0 ? "0".repeat(prec) : "");
else if(alt) O = O + ".";
O = "0x" + O + "p" + (E>=0 ? "+" + E : E);
break;
@ -566,9 +558,9 @@ function doit(t, args) {
/* width */
if(width > O.length) {
if(flags.indexOf("-") > -1) {
O = O + ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "");
O = O + ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "");
} else if(flags.indexOf("0") > -1 && O.length > 0 && isf) {
pad = ((width - O.length) >= 0 ? padstr[ "0"].substr(0,(width - O.length)) : "");
pad = ((width - O.length) >= 0 ? "0".repeat((width - O.length)) : "");
if(O.charCodeAt(0) < 48) {
if(O.charAt(2).toLowerCase() == "x") O = O.substr(0,3) + pad + O.substring(3);
else O = O.substr(0,1) + pad + O.substring(1);
@ -576,7 +568,7 @@ function doit(t, args) {
else if(O.charAt(1).toLowerCase() == "x") O = O.substr(0,2) + pad + O.substring(2);
else O = pad + O;
} else {
O = ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "") + O;
O = ((width - O.length) >= 0 ? " ".repeat((width - O.length)) : "") + O;
}
}
if(c < 96) O = O.toUpperCase();

@ -7,7 +7,7 @@
var PRINTJ/*:PRINTJModule*/ = /*::(*/{}/*:: :any)*/;
PRINTJ.version = '1.2.0';
PRINTJ.version = '1.2.1';
export const version = PRINTJ.version;
@ -133,14 +133,6 @@ function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
return out;
}
//#define PAD_(x,c) (x >= 0 ? new Array(((x)|0) + 1).join((c)) : "")
var padstr/*:{[s:string]:string}*/ = {
" ": " ",
"0": "000000000000000000000000000000000",
"7": "777777777777777777777777777777777",
"f": "fffffffffffffffffffffffffffffffff"
};
var u_inspect/*:(o:any)=>string*/ = JSON.stringify;
function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
@ -190,7 +182,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
/* only valid flag is "-" for left justification */
O = String(arg);
if( prec >= 0) O = O.substr(0, prec);
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
/* first char of string or convert */
@ -205,7 +197,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
case "string": O = /*::(*/arg/*:: :string)*/.charAt(0); break;
default: O = String(arg).charAt(0);
}
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
/* int diDuUoOxXbB */
@ -293,7 +285,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
O = (arg) ? (alt ? "yes" : "true") : (alt ? "no" : "false");
if(c == /*Y*/ 89) O = O.toUpperCase();
if( prec >= 0) O = O.substr(0, prec);
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? "0".repeat( width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? " ".repeat( width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
break;
}
@ -355,16 +347,16 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
if(radix == 16 || radix == -16) {
O = (Vnum>>>0).toString(16);
Vnum = Math.floor((Vnum - (Vnum >>> 0)) / Math.pow(2,32));
O = (Vnum>>>0).toString(16) + (8 - O.length >= 0 ? padstr[ "0"].substr(0,8 - O.length) : "") + O;
O = (16 - O.length >= 0 ? padstr[ "f"].substr(0,16 - O.length) : "") + O;
O = (Vnum>>>0).toString(16) + (8 - O.length >= 0 ? "0".repeat(8 - O.length) : "") + O;
O = (16 - O.length >= 0 ? "f".repeat(16 - O.length) : "") + O;
if(radix == 16) O = O.toUpperCase();
} else if(radix == 8) {
O = (Vnum>>>0).toString(8);
O = (10 - O.length >= 0 ? padstr[ "0"].substr(0,10 - O.length) : "") + O;
O = (10 - O.length >= 0 ? "0".repeat(10 - O.length) : "") + O;
Vnum = Math.floor((Vnum - ((Vnum >>> 0)&0x3FFFFFFF)) / Math.pow(2,30));
O = (Vnum>>>0).toString(8) + O.substr(O.length - 10);
O = O.substr(O.length - 20);
O = "1" + (21 - O.length >= 0 ? padstr[ "7"].substr(0,21 - O.length) : "") + O;
O = "1" + (21 - O.length >= 0 ? "7".repeat(21 - O.length) : "") + O;
} else {
Vnum = (-Vnum) % 1e16;
var d1/*:Array<number>*/ = [1,8,4,4,6,7,4,4,0,7,3,7,0,9,5,5,1,6,1,6];
@ -385,8 +377,8 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
if(prec ===0 && O == "0" && !(radix == 8 && alt)) O = ""; /* bail out */
else {
if(O.length < prec + (O.substr(0,1) == "-" ? 1 : 0)) {
if(O.substr(0,1) != "-") O = (prec - O.length >= 0 ? padstr[ "0"].substr(0,prec - O.length) : "") + O;
else O = O.substr(0,1) + (prec + 1 - O.length >= 0 ? padstr[ "0"].substr(0,prec + 1 - O.length) : "") + O.substr(1);
if(O.substr(0,1) != "-") O = (prec - O.length >= 0 ? "0".repeat(prec - O.length) : "") + O;
else O = O.substr(0,1) + (prec + 1 - O.length >= 0 ? "0".repeat(prec + 1 - O.length) : "") + O.substr(1);
}
/* add prefix for # form */
@ -407,10 +399,10 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
if(width > 0) {
if(O.length < width) {
if(flags.indexOf("-") > -1) {
O = O