@synstack/web
Version:
Web scraping utilities
46 lines (42 loc) • 1.52 kB
TypeScript
import { ZodType, ZodTypeDef } from 'zod/v3';
import { ZodType as ZodType$1 } from 'zod/v4';
type ZodSchema<OUT = any, IN = any> = ZodType<OUT, ZodTypeDef, IN> | ZodType$1<OUT, IN>;
/**
* Retrieves an URL as JSON
* @param url
* @param options.schema an optional Zod schema to validate the data against
* @returns the JSON as a JS object
*/
declare const fetchJson: <SHAPE>(url: string, options?: {
schema?: ZodSchema<SHAPE>;
}) => Promise<SHAPE>;
/**
* Retrieves an URL as a string
* @param url
* @returns the plain text content of the URL
*/
declare const fetchText: (url: string) => Promise<string>;
/**
* Extract an article from a URL
* @param url
* @returns the article content as a JS object
*/
declare const fetchArticle: (url: string) => Promise<{
url: string;
content: string;
title: string | null | undefined;
byline: string | null | undefined;
siteName: string | null | undefined;
lang: string | null | undefined;
publishedTime: string | null | undefined;
}>;
declare class ArticleNotFoundException extends Error {
constructor(url: string);
}
declare const web_bundle_fetchArticle: typeof fetchArticle;
declare const web_bundle_fetchJson: typeof fetchJson;
declare const web_bundle_fetchText: typeof fetchText;
declare namespace web_bundle {
export { web_bundle_fetchArticle as fetchArticle, web_bundle_fetchJson as fetchJson, web_bundle_fetchText as fetchText };
}
export { ArticleNotFoundException, fetchArticle, fetchJson, fetchText, web_bundle as web };