UNPKG

@jswf/core

Version:

JavaScript Window Framework

90 lines 2.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function Sleep(timeout) { return new Promise(function (resolv) { setTimeout(function () { resolv(); }, timeout); }); } exports.Sleep = Sleep; var TimerProc = /** @class */ (function () { function TimerProc(proc, timeout) { this.proc = proc; this.timeout = timeout; } TimerProc.prototype.call = function (timeout) { var _this = this; if (this.handle) { window.clearTimeout(this.handle); } this.handle = window.setTimeout(function () { _this.handle = 0; _this.proc(); }, timeout || this.timeout); }; return TimerProc; }()); exports.TimerProc = TimerProc; //--------------------------------------- //書式付文字列生成 // 引数 format,・・・ // 戻り値 生成文字列 function sprintf(format) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } if (args[0] == null) return ""; var paramIndex = 0; var dest = ""; for (var i = 0; format.charAt(i); i++) { if (format.charAt(i) == "%") { var flagZero = false; var num = 0; i++; if (format.charAt(i) == "0") { flagZero = true; i++; } for (; format.charAt(i) >= "0" && format.charAt(i) <= "9"; i++) { num *= 10; num += parseInt(format.charAt(i)); } var work = void 0; var len = void 0; switch (format.charAt(i)) { case "s": work = String(args[paramIndex++]); len = num - work.length; dest += work; len = num - work.length; if (len > 0) { for (var j = 0; j < len; j++) dest += " "; } break; case "d": work = String(args[paramIndex++]); len = num - work.length; if (len > 0) { var j = void 0; var c = void 0; if (flagZero) c = "0"; else c = " "; for (j = 0; j < len; j++) dest += c; } dest += work; } } else dest += format.charAt(i); } return dest; } exports.sprintf = sprintf; //# sourceMappingURL=Libs.js.map