pdfkit-table
Advanced tools
Comparing version 0.1.32 to 0.1.33
64
index.js
@@ -319,2 +319,64 @@ "use strict"; | ||
module.exports = PDFDocumentWithTables; | ||
module.exports = PDFDocumentWithTables; | ||
function t2j( element ){ | ||
let head = []; | ||
let data = []; | ||
const table = element; | ||
const rows = table.rows.length; | ||
let cells = 0; | ||
let text = ''; | ||
for( var r = 0; r < rows; r++ ){ | ||
cells || (cells = table.rows[0].cells.length); | ||
let simpleRow = []; | ||
for( var c = 0; c < cells; c++ ){ | ||
text = table.rows[r].cells[c].textContent; | ||
if( r === 0 ) { | ||
head.push(text); | ||
}else { | ||
simpleRow.push(text); | ||
} | ||
} | ||
simpleRow.length && data.push(simpleRow); | ||
} | ||
return { | ||
headers: head, | ||
datas: [], | ||
rows: data, | ||
}; | ||
// console.log(head, data); | ||
// console.log(table.rows); | ||
// console.log(table.rows.length); | ||
// console.log(table.rows[0].cells); | ||
// console.log(table.rows[0].cells[0].textContent); | ||
// console.log(table.rows[0].cells[0].cellIndex); | ||
// console.log(table.rows[0].innerHTML); | ||
} | ||
function tableToJson( idElement ){ | ||
return t2j( document.getElementById(idElement) ); | ||
} | ||
function allTablesToJson(){ | ||
let all = []; | ||
const table = document.getElementsByTagName('table'); | ||
const rows = table.length; | ||
for( var r = 0; r < rows; r++ ){ | ||
all.push( t2j(table[r]) ); | ||
} | ||
return all; | ||
} | ||
module.exports.tableToJson = tableToJson; | ||
module.exports.allTablesToJson = allTablesToJson; |
{ | ||
"name": "pdfkit-table", | ||
"version": "0.1.32", | ||
"version": "0.1.33", | ||
"description": "PdfKit Table. Helps to draw informations in simple tables using pdfkit. #server-side. Generate pdf tables with javascript (PDFKIT plugin) ", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -293,4 +293,4 @@ # pdfkit-table | ||
{ name: 'size8:Will' }, | ||
// normal | ||
{ name: 'San' }, | ||
// normal | ||
{ name: 'San' }, | ||
] | ||
@@ -350,2 +350,11 @@ ``` | ||
### 0.1.33 | ||
+ Function **tableToJson** | ||
- import {tableToJson} from 'pdfkit-table'; | ||
- const table = tableToJson('#id_table'); <code>{Object}</code> | ||
+ Function **allTablesToJson** | ||
- import {allTablesToJson} from 'pdfkit-table'; | ||
- const tables = allTablesToJson(); <code>{Array}</code> | ||
### 0.1.32 | ||
@@ -386,1 +395,2 @@ | ||
- influence [voilab](https://github.com/voilab/voilab-pdf-table) | ||
- **Marcos Aurelio P. Araujo**, thanks for give me the challenge. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24779
4
295
393