當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript util.format函數代碼示例

本文整理匯總了TypeScript中util.format函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript format函數的具體用法?TypeScript format怎麽用?TypeScript format使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了format函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getDockerConfig

 public getDockerConfig(): string {
     var authenticationToken = new Buffer(this.username+":"+this.password).toString('base64')
     console.log("##vso[task.setvariable variable=CONTAINER_AUTHENTICATIONTOKEN;issecret=true;]" + authenticationToken);
     var auths = util.format('{"auths": { "%s": {"auth": "%s", "email": "%s" } }, "HttpHeaders":{"X-Meta-Source-Client":"%s"} }', this.registry, authenticationToken,this.email, this.xMetaSourceClient);
     return auths;
 }
開發者ID:bleissem,項目名稱:vsts-tasks,代碼行數:6,代碼來源:registryauthenticationtoken.ts

示例2: warn

 warn(firstArg: any, ...rest: Array<any>) {
   this._log('warn', format(firstArg, ...rest));
 }
開發者ID:facebook,項目名稱:jest,代碼行數:3,代碼來源:BufferedConsole.ts

示例3: executePythonTool

var workingDirectory = tl.getInput('wd', true);
var serviceEndpointId = tl.getInput('serviceEndpoint', true);
var wheel: boolean = tl.getBoolInput('wheel');
var homedir = os.homedir();
var pypircFilePath = path.join(homedir, ".pypirc");
var pythonToolPath = tl.which('python', true);
var error = '';

//Generic service endpoint
var pythonServer = tl.getEndpointUrl(serviceEndpointId, false);
var username = tl.getEndpointAuthorizationParameter(serviceEndpointId, 'username', false);
var password = tl.getEndpointAuthorizationParameter(serviceEndpointId, 'password', false);

//Create .pypirc file
var text = util.format("[distutils] \nindex-servers =\n    pypi \n[pypi] \nrepository=%s \nusername=%s \npassword=%s", pythonServer, username, password);
tl.writeFile(pypircFilePath, text, 'utf8');

(async () => {
    //PyPI upload
    try{
        tl.cd(workingDirectory);
        await executePythonTool("-m pip install twine --user");
        await executePythonTool("setup.py sdist");
        if(wheel){
            await executePythonTool("-m pip install wheel --user");
            await executePythonTool("setup.py bdist_wheel --universal");
        }
        await executePythonTool("-m twine upload dist/*");
    }
    catch(err){
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:30,代碼來源:publisher.ts

示例4: onRunComplete

  onRunComplete(contexts: Set<Context>, result: AggregatedResult): void {
    const success =
      result.numFailedTests === 0 && result.numRuntimeErrorTestSuites === 0;

    const firstContext = contexts.values().next();

    const hasteFS =
      firstContext && firstContext.value && firstContext.value.hasteFS;

    let packageName;
    if (hasteFS != null) {
      // assuming root package.json is the first one
      const [filePath] = hasteFS.matchFiles('package.json');

      packageName =
        filePath != null
          ? hasteFS.getModuleName(filePath)
          : this._globalConfig.rootDir;
    } else {
      packageName = this._globalConfig.rootDir;
    }

    packageName = packageName != null ? `${packageName} - ` : '';

    const notifyMode = this._globalConfig.notifyMode;
    const statusChanged =
      this._context.previousSuccess !== success || this._context.firstRun;
    const testsHaveRun = result.numTotalTests !== 0;

    if (
      testsHaveRun &&
      success &&
      (notifyMode === 'always' ||
        notifyMode === 'success' ||
        notifyMode === 'success-change' ||
        (notifyMode === 'change' && statusChanged) ||
        (notifyMode === 'failure-change' && statusChanged))
    ) {
      const title = util.format('%s%d%% Passed', packageName, 100);
      const message = util.format(
        (isDarwin ? '\u2705 ' : '') + '%d tests passed',
        result.numPassedTests,
      );

      notifier.notify({icon, message, title});
    } else if (
      testsHaveRun &&
      !success &&
      (notifyMode === 'always' ||
        notifyMode === 'failure' ||
        notifyMode === 'failure-change' ||
        (notifyMode === 'change' && statusChanged) ||
        (notifyMode === 'success-change' && statusChanged))
    ) {
      const failed = result.numFailedTests / result.numTotalTests;

      const title = util.format(
        '%s%d%% Failed',
        packageName,
        Math.ceil(Number.isNaN(failed) ? 0 : failed * 100),
      );
      const message = util.format(
        (isDarwin ? '\u26D4\uFE0F ' : '') + '%d of %d tests failed',
        result.numFailedTests,
        result.numTotalTests,
      );

      const watchMode = this._globalConfig.watch || this._globalConfig.watchAll;
      const restartAnswer = 'Run again';
      const quitAnswer = 'Exit tests';

      if (!watchMode) {
        notifier.notify({
          icon,
          message,
          title,
        });
      } else {
        notifier.notify(
          {
            actions: [restartAnswer, quitAnswer],
            closeLabel: 'Close',
            icon,
            message,
            title,
          },
          (err, _, metadata) => {
            if (err || !metadata) {
              return;
            }
            if (metadata.activationValue === quitAnswer) {
              exit(0);
              return;
            }
            if (metadata.activationValue === restartAnswer) {
              this._startRun(this._globalConfig);
            }
          },
        );
      }
//.........這裏部分代碼省略.........
開發者ID:facebook,項目名稱:jest,代碼行數:101,代碼來源:notify_reporter.ts

示例5: print_stat

 function print_stat() {
     t2 = Date.now();
     const str = util.format("R= %d W= %d T=%d t= %d",
       client.bytesRead, client.bytesWritten, client.transactionsPerformed, (t2 - t1));
     console.log(chalk.yellow.bold(str));
 }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:6,代碼來源:simple_client.ts

示例6: TOO_COMPLEX

export function TOO_COMPLEX() {
    let fmt = `Method table is too complex. Try reducing the number of predicates or their degree of overlap.`;
    return error(format(fmt));
}
開發者ID:yortus,項目名稱:multimethods,代碼行數:4,代碼來源:fatal-error.ts

示例7: DUPLICATE_PREDICATE

export function DUPLICATE_PREDICATE(normalised: string, predicates: string) {
    let fmt = `The predicate '%s' is duplicated across multiple methods: %s. To resolve this, use a method chain.`;
    return error(format(fmt, normalised, predicates));
}
開發者ID:yortus,項目名稱:multimethods,代碼行數:4,代碼來源:fatal-error.ts

示例8: INVALID_ARITY_OPTION

export function INVALID_ARITY_OPTION(value: any) {
    let fmt = `Expected a positive integer or undefined value for options.arity, but found %j.`;
    return error(format(fmt, value));
}
開發者ID:yortus,項目名稱:multimethods,代碼行數:4,代碼來源:fatal-error.ts

示例9: INVALID_NAME_OPTION

export function INVALID_NAME_OPTION(value: any) {
    let fmt = `Expected a valid identifier or undefined value for options.name, but found %j.`;
    return error(format(fmt, value));
}
開發者ID:yortus,項目名稱:multimethods,代碼行數:4,代碼來源:fatal-error.ts

示例10: constructor

	constructor(private $dynamicHelpService: IDynamicHelpService,
		private $injector: IInjector) {
		// Injector's dynamicCallRegex doesn't have 'g' option, which we need here.
		// Use ( ) in order to use $1 to get whole expression later
		this.dynamicCallRegex = new RegExp(util.format("(%s)", this.$injector.dynamicCallRegex.source), "g");
	}
開發者ID:telerik,項目名稱:mobile-cli-lib,代碼行數:6,代碼來源:micro-templating-service.ts

示例11: test

test('works', async (t) => {
    const url = format('http://unix:%s:%s', socketPath, '/');
    t.is((await got(url)).body, 'ok');
});
開發者ID:cyounkins,項目名稱:typed-got,代碼行數:4,代碼來源:unix-socket.ts

示例12: delete

 delete(id, callback) {
   var path = format('/v1.0/inbox/messages/%s', id);
 
   this.client.requesthandler.request('DELETE', path, null, null, 200, callback);
 };
開發者ID:Codesleuth,項目名稱:esendex-node,代碼行數:5,代碼來源:inbox.ts

示例13: update

 update(options: InboxUpdateOptions, callback: (err: any) => void) {
   var path = format('/v1.0/inbox/messages/%s', options.id);
   var query = { action: options.read ? 'read' : 'unread' };
 
   this.client.requesthandler.request('PUT', path, query, null, 200, callback);
 }
開發者ID:Codesleuth,項目名稱:esendex-node,代碼行數:6,代碼來源:inbox.ts

示例14: CliImport

export default function CliImport() {
    let err;
    let program = require('commander');
    let colors = require('colors');
    let pkg = require('../package.json');
    let util = require('util');

    program.version(pkg.version)
        .option('-c, --collection <collection>', 'The Power BI workspace collection')
        .option('-w, --workspace <workspaceId>', 'The Power BI workspace')
        .option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
        .option('-n, --displayName <displayName>', 'The dataset display name')
        .option('-f, --file <file>', 'The PBIX file to upload')
        .option('-o, --overwrite [overwrite]', 'Whether to overwrite a dataset with the same name.  Default is false')
        .option('-b --baseUri [baseUri]', 'The base uri to connect to');

    program.on('--help', function () {
        console.log('  Examples:');
        console.log('');
        console.log('    $ powerbi import -c <collection> -k <accessKey> -w <workspace> -f <file>');
    });

    program.parse(process.argv);
    let settings = config.merge(program);

    if (process.argv.length === 2) {
        program.help();
    } else {
        try {
            let options: powerbi.ImportFileOptions = {};
            let token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
            let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
            let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);

            if (!_.isUndefined(settings.overwrite) && settings.overwrite) {
                options.nameConflict = 'Overwrite';
            }

            options.datasetDisplayName = settings.displayName;

            if (!fs.existsSync(settings.file)) {
                throw new Error(util.format('File "%s" not found', settings.file));
            }

            cli.print('Importing %s to workspace: %s', settings.file, settings.workspace);

            client.imports.uploadFile(settings.collection, settings.workspace, settings.file, options, (err, result, request, response) => {
                if (err) {
                    return cli.error(err);
                }

                let importResult: powerbi.ImportModel = result;

                cli.print('File uploaded successfully');
                cli.print('Import ID: %s', importResult.id);

                checkImportState(client, importResult, (importStateErr, importStateResult) => {
                    if (importStateErr) {
                        return cli.print(importStateErr);
                    }

                    cli.print('Import succeeded');
                });
            });
        } catch (err) {
            cli.error(err);
        }
    }

    /**
     * Checks the import state of the requested import id
     */
    function checkImportState(client: powerbi.PowerBIClient, importResult: powerbi.ImportModel, callback) {
        client.imports.getImportById(settings.collection, settings.workspace, importResult.id, (err, result) => {
            importResult = result;
            cli.print('Checking import state: %s', importResult.importState);

            if (importResult.importState === 'Succeeded' || importResult.importState === 'Failed') {
                callback(null, importResult);
            } else {
                setTimeout(() => {
                    checkImportState(client, importResult, callback);
                }, 500);
            }
        });
    }
}
開發者ID:llenroc,項目名稱:PowerBI-Cli,代碼行數:87,代碼來源:cli-import.ts

示例15: PREDICATE_SYNTAX

export function PREDICATE_SYNTAX(message: string) {
    let fmt = `Predicate syntax error: %s`;
    return error(format(fmt, message));
}
開發者ID:yortus,項目名稱:multimethods,代碼行數:4,代碼來源:fatal-error.ts


注:本文中的util.format函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。