version bump 1.3.0: memoization
This commit is contained in:
parent
a79d4e4b32
commit
7847c20022
@ -1 +1 @@
|
||||
PRINTJ.version = '1.2.3';
|
||||
PRINTJ.version = '1.3.0';
|
||||
|
@ -4,8 +4,11 @@
|
||||
#define GETCHAR c = fmt.charCodeAt(i);
|
||||
#endif
|
||||
|
||||
var tcache = {};
|
||||
|
||||
#define DRAIN(idx) if(start < idx) out.push(["L", fmt.substring(start, idx)]);
|
||||
function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
|
||||
if(tcache[fmt]) return tcache[fmt];
|
||||
var out/*:ParsedFmt*/ = [];
|
||||
var start/*:number*/ = 0;
|
||||
|
||||
@ -16,7 +19,7 @@ function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
|
||||
DRAIN(m.index)
|
||||
start = m.index + m[0].length;
|
||||
if(m[0] === "%%") out.push(["%","%"]);
|
||||
else out.push([m[6], m[0], m[1], m[2], m[3], m[4], m[5]]);
|
||||
else out.push([m[6], m[0]||"", m[1]||"", m[2]||"", m[3]||"", m[4]||"", m[5]||""]);
|
||||
}
|
||||
|
||||
#else /* NOT USE_REGEX */
|
||||
@ -74,5 +77,5 @@ function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
|
||||
#endif /* USE_REGEX */
|
||||
|
||||
if(start < fmt.length) out.push(["L", fmt.substring(start)]);
|
||||
return out;
|
||||
return (tcache[fmt] = out);
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ var u_inspect/*:(o:any)=>string*/ = (typeof util != 'undefined') ? util.inspect
|
||||
#endif
|
||||
|
||||
function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var o/*:Array<string>*/ = [];
|
||||
//var o/*:Array<string>*/ = [];
|
||||
var o = "";
|
||||
var argidx/*:number*/ = 0, idx/*:number*/ = 0;
|
||||
var Vnum/*:number*/ = 0;
|
||||
var pad/*:string*/ = "";
|
||||
@ -18,24 +19,24 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var m/*:ParsedEntry*/ = t[i], c/*:number*/ = (m[0]/*:string*/).charCodeAt(0);
|
||||
/* m order: conv full param flags width prec length */
|
||||
|
||||
if(c === /*L*/ 76) { o.push(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o.push("%"); continue; }
|
||||
if(c === /*L*/ 76) { o += /*o.push*/(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o += /*o.push*/("%"); continue; }
|
||||
|
||||
var O/*:string*/ = "";
|
||||
var isnum/*:number*/ = 0, radix/*:number*/ = 10, bytes/*:number*/ = SIZEOF_INT, sign/*:boolean*/ = false;
|
||||
|
||||
/* flags */
|
||||
var flags/*:string*/ = m[IDX_FLAGS]||"";
|
||||
var flags/*:string*/ = m[IDX_FLAGS]/*||""*/;
|
||||
var alt/*:boolean*/ = flags.indexOf("#") > -1;
|
||||
|
||||
/* position */
|
||||
if(m[IDX_POS]) argidx = parseInt(m[IDX_POS])-1;
|
||||
if(m[IDX_POS]) argidx = parseInt(m[IDX_POS], 10)-1;
|
||||
/* %m special case */
|
||||
else if(c === /*m*/ 109 && !alt) { o.push("Success"); continue; }
|
||||
else if(c === /*m*/ 109 && !alt) { o += /*.push*/("Success"); continue; }
|
||||
|
||||
#define GRAB_INT(NAME, IDX, DFL) \
|
||||
var NAME/*:number*/ = DFL; \
|
||||
if(m[IDX] != null && m[IDX].length > 0) { \
|
||||
if(/*m[IDX] != null &&*/ m[IDX].length > 0) { \
|
||||
if(m[IDX].charAt(0) !== '*') NAME = parseInt(m[IDX], 10); \
|
||||
else if(m[IDX].length === 1) NAME = args[idx++]; \
|
||||
else NAME = args[parseInt(m[IDX].substr(1), 10)-1]; \
|
||||
@ -54,7 +55,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var arg/*:any*/ = args[argidx];
|
||||
|
||||
/* grab length */
|
||||
var len/*:string*/ = m[IDX_LEN] || "";
|
||||
var len/*:string*/ = m[IDX_LEN]/* || ""*/;
|
||||
|
||||
#define INT isnum = -1
|
||||
#define SGN(s) sign = s
|
||||
@ -81,7 +82,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
#include "70_float.js"
|
||||
}
|
||||
|
||||
o.push(O);
|
||||
o += /*.push*/(O);
|
||||
}
|
||||
return o.join("");
|
||||
return o/*.join("")*/;
|
||||
}
|
||||
|
@ -11,7 +11,8 @@
|
||||
|
||||
/* store length in the `len` key */
|
||||
case /*n*/ 110:
|
||||
if(arg) { arg.len=0; for(var oo/*:number*/ = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
if(arg) { arg.len = o.length; }
|
||||
//if(arg) { arg.len=0; for(var oo/*:number*/ = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
continue;
|
||||
|
||||
/* process error */
|
||||
|
@ -25,9 +25,12 @@ var PRINTJ;
|
||||
/*jshint ignore:end */
|
||||
}(function(PRINTJ) {
|
||||
|
||||
PRINTJ.version = '1.2.2';
|
||||
PRINTJ.version = '1.3.0';
|
||||
|
||||
var tcache = {};
|
||||
|
||||
function tokenize(fmt) {
|
||||
if(tcache[fmt]) return tcache[fmt];
|
||||
var out = [];
|
||||
var start = 0;
|
||||
|
||||
@ -146,7 +149,7 @@ function tokenize(fmt) {
|
||||
}
|
||||
|
||||
if(start < fmt.length) out.push(["L", fmt.substring(start)]);
|
||||
return out;
|
||||
return (tcache[fmt] = out);
|
||||
}
|
||||
|
||||
/*global process:true, util:true, require:true */
|
||||
@ -154,7 +157,8 @@ if(typeof process !== 'undefined' && !!process.versions && !!process.versions.no
|
||||
var u_inspect = (typeof util != 'undefined') ? util.inspect : JSON.stringify;
|
||||
|
||||
function doit(t, args) {
|
||||
var o = [];
|
||||
//var o = [];
|
||||
var o = "";
|
||||
var argidx = 0, idx = 0;
|
||||
var Vnum = 0;
|
||||
var pad = "";
|
||||
@ -162,26 +166,26 @@ function doit(t, args) {
|
||||
var m = t[i], c = (m[0]).charCodeAt(0);
|
||||
/* m order: conv full param flags width prec length */
|
||||
|
||||
if(c === /*L*/ 76) { o.push(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o.push("%"); continue; }
|
||||
if(c === /*L*/ 76) { o += /*o.push*/(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o += /*o.push*/("%"); continue; }
|
||||
|
||||
var O = "";
|
||||
var isnum = 0, radix = 10, bytes = 4, sign = false;
|
||||
|
||||
/* flags */
|
||||
var flags = m[3]||"";
|
||||
var flags = m[3]/*||""*/;
|
||||
var alt = flags.indexOf("#") > -1;
|
||||
|
||||
/* position */
|
||||
if(m[2]) argidx = parseInt(m[2])-1;
|
||||
if(m[2]) argidx = parseInt(m[2], 10)-1;
|
||||
/* %m special case */
|
||||
else if(c === /*m*/ 109 && !alt) { o.push("Success"); continue; }
|
||||
else if(c === /*m*/ 109 && !alt) { o += /*.push*/("Success"); continue; }
|
||||
|
||||
/* grab width */
|
||||
var width = 0; if(m[ 4] != null && m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
var width = 0; if( m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
|
||||
/* grab precision */
|
||||
var prec = -1; if(m[ 5] != null && m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
var prec = -1; if( m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
|
||||
/* position not specified */
|
||||
if(!m[2]) argidx = idx++;
|
||||
@ -190,7 +194,7 @@ function doit(t, args) {
|
||||
var arg = args[argidx];
|
||||
|
||||
/* grab length */
|
||||
var len = m[6] || "";
|
||||
var len = m[6]/* || ""*/;
|
||||
|
||||
switch(c) {
|
||||
/* str cCsS */
|
||||
@ -276,7 +280,8 @@ function doit(t, args) {
|
||||
|
||||
/* store length in the `len` key */
|
||||
case /*n*/ 110:
|
||||
if(arg) { arg.len=0; for(var oo = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
if(arg) { arg.len = o.length; }
|
||||
//if(arg) { arg.len=0; for(var oo = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
continue;
|
||||
|
||||
/* process error */
|
||||
@ -575,9 +580,9 @@ function doit(t, args) {
|
||||
|
||||
}
|
||||
|
||||
o.push(O);
|
||||
o += /*.push*/(O);
|
||||
}
|
||||
return o.join("");
|
||||
return o/*.join("")*/;
|
||||
}
|
||||
|
||||
function vsprintf(fmt, args) { return doit(tokenize(fmt), args); }
|
||||
|
33
dist/printj.js
vendored
33
dist/printj.js
vendored
@ -25,9 +25,12 @@ var PRINTJ;
|
||||
/*jshint ignore:end */
|
||||
}(function(PRINTJ) {
|
||||
|
||||
PRINTJ.version = '1.2.3';
|
||||
PRINTJ.version = '1.3.0';
|
||||
|
||||
var tcache = {};
|
||||
|
||||
function tokenize(fmt) {
|
||||
if(tcache[fmt]) return tcache[fmt];
|
||||
var out = [];
|
||||
var start = 0;
|
||||
|
||||
@ -146,7 +149,7 @@ function tokenize(fmt) {
|
||||
}
|
||||
|
||||
if(start < fmt.length) out.push(["L", fmt.substring(start)]);
|
||||
return out;
|
||||
return (tcache[fmt] = out);
|
||||
}
|
||||
|
||||
/*global process:true, util:true, require:true */
|
||||
@ -154,7 +157,8 @@ if(typeof process !== 'undefined' && !!process.versions && !!process.versions.no
|
||||
var u_inspect = (typeof util != 'undefined') ? util.inspect : JSON.stringify;
|
||||
|
||||
function doit(t, args) {
|
||||
var o = [];
|
||||
//var o = [];
|
||||
var o = "";
|
||||
var argidx = 0, idx = 0;
|
||||
var Vnum = 0;
|
||||
var pad = "";
|
||||
@ -162,26 +166,26 @@ function doit(t, args) {
|
||||
var m = t[i], c = (m[0]).charCodeAt(0);
|
||||
/* m order: conv full param flags width prec length */
|
||||
|
||||
if(c === /*L*/ 76) { o.push(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o.push("%"); continue; }
|
||||
if(c === /*L*/ 76) { o += /*o.push*/(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o += /*o.push*/("%"); continue; }
|
||||
|
||||
var O = "";
|
||||
var isnum = 0, radix = 10, bytes = 4, sign = false;
|
||||
|
||||
/* flags */
|
||||
var flags = m[3]||"";
|
||||
var flags = m[3]/*||""*/;
|
||||
var alt = flags.indexOf("#") > -1;
|
||||
|
||||
/* position */
|
||||
if(m[2]) argidx = parseInt(m[2])-1;
|
||||
if(m[2]) argidx = parseInt(m[2], 10)-1;
|
||||
/* %m special case */
|
||||
else if(c === /*m*/ 109 && !alt) { o.push("Success"); continue; }
|
||||
else if(c === /*m*/ 109 && !alt) { o += /*.push*/("Success"); continue; }
|
||||
|
||||
/* grab width */
|
||||
var width = 0; if(m[ 4] != null && m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
var width = 0; if( m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
|
||||
/* grab precision */
|
||||
var prec = -1; if(m[ 5] != null && m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
var prec = -1; if( m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
|
||||
/* position not specified */
|
||||
if(!m[2]) argidx = idx++;
|
||||
@ -190,7 +194,7 @@ function doit(t, args) {
|
||||
var arg = args[argidx];
|
||||
|
||||
/* grab length */
|
||||
var len = m[6] || "";
|
||||
var len = m[6]/* || ""*/;
|
||||
|
||||
switch(c) {
|
||||
/* str cCsS */
|
||||
@ -276,7 +280,8 @@ function doit(t, args) {
|
||||
|
||||
/* store length in the `len` key */
|
||||
case /*n*/ 110:
|
||||
if(arg) { arg.len=0; for(var oo = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
if(arg) { arg.len = o.length; }
|
||||
//if(arg) { arg.len=0; for(var oo = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
continue;
|
||||
|
||||
/* process error */
|
||||
@ -575,9 +580,9 @@ function doit(t, args) {
|
||||
|
||||
}
|
||||
|
||||
o.push(O);
|
||||
o += /*.push*/(O);
|
||||
}
|
||||
return o.join("");
|
||||
return o/*.join("")*/;
|
||||
}
|
||||
|
||||
function vsprintf(fmt, args) { return doit(tokenize(fmt), args); }
|
||||
|
2
dist/printj.min.js
vendored
2
dist/printj.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/printj.min.map
vendored
2
dist/printj.min.map
vendored
File diff suppressed because one or more lines are too long
@ -7,11 +7,14 @@
|
||||
|
||||
var PRINTJ/*:PRINTJModule*/ = /*::(*/{}/*:: :any)*/;
|
||||
|
||||
PRINTJ.version = '1.2.3';
|
||||
PRINTJ.version = '1.3.0';
|
||||
|
||||
export const version = PRINTJ.version;
|
||||
|
||||
var tcache = {};
|
||||
|
||||
function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
|
||||
if(tcache[fmt]) return tcache[fmt];
|
||||
var out/*:ParsedFmt*/ = [];
|
||||
var start/*:number*/ = 0;
|
||||
|
||||
@ -130,13 +133,14 @@ function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
|
||||
}
|
||||
|
||||
if(start < fmt.length) out.push(["L", fmt.substring(start)]);
|
||||
return out;
|
||||
return (tcache[fmt] = out);
|
||||
}
|
||||
|
||||
var u_inspect/*:(o:any)=>string*/ = JSON.stringify;
|
||||
|
||||
function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var o/*:Array<string>*/ = [];
|
||||
//var o/*:Array<string>*/ = [];
|
||||
var o = "";
|
||||
var argidx/*:number*/ = 0, idx/*:number*/ = 0;
|
||||
var Vnum/*:number*/ = 0;
|
||||
var pad/*:string*/ = "";
|
||||
@ -144,26 +148,26 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var m/*:ParsedEntry*/ = t[i], c/*:number*/ = (m[0]/*:string*/).charCodeAt(0);
|
||||
/* m order: conv full param flags width prec length */
|
||||
|
||||
if(c === /*L*/ 76) { o.push(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o.push("%"); continue; }
|
||||
if(c === /*L*/ 76) { o += /*o.push*/(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o += /*o.push*/("%"); continue; }
|
||||
|
||||
var O/*:string*/ = "";
|
||||
var isnum/*:number*/ = 0, radix/*:number*/ = 10, bytes/*:number*/ = 4, sign/*:boolean*/ = false;
|
||||
|
||||
/* flags */
|
||||
var flags/*:string*/ = m[3]||"";
|
||||
var flags/*:string*/ = m[3]/*||""*/;
|
||||
var alt/*:boolean*/ = flags.indexOf("#") > -1;
|
||||
|
||||
/* position */
|
||||
if(m[2]) argidx = parseInt(m[2])-1;
|
||||
if(m[2]) argidx = parseInt(m[2], 10)-1;
|
||||
/* %m special case */
|
||||
else if(c === /*m*/ 109 && !alt) { o.push("Success"); continue; }
|
||||
else if(c === /*m*/ 109 && !alt) { o += /*.push*/("Success"); continue; }
|
||||
|
||||
/* grab width */
|
||||
var width = 0; if(m[ 4] != null && m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
var width = 0; if( m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
|
||||
/* grab precision */
|
||||
var prec = -1; if(m[ 5] != null && m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
var prec = -1; if( m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
|
||||
/* position not specified */
|
||||
if(!m[2]) argidx = idx++;
|
||||
@ -172,7 +176,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var arg/*:any*/ = args[argidx];
|
||||
|
||||
/* grab length */
|
||||
var len/*:string*/ = m[6] || "";
|
||||
var len/*:string*/ = m[6]/* || ""*/;
|
||||
|
||||
switch(c) {
|
||||
/* str cCsS */
|
||||
@ -258,7 +262,8 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
|
||||
/* store length in the `len` key */
|
||||
case /*n*/ 110:
|
||||
if(arg) { arg.len=0; for(var oo/*:number*/ = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
if(arg) { arg.len = o.length; }
|
||||
//if(arg) { arg.len=0; for(var oo/*:number*/ = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
continue;
|
||||
|
||||
/* process error */
|
||||
@ -557,9 +562,9 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
|
||||
}
|
||||
|
||||
o.push(O);
|
||||
o += /*.push*/(O);
|
||||
}
|
||||
return o.join("");
|
||||
return o/*.join("")*/;
|
||||
}
|
||||
|
||||
function vsprintf(fmt/*:string*/, args/*:Args*/)/*:string*/ { return doit(tokenize(fmt), args); }
|
||||
|
15
package.json
15
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "printj",
|
||||
"version": "1.2.3",
|
||||
"version": "1.3.0",
|
||||
"author": "sheetjs",
|
||||
"description": "Pure-JS printf",
|
||||
"keywords": [
|
||||
@ -22,11 +22,11 @@
|
||||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "~2.5.3",
|
||||
"blanket": "~1.2.3",
|
||||
"@sheetjs/uglify-js": "~2.7.3",
|
||||
"@types/node": "^8.0.7",
|
||||
"blanket": "~1.2.3",
|
||||
"dtslint": "^0.1.2",
|
||||
"mocha": "~2.5.3",
|
||||
"typescript": "2.2.0"
|
||||
},
|
||||
"repository": {
|
||||
@ -46,11 +46,14 @@
|
||||
},
|
||||
"alex": {
|
||||
"allow": [
|
||||
"period", "just", "special", "invalid"
|
||||
"special",
|
||||
"period",
|
||||
"just",
|
||||
"invalid"
|
||||
]
|
||||
},
|
||||
"homepage": "http://sheetjs.com/opensource",
|
||||
"files": ["printj.js", "printj.mjs", "bin/printj.njs", "LICENSE", "README.md", "dist/*.js", "dist/*.map", "dist/LICENSE", "types/index.d.ts", "types/*.json"],
|
||||
"homepage": "https://sheetjs.com/",
|
||||
"files": ["printj.js", "printj.mjs", "bin/printj.njs", "LICENSE", "README.md", "shim.js", "dist/*.js", "dist/*.map", "dist/LICENSE", "types/index.d.ts", "types/*.json"],
|
||||
"bugs": {
|
||||
"url": "https://github.com/SheetJS/printj/issues"
|
||||
},
|
||||
|
@ -28,9 +28,12 @@ var PRINTJ/*:PRINTJModule*/;
|
||||
/*jshint ignore:end */
|
||||
}(function(PRINTJ/*:PRINTJModule*/) {
|
||||
|
||||
PRINTJ.version = '1.2.3';
|
||||
PRINTJ.version = '1.3.0';
|
||||
|
||||
var tcache = {};
|
||||
|
||||
function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
|
||||
if(tcache[fmt]) return tcache[fmt];
|
||||
var out/*:ParsedFmt*/ = [];
|
||||
var start/*:number*/ = 0;
|
||||
|
||||
@ -149,7 +152,7 @@ function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
|
||||
}
|
||||
|
||||
if(start < fmt.length) out.push(["L", fmt.substring(start)]);
|
||||
return out;
|
||||
return (tcache[fmt] = out);
|
||||
}
|
||||
|
||||
/*:: var util = require('util'); */
|
||||
@ -158,7 +161,8 @@ if(typeof process !== 'undefined' && !!process.versions && !!process.versions.no
|
||||
var u_inspect/*:(o:any)=>string*/ = (typeof util != 'undefined') ? util.inspect : JSON.stringify;
|
||||
|
||||
function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var o/*:Array<string>*/ = [];
|
||||
//var o/*:Array<string>*/ = [];
|
||||
var o = "";
|
||||
var argidx/*:number*/ = 0, idx/*:number*/ = 0;
|
||||
var Vnum/*:number*/ = 0;
|
||||
var pad/*:string*/ = "";
|
||||
@ -166,26 +170,26 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var m/*:ParsedEntry*/ = t[i], c/*:number*/ = (m[0]/*:string*/).charCodeAt(0);
|
||||
/* m order: conv full param flags width prec length */
|
||||
|
||||
if(c === /*L*/ 76) { o.push(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o.push("%"); continue; }
|
||||
if(c === /*L*/ 76) { o += /*o.push*/(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o += /*o.push*/("%"); continue; }
|
||||
|
||||
var O/*:string*/ = "";
|
||||
var isnum/*:number*/ = 0, radix/*:number*/ = 10, bytes/*:number*/ = 4, sign/*:boolean*/ = false;
|
||||
|
||||
/* flags */
|
||||
var flags/*:string*/ = m[3]||"";
|
||||
var flags/*:string*/ = m[3]/*||""*/;
|
||||
var alt/*:boolean*/ = flags.indexOf("#") > -1;
|
||||
|
||||
/* position */
|
||||
if(m[2]) argidx = parseInt(m[2])-1;
|
||||
if(m[2]) argidx = parseInt(m[2], 10)-1;
|
||||
/* %m special case */
|
||||
else if(c === /*m*/ 109 && !alt) { o.push("Success"); continue; }
|
||||
else if(c === /*m*/ 109 && !alt) { o += /*.push*/("Success"); continue; }
|
||||
|
||||
/* grab width */
|
||||
var width = 0; if(m[ 4] != null && m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
var width = 0; if( m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
|
||||
/* grab precision */
|
||||
var prec = -1; if(m[ 5] != null && m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
var prec = -1; if( m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
|
||||
/* position not specified */
|
||||
if(!m[2]) argidx = idx++;
|
||||
@ -194,7 +198,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var arg/*:any*/ = args[argidx];
|
||||
|
||||
/* grab length */
|
||||
var len/*:string*/ = m[6] || "";
|
||||
var len/*:string*/ = m[6]/* || ""*/;
|
||||
|
||||
switch(c) {
|
||||
/* str cCsS */
|
||||
@ -280,7 +284,8 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
|
||||
/* store length in the `len` key */
|
||||
case /*n*/ 110:
|
||||
if(arg) { arg.len=0; for(var oo/*:number*/ = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
if(arg) { arg.len = o.length; }
|
||||
//if(arg) { arg.len=0; for(var oo/*:number*/ = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
continue;
|
||||
|
||||
/* process error */
|
||||
@ -579,9 +584,9 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
|
||||
}
|
||||
|
||||
o.push(O);
|
||||
o += /*.push*/(O);
|
||||
}
|
||||
return o.join("");
|
||||
return o/*.join("")*/;
|
||||
}
|
||||
|
||||
function vsprintf(fmt/*:string*/, args/*:Args*/)/*:string*/ { return doit(tokenize(fmt), args); }
|
||||
|
33
printj.js
33
printj.js
@ -25,9 +25,12 @@ var PRINTJ;
|
||||
/*jshint ignore:end */
|
||||
}(function(PRINTJ) {
|
||||
|
||||
PRINTJ.version = '1.2.3';
|
||||
PRINTJ.version = '1.3.0';
|
||||
|
||||
var tcache = {};
|
||||
|
||||
function tokenize(fmt) {
|
||||
if(tcache[fmt]) return tcache[fmt];
|
||||
var out = [];
|
||||
var start = 0;
|
||||
|
||||
@ -146,7 +149,7 @@ function tokenize(fmt) {
|
||||
}
|
||||
|
||||
if(start < fmt.length) out.push(["L", fmt.substring(start)]);
|
||||
return out;
|
||||
return (tcache[fmt] = out);
|
||||
}
|
||||
|
||||
/*global process:true, util:true, require:true */
|
||||
@ -154,7 +157,8 @@ if(typeof process !== 'undefined' && !!process.versions && !!process.versions.no
|
||||
var u_inspect = (typeof util != 'undefined') ? util.inspect : JSON.stringify;
|
||||
|
||||
function doit(t, args) {
|
||||
var o = [];
|
||||
//var o = [];
|
||||
var o = "";
|
||||
var argidx = 0, idx = 0;
|
||||
var Vnum = 0;
|
||||
var pad = "";
|
||||
@ -162,26 +166,26 @@ function doit(t, args) {
|
||||
var m = t[i], c = (m[0]).charCodeAt(0);
|
||||
/* m order: conv full param flags width prec length */
|
||||
|
||||
if(c === /*L*/ 76) { o.push(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o.push("%"); continue; }
|
||||
if(c === /*L*/ 76) { o += /*o.push*/(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o += /*o.push*/("%"); continue; }
|
||||
|
||||
var O = "";
|
||||
var isnum = 0, radix = 10, bytes = 4, sign = false;
|
||||
|
||||
/* flags */
|
||||
var flags = m[3]||"";
|
||||
var flags = m[3]/*||""*/;
|
||||
var alt = flags.indexOf("#") > -1;
|
||||
|
||||
/* position */
|
||||
if(m[2]) argidx = parseInt(m[2])-1;
|
||||
if(m[2]) argidx = parseInt(m[2], 10)-1;
|
||||
/* %m special case */
|
||||
else if(c === /*m*/ 109 && !alt) { o.push("Success"); continue; }
|
||||
else if(c === /*m*/ 109 && !alt) { o += /*.push*/("Success"); continue; }
|
||||
|
||||
/* grab width */
|
||||
var width = 0; if(m[ 4] != null && m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
var width = 0; if( m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
|
||||
/* grab precision */
|
||||
var prec = -1; if(m[ 5] != null && m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
var prec = -1; if( m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
|
||||
/* position not specified */
|
||||
if(!m[2]) argidx = idx++;
|
||||
@ -190,7 +194,7 @@ function doit(t, args) {
|
||||
var arg = args[argidx];
|
||||
|
||||
/* grab length */
|
||||
var len = m[6] || "";
|
||||
var len = m[6]/* || ""*/;
|
||||
|
||||
switch(c) {
|
||||
/* str cCsS */
|
||||
@ -276,7 +280,8 @@ function doit(t, args) {
|
||||
|
||||
/* store length in the `len` key */
|
||||
case /*n*/ 110:
|
||||
if(arg) { arg.len=0; for(var oo = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
if(arg) { arg.len = o.length; }
|
||||
//if(arg) { arg.len=0; for(var oo = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
continue;
|
||||
|
||||
/* process error */
|
||||
@ -575,9 +580,9 @@ function doit(t, args) {
|
||||
|
||||
}
|
||||
|
||||
o.push(O);
|
||||
o += /*.push*/(O);
|
||||
}
|
||||
return o.join("");
|
||||
return o/*.join("")*/;
|
||||
}
|
||||
|
||||
function vsprintf(fmt, args) { return doit(tokenize(fmt), args); }
|
||||
|
33
printj.mjs
33
printj.mjs
@ -7,11 +7,14 @@
|
||||
|
||||
var PRINTJ/*:PRINTJModule*/ = /*::(*/{}/*:: :any)*/;
|
||||
|
||||
PRINTJ.version = '1.2.3';
|
||||
PRINTJ.version = '1.3.0';
|
||||
|
||||
export const version = PRINTJ.version;
|
||||
|
||||
var tcache = {};
|
||||
|
||||
function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
|
||||
if(tcache[fmt]) return tcache[fmt];
|
||||
var out/*:ParsedFmt*/ = [];
|
||||
var start/*:number*/ = 0;
|
||||
|
||||
@ -130,13 +133,14 @@ function tokenize(fmt/*:string*/)/*:ParsedFmt*/ {
|
||||
}
|
||||
|
||||
if(start < fmt.length) out.push(["L", fmt.substring(start)]);
|
||||
return out;
|
||||
return (tcache[fmt] = out);
|
||||
}
|
||||
|
||||
var u_inspect/*:(o:any)=>string*/ = JSON.stringify;
|
||||
|
||||
function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var o/*:Array<string>*/ = [];
|
||||
//var o/*:Array<string>*/ = [];
|
||||
var o = "";
|
||||
var argidx/*:number*/ = 0, idx/*:number*/ = 0;
|
||||
var Vnum/*:number*/ = 0;
|
||||
var pad/*:string*/ = "";
|
||||
@ -144,26 +148,26 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var m/*:ParsedEntry*/ = t[i], c/*:number*/ = (m[0]/*:string*/).charCodeAt(0);
|
||||
/* m order: conv full param flags width prec length */
|
||||
|
||||
if(c === /*L*/ 76) { o.push(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o.push("%"); continue; }
|
||||
if(c === /*L*/ 76) { o += /*o.push*/(m[1]); continue; }
|
||||
if(c === /*%*/ 37) { o += /*o.push*/("%"); continue; }
|
||||
|
||||
var O/*:string*/ = "";
|
||||
var isnum/*:number*/ = 0, radix/*:number*/ = 10, bytes/*:number*/ = 4, sign/*:boolean*/ = false;
|
||||
|
||||
/* flags */
|
||||
var flags/*:string*/ = m[3]||"";
|
||||
var flags/*:string*/ = m[3]/*||""*/;
|
||||
var alt/*:boolean*/ = flags.indexOf("#") > -1;
|
||||
|
||||
/* position */
|
||||
if(m[2]) argidx = parseInt(m[2])-1;
|
||||
if(m[2]) argidx = parseInt(m[2], 10)-1;
|
||||
/* %m special case */
|
||||
else if(c === /*m*/ 109 && !alt) { o.push("Success"); continue; }
|
||||
else if(c === /*m*/ 109 && !alt) { o += /*.push*/("Success"); continue; }
|
||||
|
||||
/* grab width */
|
||||
var width = 0; if(m[ 4] != null && m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
var width = 0; if( m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
|
||||
|
||||
/* grab precision */
|
||||
var prec = -1; if(m[ 5] != null && m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
var prec = -1; if( m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
|
||||
|
||||
/* position not specified */
|
||||
if(!m[2]) argidx = idx++;
|
||||
@ -172,7 +176,7 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
var arg/*:any*/ = args[argidx];
|
||||
|
||||
/* grab length */
|
||||
var len/*:string*/ = m[6] || "";
|
||||
var len/*:string*/ = m[6]/* || ""*/;
|
||||
|
||||
switch(c) {
|
||||
/* str cCsS */
|
||||
@ -258,7 +262,8 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
|
||||
/* store length in the `len` key */
|
||||
case /*n*/ 110:
|
||||
if(arg) { arg.len=0; for(var oo/*:number*/ = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
if(arg) { arg.len = o.length; }
|
||||
//if(arg) { arg.len=0; for(var oo/*:number*/ = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
|
||||
continue;
|
||||
|
||||
/* process error */
|
||||
@ -557,9 +562,9 @@ function doit(t/*:ParsedFmt*/, args/*:Array<any>*/)/*:string*/ {
|
||||
|
||||
}
|
||||
|
||||
o.push(O);
|
||||
o += /*.push*/(O);
|
||||
}
|
||||
return o.join("");
|
||||
return o/*.join("")*/;
|
||||
}
|
||||
|
||||
function vsprintf(fmt/*:string*/, args/*:Args*/)/*:string*/ { return doit(tokenize(fmt), args); }
|
||||
|
Loading…
Reference in New Issue
Block a user