commit 18b9a7787ee66302da2b659ff3f84c3b19106ec6 parent e2f282c356e25eb58ffef46434fdc0a7326c269a Author: Agastya Chandrakant <acagastya@outlook.com> Date: Mon, 29 Jul 2019 12:50:28 +0530 module.exports for node Diffstat:
M | jsonify-my-table.min.js | | | 2 | +- |
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(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; +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)}}}if(!window)module.exports=jsonifyMyTable;