html-content-processor
Version:
A professional library for processing, cleaning, filtering, and converting HTML content to Markdown. Features advanced customization options, presets, plugin support, fluent API, and TypeScript integration for reliable content extraction.
85 lines (84 loc) • 2.5 kB
TypeScript
/**
* DOM Adapter - Provides unified DOM API for both browser and Node.js environments
*/
export interface DOMParserInterface {
parseFromString(str: string, type: DOMParserSupportedType): Document;
}
export interface DocumentInterface {
createNodeIterator(root: Node, whatToShow?: number, filter?: NodeFilter | null): NodeIterator;
createElement(tagName: string): Element;
body: HTMLElement | null;
}
export interface WindowInterface {
DOMParser: new () => DOMParserInterface;
document: DocumentInterface;
NodeFilter: {
SHOW_COMMENT: number;
};
Node?: {
TEXT_NODE: number;
ELEMENT_NODE: number;
};
}
export declare const NODE_TYPES: {
TEXT_NODE: number;
ELEMENT_NODE: number;
COMMENT_NODE: number;
};
/**
* Main DOM Adapter with automatic environment detection
*/
declare class DOMAdapter {
private static instance;
private _window;
private _environment;
private _initialized;
private constructor();
static getInstance(): DOMAdapter;
get isNode(): boolean;
get isBrowser(): boolean;
get isWebWorker(): boolean;
private ensureInitialized;
getDOMParser(): Promise<DOMParserInterface>;
getDocument(): Promise<DocumentInterface>;
getNodeFilter(): Promise<{
SHOW_COMMENT: number;
}>;
getNode(): Promise<{
TEXT_NODE: number;
ELEMENT_NODE: number;
}>;
/**
* Parse HTML string to Document
*/
parseHTML(html: string): Promise<Document>;
/**
* Check if jsdom is available and properly loaded
*/
hasJSDOM(): Promise<boolean>;
/**
* Get environment information
*/
getEnvironmentInfo(): Promise<{
environment: string;
isNode: boolean;
isBrowser: boolean;
isWebWorker: boolean;
hasJSDOM: boolean;
hasNativeDOM: boolean;
}>;
}
export declare const domAdapter: DOMAdapter;
export declare const parseHTML: (html: string) => Promise<Document>;
export declare const getDOMParser: () => Promise<DOMParserInterface>;
export declare const getDocument: () => Promise<DocumentInterface>;
export declare const getNodeFilter: () => Promise<{
SHOW_COMMENT: number;
}>;
export declare const getNode: () => Promise<{
TEXT_NODE: number;
ELEMENT_NODE: number;
}>;
export declare const isNode: () => boolean;
export declare const isBrowser: () => boolean;
export {};