本文整理汇总了TypeScript中try-resolve.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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);
};
}
示例2: ReferenceError
/**
* Take Config package name, and return path to module.
* @param {string} packageName
* @returns {string} return path to module
*/
resolveConfigPackageName(packageName: string): string {
const baseDir = this.baseDirectory;
const fullPackageName = createFullPackageName(PackageNamePrefix.config, packageName);
// <plugin-name> or textlint-config-<rule-name>
const pkgPath = tryResolve(path.join(baseDir, fullPackageName)) || tryResolve(path.join(baseDir, packageName));
if (!pkgPath) {
throw new ReferenceError(`Failed to load textlint's config module: "${packageName}" is not found.
See FAQ: https://github.com/textlint/textlint/blob/master/docs/faq/failed-to-load-textlints-module.md
`);
}
return pkgPath;
}
示例3: ReferenceError
/**
* Take package name, and return path to module.
* @param {string} packageName
* @returns {string} return path to module
*/
resolvePluginPackageName(packageName: string): string {
const baseDir = this.baseDirectory;
const PREFIX = this.PLUGIN_NAME_PREFIX;
const fullPackageName = createFullPackageName(PREFIX, packageName);
// <plugin-name> or textlint-plugin-<rule-name>
const pkgPath = tryResolve(path.join(baseDir, fullPackageName)) || tryResolve(path.join(baseDir, packageName));
if (!pkgPath) {
debug(`plugin fullPackageName: ${fullPackageName}`);
throw new ReferenceError(`Failed to load textlint's plugin module: "${packageName}" is not found.
See FAQ: https://github.com/textlint/textlint/blob/master/docs/faq/failed-to-load-textlints-module.md
`);
}
return pkgPath;
}