From 7975af960efd178b41901ee51d55aa582326a131 Mon Sep 17 00:00:00 2001 From: Randall Schmidt Date: Wed, 27 Feb 2019 18:15:16 +0700 Subject: [PATCH] regenerate docs --- docs/API.html | 12 ++++----- docs/global.html | 16 ++++++------ docs/index.html | 62 ++++++++++++++++++++++++++++++++++++++++++++-- docs/index.js.html | 15 ++++++++--- 4 files changed, 85 insertions(+), 20 deletions(-) diff --git a/docs/API.html b/docs/API.html index 1551a4b..9f3c9b8 100644 --- a/docs/API.html +++ b/docs/API.html @@ -70,7 +70,7 @@

new APISource:
@@ -226,7 +226,7 @@

(async) Source:
@@ -411,7 +411,7 @@

(async) Source:
@@ -583,7 +583,7 @@

(async) Source:
@@ -763,7 +763,7 @@

(async) Source:
@@ -949,7 +949,7 @@
Returns:

- Documentation generated by JSDoc 3.5.5 on Tue Feb 26 2019 13:55:21 GMT+0700 (GMT+07:00) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Wed Feb 27 2019 18:13:52 GMT+0700 (GMT+07:00) using the docdash theme.
diff --git a/docs/global.html b/docs/global.html index 433212e..52c7a3c 100644 --- a/docs/global.html +++ b/docs/global.html @@ -131,7 +131,7 @@

ExampleResultData

Source:
@@ -299,7 +299,7 @@

ExampleResults

Source:
@@ -489,7 +489,7 @@

KanjiResult

Source:
@@ -1240,7 +1240,7 @@

PhrasePageScrapeResult

Source:
@@ -1523,7 +1523,7 @@

PhraseScrapeMeaning

Source:
@@ -1761,7 +1761,7 @@

PhraseScrapeSentence

Source:
@@ -1905,7 +1905,7 @@

YomiExample

Source:
@@ -2077,7 +2077,7 @@
Type:

- Documentation generated by JSDoc 3.5.5 on Tue Feb 26 2019 13:55:21 GMT+0700 (GMT+07:00) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Wed Feb 27 2019 18:13:52 GMT+0700 (GMT+07:00) using the docdash theme.
diff --git a/docs/index.html b/docs/index.html index 62c75d6..9cad5a4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -124,7 +124,55 @@

Word/phrase search (provided by official Jisho API)

This returns the 日本には美しい都市が多い。例えば京都、奈良だ にほんにはうつくしいとしがおおい。たとえばきょうと、奈良だ -Japan is full of beautiful cities. Kyoto and Nara, for instance.

Request options

Optionally, you can provide options, such as timeout and proxy, to use for requests. The options are passed directly to the request module. See its documentation for a full list of options.

+Japan is full of beautiful cities. Kyoto and Nara, for instance.

Word/phrase scraping

This scrapes the word/phrase page on Jisho.org. This can get you some data that the official API doesn't have, such as JLPT level and part-of-speech. The official API (searchForPhrase) should be preferred if it has the data you need.

+
const jishoApi = require('unofficial-jisho-api');
+const jisho = new jishoApi();
+
+jisho.scrapeForPhrase('谷').then((data) => {
+  console.log(JSON.stringify(data, null, 2));
+});

This outputs the following:

+
{
+  "found": true,
+  "tags": [
+    "Common word",
+    "JLPT N3",
+    "Wanikani level 5"
+  ],
+  "meanings": [
+    {
+      "seeAlsoTerms": [],
+      "sentences": [],
+      "definition": "valley",
+      "supplemental": [],
+      "definitionAbstract": "",
+      "tags": [
+        "noun"
+      ]
+    },
+    {
+      "seeAlsoTerms": [],
+      "sentences": [],
+      "definition": "Valley",
+      "supplemental": [],
+      "definitionAbstract": "In geology, a valley or dale is a depression with predominant extent in one direction. A very deep river valley may be called a canyon or gorge. The terms U-shaped and V-shaped are descriptive terms of geography to characterize the form of valleys. Most valleys belong to one of these two main types or a mixture of them, (at least) with respect of the cross section of the slopes or hillsides.",
+      "tags": [
+        "wikipedia definition"
+      ]
+    }
+  ],
+  "otherForms": [
+    {
+      "kanji": "渓",
+      "kana": "たに"
+    },
+    {
+      "kanji": "谿",
+      "kana": "たに"
+    }
+  ],
+  "query": "谷",
+  "uri": "https://jisho.org/word/%E8%B0%B7"
+}

Request options

Optionally, you can provide options, such as timeout and proxy, to use for requests. The options are passed directly to the request module. See its documentation for a full list of options.

If you provide an options object to the jishoApi constructor, those options will be used for all requests. Alternatively, you can provide the options as the second argument to the searchForPhrase, searchForKanji, or searchForExamples functions, and the options will only be used for that specific request. If you provide options in both manners, the options will be merged, with the options passed to the function taking precedence if the two are in conflict.

Use a proxy for all requests

const jishoApi = require('unofficial-jisho-api');
 const jisho = new jishoApi({ proxy: 'http://99.99.99.99:9999' });
@@ -161,6 +209,16 @@ 

Parse kanji page HTML

cons
   console.log(`English: ${json.results[0].english}`);
   console.log(`Kanji ${json.results[0].kanji}`);
   console.log(`Kana: ${json.results[0].kana}`);
+});

Parse phrase page HTML

const request = require('request');
+const jishoApi = require('unofficial-jisho-api');
+const jisho = new jishoApi();
+
+const SEARCH_EXAMPLE = '保護者';
+const SEARCH_URI = jisho.getUriForPhraseScrape(SEARCH_EXAMPLE);
+
+request(SEARCH_URI, (error, response, body) => {
+  const json = jisho.parsePhraseScrapeHtml(body, SEARCH_EXAMPLE);
+  console.log(JSON.stringify(json, null, 2));
 });

About

Permission to scrape granted by Jisho's admin Kimtaro: http://jisho.org/forum/54fefc1f6e73340b1f160000-is-there-any-kind-of-search-api

For bugs or requested additional data, feel free to open an issue on the Github repo.

@@ -177,7 +235,7 @@

Parse kanji page HTML

cons
 
- Documentation generated by JSDoc 3.5.5 on Tue Feb 26 2019 13:55:21 GMT+0700 (GMT+07:00) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Wed Feb 27 2019 18:13:52 GMT+0700 (GMT+07:00) using the docdash theme.
diff --git a/docs/index.js.html b/docs/index.js.html index 80d5c7f..8f5d203 100644 --- a/docs/index.js.html +++ b/docs/index.js.html @@ -148,7 +148,7 @@

index.js

const examples = regexResults.map((regexResult) => { const examplesLines = regexResult.split('\n').map(s => s.trim()); return { - examples: examplesLines[0], + example: examplesLines[0], reading: examplesLines[1].replace('【', '').replace('】', ''), meaning: htmlEntities.decode(examplesLines[2]), }; @@ -298,11 +298,16 @@

index.js

kanji += unlifted; kana += furigana; - for (let j = 0; j < unlifted.length; j += 1) { + const kanaEnding = []; + for (let j = unlifted.length - 1; j > 0; j -= 1) { if (!unlifted[j].match(kanjiRegex)) { - kana += unlifted[j]; + kanaEnding.push(unlifted[j]); + } else { + break; } } + + kana += kanaEnding.reverse().join(''); } else { kanji += unlifted; kana += unlifted; @@ -660,8 +665,10 @@

index.js

API.prototype.getUriForKanjiSearch = uriForKanjiSearch; API.prototype.getUriForExampleSearch = uriForExampleSearch; API.prototype.getUriForPhraseSearch = uriForPhraseSearch; +API.prototype.getUriForPhraseScrape = uriForPhraseScrape; API.prototype.parseExamplePageHtml = parseExamplePageData; API.prototype.parseKanjiPageHtml = parseKanjiPageData; +API.prototype.parsePhraseScrapeHtml = parsePhrasePageData; module.exports = API;
@@ -678,7 +685,7 @@

index.js


- Documentation generated by JSDoc 3.5.5 on Tue Feb 26 2019 13:55:21 GMT+0700 (GMT+07:00) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Wed Feb 27 2019 18:13:52 GMT+0700 (GMT+07:00) using the docdash theme.