jsonify-my-table

Convert a HTML table to JSON
git clone http://git.hanabi.in/repos/jsonify-my-table.git
Log | Files | Refs | LICENSE

jsonify-my-table.min.js (790B)


      1 HTMLTableElement.prototype.jsonify=function(){var e={error:!1};if(this.rows.length<1)return e.error="There are no rows in the table.",e;var r=[...this.rows[0].cells].map(r=>{if(0==r.childElementCount)return r.innerText;if(1==r.childElementCount){while(1==r.childElementCount)r=r.children[0];return r.innerText}e.error="Can't extract headers."});if(r.length>new Set(r).size)return e.error="Headers repeat",e;var t=[...this.rows].map((t,n)=>{if(0==n)return;var o=[...t.cells].map(r=>{if(0==r.childElementCount)return r.innerText;if(1==r.childElementCount){while(1==r.childElementCount)r=r.children[0];return r.innerText}e.error="Can't extract information."});return r.reduce((e,r,t)=>e={...e,[r.valueOf()]:o[t]},{})});return t.shift(),e.res=t,e.headers=r,e},window||(module.exports=jsonify);