Fix bug and incorrect type definitions

This commit is contained in:
syuilo
2017-02-05 21:07:19 +09:00
parent 70bf14ad35
commit 4fceeb1843
2 changed files with 4 additions and 6 deletions

View File

@ -14,7 +14,7 @@ client.set('timeout', 10000);
import ISummary from './isummary';
export default async (url: URL.Url) => {
export default async (url: URL.Url): Promise<ISummary> => {
const res = await client.fetch(url.href);
if (res.error) {

View File

@ -13,7 +13,7 @@ import general from './general';
// Load builtin plugins
const builtinPlugins = requireAll({
dirname: __dirname + '/plugins'
}) as IPlugin[];
}) as { [key: string]: IPlugin };
export interface IOptions {
/**
@ -41,7 +41,7 @@ export default async (url: string, options: IOptions): Promise<Result> => {
const opts = Object.assign({
followRedirects: true,
plugins: null
}, options);
}, options) as IOptions;
const plugins = Object.keys(builtinPlugins)
.map(key => builtinPlugins[key])
@ -53,9 +53,7 @@ export default async (url: string, options: IOptions): Promise<Result> => {
const _url = URL.parse(actualUrl, true);
// Find matching plugin
const match = Object.keys(plugins)
.map(key => plugins[key])
.filter(plugin => plugin.test(_url))[0] as IPlugin;
const match = plugins.filter(plugin => plugin.test(_url))[0];
// Get summary
const summary = match