Gathering detailed insights and metrics for html-table-to-dataframe
Gathering detailed insights and metrics for html-table-to-dataframe
Gathering detailed insights and metrics for html-table-to-dataframe
Gathering detailed insights and metrics for html-table-to-dataframe
npm install html-table-to-dataframe
Typescript
Module System
Node Version
NPM Version
68.5
Supply Chain
96.5
Quality
84.3
Maintenance
100
Vulnerability
98.6
License
TypeScript (83.21%)
HTML (15.57%)
JavaScript (1.22%)
Total Downloads
3,872
Last Day
2
Last Week
30
Last Month
137
Last Year
3,872
Apache-2.0 License
1 Stars
126 Commits
2 Watchers
1 Branches
3 Contributors
Updated on Nov 15, 2024
Latest Version
1.0.37
Package Id
html-table-to-dataframe@1.0.37
Unpacked Size
78.11 kB
Size
17.18 kB
File Count
21
NPM Version
10.7.0
Node Version
18.20.4
Published on
Nov 15, 2024
Cumulative downloads
Total Downloads
Last Day
0%
2
Compared to previous day
Last Week
500%
30
Compared to previous week
Last Month
67.1%
137
Compared to previous month
Last Year
0%
3,872
Compared to previous year
Convert an HTML Table to a DataFrame
This project provides utilities to convert HTML tables into structured data formats and pretty-print them as tables. It uses jsdom
for parsing HTML and cli-table3
for displaying data in a formatted table.
Usage:
Person | Like | Age |
---|---|---|
Chris | HTML tables | 22 |
Dennis | Web accessibility | 45 |
Sarah | JavaScript frameworks | 29 |
Karen | Web performance | 36 |
1import { toDataFrame } from 'html-table-to-dataframe'; 2 3const dataFrame = toDataFrame(htmlString, ['Person', 'Likes', 'Age']); 4 5console.log(dataFrame) 6// data => [ 7// { Person: "Chris", Likes: "HTML tables", Age: "22" }, 8//]; 9 10await toPrettyPrint(data); 11
1┌─────────┬──────────────────────┬─────┐ 2│ Person │ Likes │ Age │ 3├─────────┼──────────────────────┼─────┤ 4│ Chris │ HTML tables │ 22 │ 5│ Dennis │ Web accessibility │ 45 │ 6│ Sarah │ JavaScript frameworks│ 29 │ 7│ Karen │ Web performance │ 36 │ 8└─────────┴──────────────────────┴─────┘
The toDataFrame function converts an HTML string into a data frame structure, which is an array of objects where each object represents a row in the table. This function is essential for transforming raw HTML tables into a format that can be easily manipulated and tested.
Checks if a single row in the table has the specified value in a given column.
1const tableData = [ 2 { col_1: '1', col_2: '3' } 3]; 4 5toHaveColumnToBeValue(tableData, 'col_2', '3'); // Passes, as the value in 'col_2' is '3'
Checks if the table contains more rows than the specified count.
1const tableData = [ 2 { one: '1', two: '3' }, 3 { one: '2', two: '100' } 4]; 5 6toHaveTableRowCountGreaterThan(tableData, 3); // Fails, as row count is 2
Checks if the values in the specified column match the given regular expression pattern.
1const tableData = [ 2 { one: '1', two: '3' }, 3 { one: '2', two: '100' } 4]; 5 6toHaveColumnValuesToMatchRegex(tableData, "two", "\\d\\d"); // Fails, as {"two":"100"} has 3 digits 7toHaveColumnsValuesToMatchRegex(tableData, ["one", "two"], "\\d\\d"); // Fails, as {"two":"100"} has 3 digits
Checks if the values in the specified column fall within the given range.
1const tableData = [ 2 { one: '1', two: '3' }, 3 { one: '2', two: '100' } 4]; 5 6toHaveColumnValuesToBeInRange(tableData, "two", 0, 4); // Fails, as {"two":"100"} is greater than 4
Checks if the values in the specified column are numbers.
1const tableData = [ 2 { one: '1', two: '3' }, 3 { one: '2', two: '1e' } 4]; 5 6toHaveColumnValuesToBeNumbers(tableData, "two"); // Fails, as {"two":"1e"} is not a number
Checks if a target column/value pair exists when filtered by a specified column/value.
1const tableData = [ 2 { col_1: '1', col_2: '3' }, 3 { col_1: '2', col_2: '1e' } 4]; 5 6toHaveColumnToMatchWhenFilteredBy(tableData, "col_1", "2", "col_2", "xyz"); 7// Fails, as {"col_1":"2"} is found, but {"col_2":"xyz"} is not
Uses an array of GroupType
to check if a target column/value pair exists when filtered by each specified column/value.
1type GroupType = { 2 filterColumn: string; 3 filterValue: string; 4}; 5 6const tableData = [ 7 { col_1: '1', col_2: 'a', col_3: 'b' } 8]; 9 10const group: GroupType[] = [ 11 { filterColumn: "col_2", filterValue: "a" }, 12 { filterColumn: "col_3", filterValue: "a" } 13]; 14 15toHaveColumnToMatchGroupWhenFilteredBy(tableData, "col_1", "1", group); 16// Fails, as {"col_2": "a"} is OK; however, {"col_3": "a"} should be "b"
Confirms that a specified column no longer contains a certain value. This is useful for checking if a row has been deleted or archived.
1const tableData = [ 2 { col_1: '1', col_2: '3' }, 3 { col_1: '2', col_2: '1e' } 4]; 5 6toHaveColumnToNotMatch(tableData, "col_1", "2"); 7// Fails, as {"col_1":"2"} is found and should not be.
Matches the row count of the table data against the expected value.
1const tableData = [ 2 { col_1: '1', col_2: '3' }, 3 { col_1: '2', col_2: '1e' } 4]; 5 6toHaveTableRowCount(tableData, 3); 7// Fails, as row count should be 2.
Expects only 1 table row and checks if the column value matches the provided value.
1const tableData = [ 2 { col_1: '1', col_2: '3' } 3]; 4 5toHaveColumnToBeValue(tableData, "col_2", "3"); 6// Passes, as the column value is "3".
Expects only 1 table row and checks if the column values in a group match the provided values. Exceptions are made when the filter value is null or undefined.
1const tableData = [ 2 { col_1: '1', col_2: '3' } 3]; 4 5const filterGroup = [ 6 { filterColumn: "col_2", filterValue: "3" } 7]; 8 9toHaveColumnGroupToBeValue(tableData, filterGroup); 10// Passes, as the column value for "col_2" is "3".
Performs multiple grouped checks using toHaveColumnGroupToBeValue
for each row. The tableData
must be the same length as the filterGroups
, and each entry in filterGroups
is applied to the corresponding row in tableData
.
1const tableData = [ 2 { col_1: '1', col_2: '3' }, 3 { col_1: '2', col_2: '4' } 4]; 5 6const filterGroups = [ 7 [{ filterColumn: "col_2", filterValue: "3" }], 8 [{ filterColumn: "col_2", filterValue: "4" }] 9]; 10toHaveColumnGroupToBeValues(tableData, filterGroups); 11// Passes, as the column values match the expected values for each row.
Converts two tables into strings and compares them for equality. This assertion checks that the two tables do not match exactly.
1const tableData1 = [ 2 { col_1: '1', col_2: '3' } 3]; 4 5const tableData2 = [ 6 { col_1: '1', col_2: '3' } 7]; 8 9toHaveTableToNotMatch(tableData1, tableData2); 10// Fails, as the two tables are identical
Converts two tables into strings and compares them for equality. This assertion checks that the two tables match exactly.
1const tableData1 = [ 2 { col_1: '1', col_2: '3' } 3]; 4 5const tableData2 = [ 6 { col_1: '1', col_2: '4' } 7]; 8toHaveTableToMatch(tableData1, tableData2); 9// Fails, as the two tables are different
Check the length of the table is equal to
1const tableData = [ 2 { col_1: '1', col_2: '3' }, 3 { col_1: '2', col_2: '4' } 4]; 5 6toHaveTableRowCountEqualTo(tableData, 3); 7// Fails, as the tables are length of 2
Check the length of the table is equal to
1const tableData = [ 2 { col_1: '1', col_2: '3' }, 3 { col_1: '2', col_2: '4' } 4]; 5 6toHaveTableRowCountLessThan(tableData, 1); 7// Fails, as the tables are length of 2
No vulnerabilities found.