当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript util.format类代码示例

本文整理汇总了TypeScript中util.format的典型用法代码示例。如果您正苦于以下问题:TypeScript format类的具体用法?TypeScript format怎么用?TypeScript format使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了format类的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;
  }
开发者ID:nertofiveone,项目名称:salesforcedx-vscode,代码行数:26,代码来源:localization.ts

示例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;
	};
开发者ID:NativeScript,项目名称:nativescript-cli,代码行数:25,代码来源:cli-layout.ts

示例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);
        }
    }
开发者ID:node-opcua,项目名称:node-opcua,代码行数:8,代码来源:redirect_to_file.ts

示例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);
}
开发者ID:tosono,项目名称:Mirakurun,代码行数:13,代码来源:log.ts

示例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);
}
开发者ID:anuragagarwal561994,项目名称:browsix,代码行数:14,代码来源:cat.ts

示例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();
    }
  }
开发者ID:Befirst-Solutions,项目名称:propel,代码行数:17,代码来源:test_browser.ts

示例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));
    }
开发者ID:furti,项目名称:jmxhealth,代码行数:17,代码来源:Logging.ts

示例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;
        }
    }

}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:20,代码来源:make_loggers.ts

示例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);
	}
开发者ID:freezy,项目名称:node-vpdb,代码行数:5,代码来源:logger.ts

示例10:

			printMarkdown: (...args: string[]): void => {
				loggedMarkdownMessages.push(format.apply(null, args));
			}
开发者ID:NathanaelA,项目名称:nativescript-cli,代码行数:3,代码来源:android-tools-info.ts


注:本文中的util.format类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。