tabletojson
Advanced tools
Comparing version 4.1.1 to 4.1.2
@@ -283,4 +283,13 @@ "use strict"; | ||
} | ||
else if (typeof callbackFunctionOrOptions === 'object') { | ||
options = callbackFunctionOrOptions; | ||
const result = yield fetch(url, callbackFunctionOrOptions.fetchOptions || {}); | ||
const resultMimetype = result.headers.get('content-type'); | ||
if (resultMimetype && !resultMimetype.includes('text/')) { | ||
throw new Error('Tabletojson can just handle text/** mimetypes'); | ||
} | ||
return Tabletojson.convert(yield result.text(), options); | ||
} | ||
else { | ||
options = callbackFunctionOrOptions || {}; | ||
options = {}; | ||
fetchOptions = options.fetchOptions || {}; | ||
@@ -287,0 +296,0 @@ const result = yield fetch(url); |
@@ -247,4 +247,13 @@ import * as cheerio from 'cheerio'; | ||
} | ||
else if (typeof callbackFunctionOrOptions === 'object') { | ||
options = callbackFunctionOrOptions; | ||
const result = await fetch(url, callbackFunctionOrOptions.fetchOptions || {}); | ||
const resultMimetype = result.headers.get('content-type'); | ||
if (resultMimetype && !resultMimetype.includes('text/')) { | ||
throw new Error('Tabletojson can just handle text/** mimetypes'); | ||
} | ||
return Tabletojson.convert(await result.text(), options); | ||
} | ||
else { | ||
options = callbackFunctionOrOptions || {}; | ||
options = {}; | ||
fetchOptions = options.fetchOptions || {}; | ||
@@ -251,0 +260,0 @@ const result = await fetch(url); |
@@ -391,5 +391,15 @@ import * as cheerio from 'cheerio'; | ||
return callbackFunctionOrOptions.call(this, Tabletojson.convert(await result.text())); | ||
} else if (typeof callbackFunctionOrOptions === 'object') { | ||
// If neither argument is callback, return a promise | ||
options = callbackFunctionOrOptions; | ||
// Use a callback (if passed) | ||
const result = await fetch(url, callbackFunctionOrOptions.fetchOptions || {}); | ||
const resultMimetype = result.headers.get('content-type'); | ||
if (resultMimetype && !resultMimetype.includes('text/')) { | ||
throw new Error('Tabletojson can just handle text/** mimetypes'); | ||
} | ||
return Tabletojson.convert(await result.text(), options); | ||
} else { | ||
// If neither argument is callback, return a promise | ||
options = callbackFunctionOrOptions || {}; | ||
options = {}; | ||
// If you need to pass in options for request (proxy) | ||
@@ -396,0 +406,0 @@ // add them to callbackFunctionOrOptions.request |
@@ -8,3 +8,3 @@ { | ||
"name": "tabletojson", | ||
"version": "4.1.1", | ||
"version": "4.1.2", | ||
"description": "Convert HTML tables to JSON objects", | ||
@@ -59,11 +59,11 @@ "main": "dist/lib/cjs/Tabletojson.js", | ||
"@types/lodash": "^4.14.202", | ||
"@types/node": "^20.11.17", | ||
"@types/node": "^20.11.25", | ||
"@types/supertest": "^6.0.2", | ||
"@typescript-eslint/eslint-plugin": "^6.21.0", | ||
"@typescript-eslint/parser": "^6.21.0", | ||
"@typescript-eslint/eslint-plugin": "^7.1.1", | ||
"@typescript-eslint/parser": "^7.1.1", | ||
"chokidar": "^3.6.0", | ||
"config": "^3.3.11", | ||
"eslint": "^8.56.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-jest": "^27.6.3", | ||
"eslint-plugin-jest": "^27.9.0", | ||
"eslint-plugin-prefer-arrow": "^1.2.3", | ||
@@ -76,3 +76,3 @@ "eslint-plugin-prettier": "^5.1.3", | ||
"markdown-toc": "^1.2.0", | ||
"nock": "^13.5.1", | ||
"nock": "^13.5.4", | ||
"npm-run-all": "^4.1.5", | ||
@@ -79,0 +79,0 @@ "prettier": "^3.2.5", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
200237
1085
8