UNPKG

html-table-to-dataframe

Version:
35 lines (34 loc) 1.49 kB
import { JSDOM } from 'jsdom'; import { DataFrameOptions, RowData } from './types'; export declare class BaseDataFrame { readonly html: string; readonly dom: JSDOM; readonly document: Document; data: RowData<string>[] | undefined; readonly options: DataFrameOptions | undefined; constructor(html: string, options?: DataFrameOptions); validateHtml(): void; /** * Validates the provided headers against the number of columns in the table. * Throws an error if the lengths do not match. * * @param headers - The headers provided by the user. * @param document - The HTML document containing the table. */ validateHeaders(headers: string[]): void; /** * Generates an array of header names from the table's thead section. * If a header element's text content is empty, it will be replaced with a unique identifier * in the format 'unknownX', where X is the number of missing headers encountered so far. * * @returns {string[]} - An array of header names, with empty headers replaced by 'unknownX'. */ generateHeaders(): string[]; /** * Cleans header text by replacing newlines and multiple spaces with a single space. * @param text - The raw text extracted from the header element (th or td). * @returns A cleaned string with normalized spaces and no line breaks. */ private cleanHeaderText; buildData<T>(rows: T[][], headers: string[]): RowData<T>[]; }