diff --git a/README.md b/README.md index 94d34ef5..942ff435 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ Asynchronous method that runs a site wide scan. Options come in the form of an o - `concurrency` (number) - The number of connections to make simultaneously. Defaults to 100. - `port` (number) - When the `path` is provided as a local path on disk, the `port` on which to start the temporary web server. Defaults to a random high range order port. - `recurse` (boolean) - By default, all scans are shallow. Only the top level links on the requested page will be scanned. By setting `recurse` to `true`, the crawler will follow all links on the page, and continue scanning links **on the same domain** for as long as it can go. Results are cached, so no worries about loops. -- `linksToSkip` (array | function) - An array of regular expression strings that should be skipped, OR a function that's called for each link with the link URL as its only argument. Return `true` to skip the link or `false` to check it. +- `linksToSkip` (array | function) - An array of regular expression strings that should be skipped, OR an async function that's called for each link with the link URL as its only argument. Return a Promise that resolves to `true` to skip the link or `false` to check it. #### linkinator.LinkChecker() Constructor method that can be used to create a new `LinkChecker` instance. This is particularly useful if you want to receive events as the crawler crawls. Exposes the following events: diff --git a/src/index.ts b/src/index.ts index ffce8cd4..bee46a24 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,7 @@ export interface CheckOptions { port?: number; path: string; recurse?: boolean; - linksToSkip?: string[] | ((link: string) => boolean); + linksToSkip?: string[] | ((link: string) => Promise); } export enum LinkState { @@ -140,7 +140,7 @@ export class LinkChecker extends EventEmitter { // Check for a user-configured function to filter out links if ( typeof opts.checkOptions.linksToSkip === 'function' && - opts.checkOptions.linksToSkip(opts.url.href) + (await opts.checkOptions.linksToSkip(opts.url.href)) ) { const result: LinkResult = { url: opts.url.href, diff --git a/test/test.ts b/test/test.ts index f2a23909..5795aa48 100644 --- a/test/test.ts +++ b/test/test.ts @@ -51,7 +51,7 @@ describe('linkinator', () => { .reply(200); const results = await check({ path: 'test/fixtures/filter', - linksToSkip: link => link.includes('filterme'), + linksToSkip: link => Promise.resolve(link.includes('filterme')) }); assert.ok(results.passed); assert.strictEqual(