本文整理汇总了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));
}