@jsdevtools/rehype-url-inspector
Version:
A rehype plugin to inspect, validate, or rewrite URLs anywhere in an HTML document
45 lines (44 loc) • 1.48 kB
TypeScript
import { UrlExtractor, UrlMatch, UrlSelector } from "./types";
/**
* Options for the Rehype Validate URLs plugin
*/
export interface Options {
/**
* Selectors indicate where to look for URLs in the document. Each selector can be a CSS attribute
* selector string, like `a[href]` or `img[src]`, or a function that accepts a HAST node and
* returns its URL(s).
*/
selectors?: Array<string | UrlSelector | UrlExtractor>;
/**
* Whether to keep the default selectors in addition to any custom ones.
*
* Defaults to `false`.
*/
keepDefaultSelectors?: boolean;
/**
* Inspects all the URLs in the document.
*/
inspect?(urls: UrlMatch[]): void;
/**
* Inspects each URL in the document as it is found.
*
* @returns
* Return a falsy value (other than `undefined`) to skip the rest of the URLs in the document.
* Return a truthy value (or no value at all) to continue.
*/
inspectEach?(url: UrlMatch): unknown;
}
/**
* Normalized, sanitized, and complete settings,
* with default values for anything that wasn't specified by the caller.
*/
export declare class NormalizedOptions {
readonly selectors: UrlSelector[];
readonly extractors: UrlExtractor[];
readonly inspect?: (urls: UrlMatch[]) => void;
readonly inspectEach?: (url: UrlMatch) => unknown;
/**
* Applies default values for any unspecified options
*/
constructor(options?: Options);
}