commit e2f282c356e25eb58ffef46434fdc0a7326c269a
parent fbb22ba8d8bbe4ec98bccb1ea61cc6fbd5560269
Author: Agastya Chandrakant <acagastya@outlook.com>
Date: Thu, 13 Jun 2019 20:14:29 +0530
Update jsonify-my-table.min.js
Diffstat:
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jsonify-my-table.min.js b/jsonify-my-table.min.js
@@ -1 +1 @@
-class jsonifyMyTable{constructor(e){if(this.table=document.getElementById(e),!this.table)return this.error=!0,void console.error("Table not found.");this.headers=[];for(let e=0;e<this.table.rows[0].cells.length;e+=1)this.headers.push(this.table.rows[0].cells[e].innerText);if(this.headers.length>new Set(this.headers).size)return this.error=!0,void console.error("Headers repeat.");this.res=[];for(let e=1;e<this.table.rows.length;e+=1){let s=[];for(let t=0;t<this.table.rows[e].cells.length;t+=1)s.push(this.table.rows[e].cells[t].innerText);let t={};this.headers.forEach((e,r)=>t={...t,[e.valueOf()]:s[r]}),this.res.push(t)}}}exports.jsonifyMyTable=jsonifyMyTable;
+class jsonifyMyTable{constructor(tableID){this.table=document.getElementById(tableID);if(!this.table){this.error=true;console.error(`Table of id "${ tableID }" not found.`);return}if(this.table.tagName!="TABLE"){this.error=true;console.error(`Element of id "${ tableID }" is not a table.`);return}this.headers=[];for(let i=0;i<this.table.rows[0].cells.length;i+=1){this.headers.push(this.table.rows[0].cells[i].innerText)}if(this.headers.length>new Set(this.headers).size){this.error=true;console.error(`Headers repeat.`);return}this.res=[];for(let i=1;i<this.table.rows.length;i+=1){let values=[];for(let j=0;j<this.table.rows[i].cells.length;j+=1){values.push(this.table.rows[i].cells[j].innerText)}let obj={};this.headers.forEach((el,index)=>(obj={...obj,[el.valueOf()]:values[index]}));this.res.push(obj)}}}exports.jsonifyMyTable=jsonifyMyTable;