link-preview-js
Version:
Javascript module to extract and fetch HTTP link information from blocks of text.
44 lines (43 loc) • 1.88 kB
TypeScript
import { type ILinkPreviewBaseOptions } from "./shared";
export type { ILinkPreviewResponse, IVideoType, IPreFetchedResource } from "./shared";
export { getPreviewFromContent } from "./shared";
/**
* Same options as the Node entrypoint, minus `resolveDNSHost`: it exists there to
* guard against SSRF/DNS-rebinding attacks that redirect a request to a server's own
* loopback/private network, which requires Node's `undici` to pin connections at the
* TCP layer (see node.ts). Mobile apps don't have a private network of internal
* services sitting behind localhost to protect against in the first place, and
* pulling in `undici`/`node:net` here would break bundling on React Native and other
* non-Node runtimes for a protection that isn't needed on-device.
*/
export interface ILinkPreviewOptions extends ILinkPreviewBaseOptions {
}
/**
* Parses the text, extracts the first link it finds and does a HTTP request
* to fetch the website content, afterwards it tries to parse the internal HTML
* and extract the information via meta tags.
*
* This is the mobile/browser-safe entrypoint: no Node-only dependencies, and no
* `resolveDNSHost` SSRF protection (see ILinkPreviewOptions above for why).
* @param text string, text to be parsed
* @param options ILinkPreviewOptions
*/
export declare function getLinkPreview(text: string, options?: ILinkPreviewOptions): Promise<import("./shared").ILinkPreviewResponse | {
url: string;
mediaType: string;
contentType: string;
favicons: string[];
charset: string | null;
} | {
url: string;
title: string;
siteName: string | undefined;
author: string | undefined;
description: string | undefined;
mediaType: string;
contentType: string | undefined;
images: string[];
videos: import("./shared").IVideoType[];
favicons: string[];
charset: string | null;
}>;