當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。