From 624fcf5d2c431ae79608122c90dbf2aee3d49d70 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 11 Jun 2020 14:52:15 +0200 Subject: [PATCH] Add types to all functions --- lib/src/unofficial_jisho_api_base.dart | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/src/unofficial_jisho_api_base.dart b/lib/src/unofficial_jisho_api_base.dart index 0485df2..fdc9f55 100644 --- a/lib/src/unofficial_jisho_api_base.dart +++ b/lib/src/unofficial_jisho_api_base.dart @@ -197,7 +197,7 @@ String getGifUri(String kanji) { int getNewspaperFrequencyRank(String pageHtml) { final frequencySection = getStringBetweenStrings(pageHtml, '
', '
'); - return frequencySection.isNotEmpty ? int.parse(getStringBetweenStrings(frequencySection, '', '')) : null; + return (frequencySection != null) ? int.parse(getStringBetweenStrings(frequencySection, '', '')) : null; } KanjiResult parseKanjiPageData(String pageHtml, String kanji) { @@ -236,7 +236,7 @@ String uriForExampleSearch(String phrase) { return '${SCRAPE_BASE_URI}${Uri.encodeComponent(phrase)}%23sentences'; } -ExampleResultData getKanjiAndKana(div) { +ExampleResultData getKanjiAndKana(xml.XmlNode div) { final ul = div.find('ul').eq(0); final contents = ul.contents(); @@ -282,7 +282,7 @@ ExampleResultData getKanjiAndKana(div) { ); } -List getPieces(sentenceElement) { +List getPieces(xml.XmlNode sentenceElement) { final pieceElements = sentenceElement.find('li.clearfix'); final pieces = []; for (var pieceIndex = 0; pieceIndex < pieceElements.length; pieceIndex += 1) { @@ -296,7 +296,7 @@ List getPieces(sentenceElement) { return pieces; } -ExampleResultData parseExampleDiv(div) { +ExampleResultData parseExampleDiv(xml.XmlNode div) { final result = getKanjiAndKana(div); result.english = div.find('.english').text(); result.pieces = getPieces(div); @@ -323,7 +323,7 @@ ExampleResults parseExamplePageData(String pageHtml, String phrase) { /* PHRASE SCRAPE FUNCTIONS START */ -List getTags(document) { +List getTags(xml.XmlDocument document) { final tags = []; final tagElements = document.descendants.where((node) => node.attributes[0].value == 'concept_light-tag').toList(); @@ -335,7 +335,7 @@ List getTags(document) { return tags; } -PhrasePageScrapeResult getMeaningsOtherFormsAndNotes(document) { +PhrasePageScrapeResult getMeaningsOtherFormsAndNotes(xml.XmlDocument document) { final returnValues = PhrasePageScrapeResult( otherForms: [], notes: [] ); //TODO: Fix @@ -414,11 +414,11 @@ PhrasePageScrapeResult getMeaningsOtherFormsAndNotes(document) { return returnValues; } -String uriForPhraseScrape(searchTerm) { +String uriForPhraseScrape(String searchTerm) { return 'https://jisho.org/word/${Uri.encodeComponent(searchTerm)}'; } -PhrasePageScrapeResult parsePhrasePageData(pageHtml, query) { +PhrasePageScrapeResult parsePhrasePageData(String pageHtml, String query) { final document = xml.parse(pageHtml); final result = getMeaningsOtherFormsAndNotes(document); @@ -443,7 +443,7 @@ class JishoApi { /// @returns {Object} The response data from the official Jisho.org API. Its format is somewhat /// complex and is not documented, so put on your trial-and-error hat. /// @async - searchForPhrase(String phrase) { + searchForPhrase(String phrase) async { final uri = uriForPhraseSearch(phrase); return http.get(uri).then((response) => jsonDecode(response.body).data); } @@ -479,7 +479,7 @@ class JishoApi { /// @param {string} kanji The kanji to search for. /// @returns {KanjiResult} Information about the searched kanji. /// @async - Future searchForKanji(String kanji) { + Future searchForKanji(String kanji) async { final uri = uriForKanjiSearch(kanji); return http.get(uri).then((response) => parseKanjiPageData(response.body, kanji)); } @@ -488,7 +488,7 @@ class JishoApi { /// @param {string} phrase The word or phrase to search for. /// @returns {ExampleResults} /// @async - Future searchForExamples(String phrase) { + Future searchForExamples(String phrase) async { final uri = uriForExampleSearch(phrase); return http.get(uri).then((response) => parseExamplePageData(response.body, phrase)); }