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


TypeScript array.forEach函數代碼示例

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


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

示例1: register

function register(
    counts: Entries,
    value: string,
    wasSeenAsImportedNamspace: boolean
): Entries {

    if (wasSeenAsImportedNamspace) {
        const existing = bk.at(counts, value);
        if (existing === undefined) {
            bk.addOrFail(counts, value, { name: value, count: 1, wasSeenAsImportedNamespace: true }, unableToAddInitialEntry);
        } else {
            existing.wasSeenAsImportedNamespace = true;
            existing.count += 1;
        }
    } else {
        ba.forEach(
            bx.splitAtHumps(value),
            word => {
                const value = word.toLowerCase();
                const existing = bk.at(counts, value);
                if (existing === undefined) {
                    bk.addOrFail(counts, value, { name: value, count: 1, wasSeenAsImportedNamespace: false }, unableToAddInitialEntry);
                } else {
                    existing.count += 1;
                }
            }
        );
    }

    return counts;
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:31,代碼來源:rule.ts

示例2: haveCompiled

export function betterBeNoIssues<r>(tried: TriedCompiling, haveCompiled: (compiled: Compiled) => r): r {

    if (bt.isLuck(tried)) {
        return haveCompiled(tried.luck);
    } else {

        const issues = ba.fromList(tried.fuck);
        ba.forEach(issues, issue => {
            console.warn(formatDiagnostic(issue));
        });

        return bb.fail('Stopped due to detected issues.');
    }
}
開發者ID:aleksey-bykov,項目名稱:linting,代碼行數:14,代碼來源:compiling-assertions.ts

示例3: run

function run(args: string): void {
    const optionsTried = readOptions(args);
    const { log, dump } = toBeingStandardConsoleLogging(Severity.Info);
    if (bt.isLuck(optionsTried)) {
        const options = optionsTried.luck;
        log(Severity.Info, 'Reading configuration from: ' + options.configFile);
        const configuration = loadConfigs(options.configFile);
        if (bt.isLuck(configuration)) {
            const beingLogging = toBeingStandardConsoleLogging(options.verbosity);
            const beingOpening = toBeingOpening(
                beingLogging,
                toBeingConfiguring(ts.sys.readFile, ts.sys, beingLogging)
            );
            const pivotDirPath = process.cwd(); // TODO: consider allowing a parameter
            const beingTypeScriptFormatting = toBeingTypeScriptFormatting(filePath => toRelativeTo(filePath, pivotDirPath));
            const beingLintingFormatting = toBeingLintingFormatting(beingTypeScriptFormatting);
            const shared = toShared();
            const { lint, dumpDiagnostics, dumpIssues } = toBeingLinting(beingLogging, beingOpening, toRunners, beingTypeScriptFormatting, beingLintingFormatting);
            const output = lint(options.project, shared, configuration.luck);
            if (bf.isFirst(output)) {
                dumpIssues(output.first, options.maxNumberOfIssues);
            } else if (bf.isSecond(output)) {
                dumpDiagnostics(output.second, options.maxNumberOfDiagnostics);
            } else {
                ba.forEach(
                    output.third,
                    line => log(line.severity, line.message)
                );
            }
        } else {
            log(Severity.Error, 'Unable to load the configuration of the rules. ' + configuration.fuck.message);
        }
    } else {
        const problems = optionsTried.fuck;
        log(Severity.Info, 'Unable to start the linter.');
        dump(Severity.Info, problems, bb.same);
    }
}
開發者ID:aleksey-bykov,項目名稱:linter,代碼行數:38,代碼來源:run.ts

示例4: format

 function dump<a>(severity: Severity, value: a, format: (value: a) => string[]): void {
     const lines = format(value);
     ba.forEach(lines, line => {
         log(severity, line);
     });
 }
開發者ID:aleksey-bykov,項目名稱:logging,代碼行數:6,代碼來源:being-logging-by-writing.ts


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