本文整理匯總了TypeScript中util.format.apply方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript format.apply方法的具體用法?TypeScript format.apply怎麽用?TypeScript format.apply使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類util.format
的用法示例。
在下文中一共展示了format.apply方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: localize
public localize(label: string, ...args: any[]): string {
const possibleLabel = this.getLabel(label);
if (!possibleLabel) {
throw new Error("Message '" + label + "' doesn't exist");
}
if (args.length >= 1) {
const expectedNumArgs = possibleLabel.split('%s').length - 1;
if (args.length !== expectedNumArgs) {
throw new Error(
'Wrong number of args for message: ' +
label +
'\nExpect ' +
expectedNumArgs +
' got ' +
args.length
);
}
args.unshift(this.messages[label]);
return util.format.apply(util, args);
}
return possibleLabel;
}
示例2: function
return function (logEvent: LoggingEvent): string {
let msg = format.apply(null, logEvent.data);
if (logEvent.context[LoggerConfigData.wrapMessageWithBorders]) {
msg = getMessageWithBorders(msg);
}
if (!logEvent.context[LoggerConfigData.skipNewLine]) {
msg += EOL;
}
if (logEvent.level.isEqualTo(LoggerLevel.INFO)) {
return msg;
}
if (logEvent.level.isEqualTo(LoggerLevel.ERROR)) {
return msg.red.bold;
}
if (logEvent.level.isEqualTo(LoggerLevel.WARN)) {
return msg.yellow;
}
return msg;
};
示例3: _write_to_file
function _write_to_file(...args: [any, ...any[]]) {
const msg = util.format.apply(null, args);
f.write(msg + "\n");
if (process.env.DEBUG) {
oldConsoleLog.call(console, msg);
}
}
示例4: getLogString
function getLogString(lvstr: string, msgs: any[]) {
let isoStr: string;
if (offsetStr) {
isoStr = new Date(Date.now() - offsetMS).toISOString();
isoStr = isoStr.slice(0, -1) + offsetStr;
} else {
isoStr = new Date().toISOString();
}
return isoStr + " " + lvstr + ": " + util.format.apply(null, msgs);
}
示例5: log
function log(fmt: string, ...args: any[]): void {
let cb: Function = undefined;
if (args.length && typeof args[args.length-1] === 'function') {
cb = args[args.length-1];
args = args.slice(0, -1);
}
let prog = process.argv[1].split('/').slice(-1);
let msg = prog + ': ' + format.apply(undefined, [fmt].concat(args)) + '\n';
if (cb)
process.stderr.write(msg, cb);
else
process.stderr.write(msg);
}
示例6: onMessage
function onMessage(msg) {
const values = msg.args.map(
v =>
v._remoteObject.value !== undefined
? v._remoteObject.value
: `[[${v._remoteObject.type}]]`
);
const text = format.apply(null, values);
console.log(prefix(text, "> "));
if (text.match(doneMsg)) {
pass();
} else {
restartTimer();
}
}
示例7: formatMessage
function formatMessage(message?: any, optionalParams?: any[]) {
if (!message) {
return;
}
if (!optionalParams || optionalParams.length === 0) {
return message;
}
var prepared = message.replace('%i', '%d')
.replace('%f', '%d')
.replace('%o', '%j')
.replace('%O', '%j')
.replace('%c', '%j');
return util.format.apply(this, [prepared].concat(optionalParams));
}
示例8: dump
function dump(mode: "E" | "D", args1: [any?, ...any[]]) {
const a2 = _.values(args1) as [string, ...string[]];
const output = format.apply(null, a2);
let a1 = [buildPrefix(mode)];
let i = 0;
for (const line of output.split("\n")) {
const lineArguments = ([] as string[]).concat(a1, [line]) as [string, ...string[]];
console.log.apply(console, lineArguments);
a1 = [continuation];
i = i + 1;
if (i > maxLines) {
const a3 = a1.concat([" .... TRUNCATED ....."]);
console.log.apply(console, a3 as [string, ...string[]]);
break;
}
}
}
示例9: debug
public debug(requestState: RequestState | null, format: any, ...param: any[]) {
const message = this.colorMessage(sprintf.apply(null, Array.from(arguments).splice(1)),
null, chalk.gray);
this.log(requestState, 'debug', message);
}
示例10:
printMarkdown: (...args: string[]): void => {
loggedMarkdownMessages.push(format.apply(null, args));
}