/** * **Note** * * The default behaviour of `scrapeURL` and `fetchTags` is to use the `fetch` implementation * provided by the `globalThis` object to download the contents of a remote url. If executing * either of these functions in an environment where `globalThis` is undefined, then the * `globalThis` object and its `fetch` implementation should be polyfilled. Similarly, if * `globalThis` is defined for your environment, but `globalThis.fetch` is not, then the * `fetch` implementation for `globalThis` should be polyfilled. * * Alternatively, an explicit configuration for `fetch` can be provided using the * `scrapeURLWithConfig` and/or `fetchTagsWithConfig` functions. * * @since 0.0.1 */ import type { Either } from 'fp-ts/Either' import type { TaskEither } from 'fp-ts/TaskEither' import type { ReaderTaskEither } from 'fp-ts/ReaderTaskEither' import type { Scraper } from './Scraper' import type { Token } from './Internal/Html/Tokenizer' /** * Represents the type signature for the global fetch API in the browser. * * @category model * @since 0.0.1 */ export declare type GlobalFetch = typeof globalThis.fetch /** * Represents a function that reads from an HTTP response and returns the * a `Promise` which resolves with the response body as a string. * * @category model * @since 0.0.1 */ export declare type ResponseDecoder = ReaderTaskEither /** * Represents a configuration object that determines how `scrapeURLWithConfig` * interacts with a remote HTTP server and interprets the results. * * @category model * @since 0.0.1 */ export interface FetchConfig { /** * An implementation of the fetch API to utilize. */ readonly fetch: GlobalFetch /** * A decoder that will decode the body of a `Response` as a string. */ readonly decoder: ResponseDecoder } /** * @category constructors * @since 0.0.1 */ export declare const FetchConfig: (fetch: GlobalFetch, decoder?: ResponseDecoder) => FetchConfig /** * Parses a raw HTML string into a list of `Token`s. * * @category utils * @since 0.0.1 */ export declare const fetchTagsRaw: (html: string) => ReadonlyArray /** * Takes a `FetchConfig` and uses the config object to download the contents of the specified * `url` and decode the response body. The decoded response body is then parsed and the * resulting list of `Token`s is returned. * * @category utils * @since 0.0.1 */ export declare const fetchTagsWithConfig: ( url: RequestInfo, init?: RequestInit ) => ReaderTaskEither> /** * Parses the contents downloaded from the specified `url` into a list of `Token`s. * * @category utils * @since 0.0.1 */ export declare const fetchTags: ( url: RequestInfo, init?: RequestInit ) => TaskEither> /** * Executes the specified `scraper` on a raw HTML string. * * @category utils * @since 0.0.1 */ export declare const scrapeRaw: (html: string) => (scraper: Scraper) => Either /** * Takes a `FetchConfig` and uses the config object to download the contents of the specified * `url` and decode the response body. The result of executing the specified `scraper` on the * decoded contents is then returned. * * @category utils * @since 0.0.1 */ export declare const scrapeURLWithConfig: ( url: RequestInfo, init?: RequestInit ) => (scraper: Scraper) => ReaderTaskEither /** * Executes the specified `scraper` on the contents downloaded from the specified `url`. * * @category utils * @since 0.0.1 */ export declare const scrapeURL: ( url: RequestInfo, init?: RequestInit ) => (scraper: Scraper) => TaskEither