Skip to content

Commit 6f6b992

Browse files
committed
redused size
1 parent c9ec40c commit 6f6b992

File tree

4 files changed

+6
-21
lines changed

4 files changed

+6
-21
lines changed

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ Install via npm
1212
npm install jsonfromtable
1313
```
1414

15-
Install via yarn
16-
17-
```batch
18-
yarn add jsonfromtable
19-
```
20-
2115
## Usage
2216

2317
```js
@@ -30,7 +24,7 @@ jsonfromtable(options, headers).then(data => {
3024

3125
`jsonfromtable` function takes two arguments `options` and `headers` and returns promise.
3226

33-
Check this example [example](https://codesandbox.io/s/jsonfromtable-example-140hz) in codesandbox.
27+
Check this [example](https://codesandbox.io/s/jsonfromtable-example-140hz) in codesandbox.
3428

3529
## Options
3630

@@ -80,8 +74,6 @@ options = {
8074

8175
## Headers
8276

83-
If the table already has `<th>` tags then you don't need to worry about headers.
84-
8577
If the table doesn't have `<th>` tags then you need to pass headers on your own. Make sure no of items in headers in equal to the no of columns of table.
8678

8779
```js
@@ -92,4 +84,4 @@ If your table has `<th>` tags as headers but you want to pass your own header th
9284

9385
## License
9486

95-
**MIT**
87+
MIT

index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ const jsonfromtable = async (options = defaultOptions, headers) => {
2727
const $ = cheerio.load(data)
2828

2929
if ($('table').html() === null) {
30-
throw new Error(
31-
`Please provide ${url ? 'url' : 'html'} which contains table`
32-
)
30+
return []
3331
}
3432

3533
let body = toJson($, selector, headers)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonfromtable",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Generate json output from html tables",
55
"main": "index.js",
66
"repository": {

utils/tojson.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ const toJson = ($, tableSelector, _header) => {
44
let header = []
55

66
if ($(tableSelector).html() === null) {
7-
throw new Error(
8-
`${tableSelector} is not a valid selector for table, please try again`
9-
)
7+
throw new Error(`${tableSelector} is not a valid selector for table`)
108
}
119

12-
// Add headers from table to header array
1310
$(`${tableSelector} th`).each((_, el) => {
1411
header.push(
1512
$(el)
@@ -18,21 +15,19 @@ const toJson = ($, tableSelector, _header) => {
1815
)
1916
})
2017

21-
// Compare table header to header given
2218
if (_header) {
2319
header = map(header, _header)
2420
}
2521

2622
if (header.length === 0) {
2723
throw new Error(
28-
'The table do not have any headers (<th></th>), please provide array of headers as a second arguement'
24+
"The table don't have any headers (th), please provide headers as a second arguement"
2925
)
3026
}
3127

3228
let d = {},
3329
j = 0
3430

35-
// loop all tds in table
3631
$(`${tableSelector} td`).each((_, el) => {
3732
let val = $(el)
3833
.text()

0 commit comments

Comments
 (0)