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


TypeScript is-file.default函数代码示例

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


在下文中一共展示了default函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getTextlintDependencyNames

 return getTextlintDependencyNames(dir).then(pkgNames => {
     const rcFile = `.${Config.CONFIG_FILE_NAME}rc`;
     const filePath = path.resolve(dir, rcFile);
     if (isFile(filePath)) {
         Logger.error(`${rcFile} is already existed.`);
         return Promise.resolve(1);
     }
     const filters = pkgNames
         .filter(pkgName => {
             return pkgName.indexOf(TextlintPackageNamePrefix.filterRule) !== -1;
         })
         .map(filterName => {
             return filterName.replace(TextlintPackageNamePrefix.filterRule, "");
         });
     const rules = pkgNames
         .filter(pkgName => {
             return pkgName.indexOf(TextlintPackageNamePrefix.rule) !== -1;
         })
         .map(filterName => {
             return filterName.replace(TextlintPackageNamePrefix.rule, "");
         });
     const defaultTextlintRc = {
         filters: arrayToObject(filters, true),
         rules: arrayToObject(rules, true)
     };
     const output = JSON.stringify(defaultTextlintRc, null, 2);
     fs.writeFileSync(filePath, output);
     if (options.verbose) {
         Logger.log(`${rcFile} is created.`);
     }
     return Promise.resolve(0);
 });
开发者ID:textlint,项目名称:textlint,代码行数:32,代码来源:config-initializer.ts

示例2: createFormatter

export function createFormatter(formatterConfig: FormatterConfig) {
    const formatterName = formatterConfig.formatterName;
    debug(`formatterName: ${formatterName}`);
    let formatter: (results: TextlintResult[], formatterConfig: FormatterConfig) => string;
    let formatterPath;
    if (fs.existsSync(formatterName)) {
        formatterPath = formatterName;
    } else if (fs.existsSync(path.resolve(process.cwd(), formatterName))) {
        formatterPath = path.resolve(process.cwd(), formatterName);
    } else {
        if (isFile(`${path.join(__dirname, "formatters/", formatterName)}.js`)) {
            formatterPath = `${path.join(__dirname, "formatters/", formatterName)}.js`;
        } else if (isFile(`${path.join(__dirname, "formatters/", formatterName)}.ts`)) {
            formatterPath = `${path.join(__dirname, "formatters/", formatterName)}.ts`;
        } else {
            const pkgPath = tryResolve(`textlint-formatter-${formatterName}`) || tryResolve(formatterName);
            if (pkgPath) {
                formatterPath = pkgPath;
            }
        }
    }
    try {
        formatter = interopRequire(formatterPath);
    } catch (ex) {
        throw new Error(`Could not find formatter ${formatterName}
${ex}`);
    }
    return function(results: TextlintResult[]) {
        return formatter(results, formatterConfig);
    };
}
开发者ID:textlint,项目名称:textlint,代码行数:31,代码来源:index.ts

示例3: loadFilterRule

 /**
  * load filter rule file with `ruleName` and define rule.
  * if rule is not found, then throw ReferenceError.
  * if already rule is loaded, do not anything.
  * @param {string} ruleName
  */
 loadFilterRule(ruleName: string) {
     /*
        Task
          - check already define
          - resolve package name
          - load package
          - emit rule
     */
     // ignore already defined rule
     // ignore rules from rulePaths because avoid ReferenceError is that try to require.
     if (isFile(ruleName)) {
         const ruleCreator = interopRequire(ruleName);
         const ruleEntry = [ruleName, ruleCreator];
         this.emit(TextLintModuleLoader.Event.filterRule, ruleEntry);
         return;
     }
     const RULE_NAME_PREFIX = this.config.constructor.FILTER_RULE_NAME_PREFIX;
     const prefixMatch = new RegExp(`^${RULE_NAME_PREFIX}`);
     const definedRuleName = ruleName.replace(prefixMatch, "");
     // ignore plugin's rule
     if (isPluginRuleKey(definedRuleName)) {
         Logger.warn(`${definedRuleName} is Plugin's rule. This is unknown case, please report issue.`);
         return;
     }
     const pkgPath = this.moduleResolver.resolveFilterRulePackageName(ruleName);
     debug("Loading filter rules from %s", pkgPath);
     const ruleCreator = interopRequire(pkgPath);
     const ruleEntry = [definedRuleName, ruleCreator];
     this.emit(TextLintModuleLoader.Event.filterRule, ruleEntry);
 }
开发者ID:,项目名称:,代码行数:36,代码来源:

示例4: loadFilterRule

 /**
  * load filter rule file with `ruleName` and define rule.
  * if rule is not found, then throw ReferenceError.
  * if already rule is loaded, do not anything.
  * @param {string} ruleName
  */
 loadFilterRule(ruleName: string) {
     /*
        Task
          - check already define
          - resolve package name
          - load package
          - emit rule
     */
     // ignore already defined rule
     // ignore rules from rulePaths because avoid ReferenceError is that try to require.
     if (isFile(ruleName)) {
         const ruleCreator = interopRequire(ruleName);
         const ruleEntry = [ruleName, ruleCreator];
         this.emit(TextLintModuleLoader.Event.filterRule, ruleEntry);
         return;
     }
     const definedRuleName = normalizeTextlintFilterRuleKey(ruleName);
     // ignore plugin's rule
     if (isPluginRuleKey(definedRuleName)) {
         Logger.warn(`${definedRuleName} is Plugin's rule. This is unknown case, please report issue.`);
         return;
     }
     const pkgPath = this.moduleResolver.resolveFilterRulePackageName(ruleName);
     debug("Loading filter rules from %s", pkgPath);
     const ruleCreator = interopRequire(pkgPath);
     const ruleEntry = [definedRuleName, ruleCreator];
     this.emit(TextLintModuleLoader.Event.filterRule, ruleEntry);
 }
开发者ID:textlint,项目名称:textlint,代码行数:34,代码来源:textlint-module-loader.ts

示例5: if

    results.forEach(function(result) {
        const filePath = result.filePath;
        const messages = result.applyingMessages;
        // still error count
        const remainingMessages = result.remainingMessages;
        errors += remainingMessages.length;
        totalFixed += messages.length;
        if (messages.length === 0) {
            return;
        }
        if (!isFile(filePath)) {
            return;
        }
        output += `${chalk.underline(result.filePath)}\n`;

        const originalContent = fs.readFileSync(filePath, "utf-8");
        const diff = jsdiff.diffLines(originalContent, result.output);

        diff.forEach(function(part: any, index: number) {
            const prevLine = diff[index - 1];
            const nextLine = diff[index + 1];
            if (!isModified(part) && part.count > 1) {
                const greyColor = "grey";
                /*
                    <MODIFIED>
                    first line
                    ....
                 */
                if (isModified(prevLine)) {
                    const lines = part.value.split("\n");
                    output += `${chalk[greyColor](lines[0])}\n`;
                }
                output += chalk[greyColor]("...");
                if (isModified(nextLine)) {
                    const lines = part.value.split("\n");
                    output += `${chalk[greyColor](lines[lines.length - 1])}\n`;
                }
                /*
                    ...
                    last line
                    <MODIFIED>
                 */
                return;
            }
            // green for additions, red for deletions
            // grey for common parts
            let lineColor;
            let diffMark = "";
            if (part.added) {
                lineColor = "green";
                diffMark = "+ ";
            } else if (part.removed) {
                lineColor = "red";
                diffMark = "- ";
            } else {
                lineColor = "grey";
                diffMark = "";
            }
            output += chalk[lineColor](addMarkEachLine(diffMark, part.value));
        });
        output += "\n\n";
    });
开发者ID:textlint,项目名称:textlint,代码行数:62,代码来源:diff.ts


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