jsonify-my-table

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

commit 1306cb35c28da947e6482447640d9f22985c5ef6
parent f84884c2b6e8dc1dff95cd51601f27a6b7f92b37
Author: Agastya Chandrakant <me@hanabi.in>
Date:   Thu, 21 Jan 2021 16:20:23 +0530

Explicit comparison of table row length

Diffstat:
MCHANGELOG.md | 4++++
MLICENSE | 2+-
Mjsonify-my-table.js | 2+-
Mjsonify-my-table.min.js | 2+-
Mpackage.json | 2+-
5 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.0.3 + +- Explicit comparison for the length of rows in the table. + # 2.0.2 - Support for extracting text in this format `<td><span class="bold">Foo</span></td>`. diff --git a/LICENSE b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2020, Agastya Chandrakant +Copyright (c) 2019-2021, Agastya Chandrakant All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/jsonify-my-table.js b/jsonify-my-table.js @@ -2,7 +2,7 @@ HTMLTableElement.prototype.jsonify = function() { const result = {}; result["error"] = false; // 1. Does table have rows? - if (this.rows < 1) { + if (this.rows.length < 1) { result["error"] = "There are no rows in the table."; return result; } diff --git a/jsonify-my-table.min.js b/jsonify-my-table.min.js @@ -1 +1 @@ -HTMLTableElement.prototype.jsonify=function(){var e={error:!1};if(this.rows<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); +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); diff --git a/package.json b/package.json @@ -1,6 +1,6 @@ { "name": "jsonify-my-table", - "version": "2.0.2", + "version": "2.0.3", "description": "Convert a HTML table to JSON", "main": "jsonify-my-table.js", "scripts": {