html-table-to-dataframe
Version:
Convert HTML tables to data-frames
44 lines (43 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toDataFrame = toDataFrame;
exports.toInteractiveDataFrame = toInteractiveDataFrame;
const data_frame_1 = require("./data-frame");
const interactive_frame_1 = require("./interactive-frame");
/**
* toDataFrame is a method, which when passed the table element via
* the data-test-id will serialize the data into a more usable object.
* The table requires the absolute header values to be processed, otherwise
* an error will be thrown.
*
* The structure should be rows of column titles and the corresponding value
* as a key/pair. Therefore a table header can be separated words e.g. "col two".
*
* | one | col two |
* | a | b |
* | c | 1 |
*
* This table will be converted and returned as a tableData:
*
* [ {"one":"a", "col two": "b"}, {"one":"c", "col two": "1"} ]
*
* NB; All values are considered strings.
*
* Call: convertHTMLTable(["one", "col two"])
*/
function toDataFrame(html, options) {
const dataFrame = new data_frame_1.DataFrame(html, options);
dataFrame.validateHtml();
if (options === null || options === void 0 ? void 0 : options.footer) {
return dataFrame.buildFooter();
}
return dataFrame.buildBody();
}
function toInteractiveDataFrame(html, options) {
const interactiveDataFrame = new interactive_frame_1.InteractiveDataFrame(html, options);
interactiveDataFrame.validateHtml();
if (options === null || options === void 0 ? void 0 : options.footer) {
return interactiveDataFrame.buildFooter();
}
return interactiveDataFrame.build();
}