From 47a49bc37915ee38761ae21d8bbb932378de4c6d Mon Sep 17 00:00:00 2001 From: Ron Nuss Date: Mon, 28 Aug 2023 11:26:33 +0300 Subject: [PATCH 1/2] fix(askTheRabbi): answer resolve to correct text --- package-lock.json | 19 +++++++++++++++++-- package.json | 1 + src/askTheRabbi/index.ts | 15 +++++++-------- test/allTests.test.ts | 1 + 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 76da338..1330d17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,17 @@ { "name": "hidabroot", - "version": "0.6.4-beta", + "version": "0.8.0-beta", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "hidabroot", - "version": "0.6.4-beta", + "version": "0.8.0-beta", "license": "MIT", "dependencies": { "@testdeck/mocha": "^0.3.3", "cheerio": "^1.0.0-rc.12", + "hidabroot": "^0.8.0-beta", "nyc": "^15.1.0", "ts-mockito": "^2.6.1" }, @@ -1356,6 +1357,20 @@ "he": "bin/he" } }, + "node_modules/hidabroot": { + "version": "0.8.0-beta", + "resolved": "https://registry.npmjs.org/hidabroot/-/hidabroot-0.8.0-beta.tgz", + "integrity": "sha512-FnSE/aA09+WryInwyOPefnlxQxWG4QJOcn3nueDHDGYl8QQfpTeRU7XNdpzt7GWwXt1G4MtogaFDeToyct9Gdw==", + "dependencies": { + "@testdeck/mocha": "^0.3.3", + "cheerio": "^1.0.0-rc.12", + "nyc": "^15.1.0", + "ts-mockito": "^2.6.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", diff --git a/package.json b/package.json index bce7e85..459ae09 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "dependencies": { "@testdeck/mocha": "^0.3.3", "cheerio": "^1.0.0-rc.12", + "hidabroot": "^0.8.0-beta", "nyc": "^15.1.0", "ts-mockito": "^2.6.1" } diff --git a/src/askTheRabbi/index.ts b/src/askTheRabbi/index.ts index 7a1d0d7..1dce1f2 100644 --- a/src/askTheRabbi/index.ts +++ b/src/askTheRabbi/index.ts @@ -34,19 +34,18 @@ export async function askTheRabbi( const formattedQuestion = question.text().replace(/\s+/g, " ").replace(/
/g, "\n") || ""; // gets the whole div with id "article_inner" and save only the answer div in the answer variable - const answer = $("[id=article_inner]").contents().eq(1); + const answer = $("[id=article_inner]").contents().eq(3); // format the answer div text content - const formattedAnswer = - answer.text().replace(/\s+/g, " ").replace(/
/g, "\n") || ""; - // saves the json response - const jsonResponse = { + const formattedAnswer = answer + .text() + .replace(/
/g, "\n") + .replace(/\s+/g, " ") + .trim(); + return { title: header, question: formattedQuestion, answer: formattedAnswer, }; - - // returns the json response - return jsonResponse; } }) .catch((error) => { diff --git a/test/allTests.test.ts b/test/allTests.test.ts index 169f1f9..a475e5d 100644 --- a/test/allTests.test.ts +++ b/test/allTests.test.ts @@ -33,6 +33,7 @@ describe("askTheRabbi function", () => { it("should return a json with 2 string keys - question and answer", async () => { const questionID = 325090; const response = await askTheRabbi(questionID); + console.log(response); expect(response).to.be.an("object"); }); From 0f10fb7bd560216e1579c4c98e1256a26db474e9 Mon Sep 17 00:00:00 2001 From: Ron Nuss Date: Mon, 28 Aug 2023 11:27:51 +0300 Subject: [PATCH 2/2] Release: v0.8.1-beta --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 459ae09..842b8bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hidabroot", - "version": "0.8.0-beta", + "version": "0.8.1-beta", "description": "An unofficial API for hidabroot", "main": "./build/index.js", "types": "./build/index.d.ts",