New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@eirikb/normalize-html-table

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eirikb/normalize-html-table

Normalization of DOM table rows - creates a matrix with duplicate cells based on rowspan and colspan

  • 1.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

npm Build

normalize-html-table

Normalization of DOM table rows - creates a matrix with duplicate cells based on rowspan and colspan.
Handy for scraping and parsing of Wikipedia tables.

  • Vanilla DOM - no dependencies.
  • Does one job only - rowspan and colspan.

Usage

npm i @eirikb/normalize-html-table
import normalizeHtmlTable from '@eirikb/normalize-html-table';

const table = document.querySelector('table');
const rows = normalizeHtmlTable(table);
console.log(rows);

This will return a matrix of rows and cells. Each cell contains the td element.
Each row will have a property row attached to them, in case you need to reference the original tr element.
E.g.,

  console.log(rows[0].row); // tr element

Notes

This library will not:

  • Map your table to a JavaScript object.
  • Do anything with your headers.
  • Convert cells to text.
  • Support older browsers (you must transpile it).

All above can be solved by you, and does not fit into this library. E.g., converting to JavaScript object with cells turned into text can be done like this:

function tableToJson(table) {
  const headers = [...table.querySelectorAll('th')].map(th => th.textContent.trim());
  return normalizeHtmlTable(table).map(row =>
    headers.reduce((res, header, index) => {
      res[header] = row[index].textContent.trim();
      return res;
    }, {})
  );
}

For nodejs support use jsdom.

Keywords

FAQs

Package last updated on 01 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc