Newton's Preposterous Miscalculation
Miss any of our Open RFC calls?Watch the recordings here! »

@joshuaavalon/cheerio-table-parser

2.0.2 • 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.

Install

npm i @joshuaavalon/cheerio-table-parser

DownloadsWeekly Downloads

4

Version

2.0.2

License

Apache-2.0

Unpacked Size

38.2 kB

Total Files

19

Last publish

Collaborators

  • avatar