• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript is-nil.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript is.undef函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap