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