Skip to content

Commit

Permalink
make linksToSkip an async function
Browse files Browse the repository at this point in the history
  • Loading branch information
zeke committed Nov 20, 2019
1 parent f3bb7ef commit f1dfd01
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface CheckOptions {
port?: number;
path: string;
recurse?: boolean;
linksToSkip?: string[] | ((link: string) => boolean);
linksToSkip?: string[] | ((link: string) => Promise<boolean>);
}

export enum LinkState {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f1dfd01

Please sign in to comment.