@joshuaavalon/cheerio-table-parser
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

Cheerio Table Parser

License Pipelines Coverage NPM

Parsing table element of Cheerio into 2D array.

Installation

npm install @joshuaavalon/cheerio-table-parser

Usage

import cheerio from "cheerio";
import { parseTable } from "@joshuaavalon/cheerio-table-parser";

const dom = cheerio.load(html);
table = parseTable(dom("table")[0], {
  parser: (element) => cheerio(element).text(),
});

/*
[
  ["A", "B", "C", "D", "E"],
  ["1a", "2a", "3a", "4a", "5a"],
  ["1a", "2b", "2b", "4b", "5b"],
  ["1a", "2b", "2b", "4c", "5c"],
  ["1a", "2d", "3d", "4c", "5d"],
  ["1a", "2d", "3e", "4e", "5e"]
]
*/

Known Issues

Overlapping Cell

According to HTML table specifications, it depends on how user agent render the table. Most browsers render it as overlapping cell.

However, this is not possible in this library. Therefore, it will favour rowspan over colspan.

Handle thead, tbody, tfoot

<thead>, <tbody>, <tfoot> should be handled separately. This is not consider in this library. However, you can pass in <tbody> instead of <table> separately.

Package Sidebar

Install

npm i @joshuaavalon/cheerio-table-parser

Weekly Downloads

15

Version

2.0.3

License

Apache-2.0

Unpacked Size

38.9 kB

Total Files

19

Last publish

Collaborators

  • joshuaavalon