本文整理匯總了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);
});
示例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);
};
}
示例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);
}
示例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);
}
示例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";
});