mirror of
				https://github.com/h7x4/unofficial_jisho_api_dart.git
				synced 2025-11-03 22:06:20 +01:00 
			
		
		
		
	Add types to all functions
This commit is contained in:
		@@ -197,7 +197,7 @@ String getGifUri(String kanji) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
int getNewspaperFrequencyRank(String pageHtml) {
 | 
					int getNewspaperFrequencyRank(String pageHtml) {
 | 
				
			||||||
  final frequencySection = getStringBetweenStrings(pageHtml, '<div class="frequency">', '</div>');
 | 
					  final frequencySection = getStringBetweenStrings(pageHtml, '<div class="frequency">', '</div>');
 | 
				
			||||||
  return frequencySection.isNotEmpty ? int.parse(getStringBetweenStrings(frequencySection, '<strong>', '</strong>')) : null;
 | 
					  return (frequencySection != null) ? int.parse(getStringBetweenStrings(frequencySection, '<strong>', '</strong>')) : null;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
KanjiResult parseKanjiPageData(String pageHtml, String kanji) {
 | 
					KanjiResult parseKanjiPageData(String pageHtml, String kanji) {
 | 
				
			||||||
@@ -236,7 +236,7 @@ String uriForExampleSearch(String phrase) {
 | 
				
			|||||||
  return '${SCRAPE_BASE_URI}${Uri.encodeComponent(phrase)}%23sentences';
 | 
					  return '${SCRAPE_BASE_URI}${Uri.encodeComponent(phrase)}%23sentences';
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ExampleResultData getKanjiAndKana(div) {
 | 
					ExampleResultData getKanjiAndKana(xml.XmlNode div) {
 | 
				
			||||||
  final ul = div.find('ul').eq(0);
 | 
					  final ul = div.find('ul').eq(0);
 | 
				
			||||||
  final contents = ul.contents();
 | 
					  final contents = ul.contents();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -282,7 +282,7 @@ ExampleResultData getKanjiAndKana(div) {
 | 
				
			|||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
List<ExampleSentencePiece> getPieces(sentenceElement) {
 | 
					List<ExampleSentencePiece> getPieces(xml.XmlNode sentenceElement) {
 | 
				
			||||||
  final pieceElements = sentenceElement.find('li.clearfix');
 | 
					  final pieceElements = sentenceElement.find('li.clearfix');
 | 
				
			||||||
  final pieces = [];
 | 
					  final pieces = [];
 | 
				
			||||||
  for (var pieceIndex = 0; pieceIndex < pieceElements.length; pieceIndex += 1) {
 | 
					  for (var pieceIndex = 0; pieceIndex < pieceElements.length; pieceIndex += 1) {
 | 
				
			||||||
@@ -296,7 +296,7 @@ List<ExampleSentencePiece> getPieces(sentenceElement) {
 | 
				
			|||||||
  return pieces;
 | 
					  return pieces;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ExampleResultData parseExampleDiv(div) {
 | 
					ExampleResultData parseExampleDiv(xml.XmlNode div) {
 | 
				
			||||||
  final result = getKanjiAndKana(div);
 | 
					  final result = getKanjiAndKana(div);
 | 
				
			||||||
  result.english = div.find('.english').text();
 | 
					  result.english = div.find('.english').text();
 | 
				
			||||||
  result.pieces = getPieces(div);
 | 
					  result.pieces = getPieces(div);
 | 
				
			||||||
@@ -323,7 +323,7 @@ ExampleResults parseExamplePageData(String pageHtml, String phrase) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* PHRASE SCRAPE FUNCTIONS START */
 | 
					/* PHRASE SCRAPE FUNCTIONS START */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
List<String> getTags(document) {
 | 
					List<String> getTags(xml.XmlDocument document) {
 | 
				
			||||||
  final tags = [];
 | 
					  final tags = [];
 | 
				
			||||||
  final tagElements = document.descendants.where((node) => node.attributes[0].value == 'concept_light-tag').toList();
 | 
					  final tagElements = document.descendants.where((node) => node.attributes[0].value == 'concept_light-tag').toList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -335,7 +335,7 @@ List<String> getTags(document) {
 | 
				
			|||||||
  return tags;
 | 
					  return tags;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PhrasePageScrapeResult getMeaningsOtherFormsAndNotes(document) {
 | 
					PhrasePageScrapeResult getMeaningsOtherFormsAndNotes(xml.XmlDocument document) {
 | 
				
			||||||
  final returnValues = PhrasePageScrapeResult( otherForms: [], notes: [] );
 | 
					  final returnValues = PhrasePageScrapeResult( otherForms: [], notes: [] );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //TODO: Fix
 | 
					  //TODO: Fix
 | 
				
			||||||
@@ -414,11 +414,11 @@ PhrasePageScrapeResult getMeaningsOtherFormsAndNotes(document) {
 | 
				
			|||||||
  return returnValues;
 | 
					  return returnValues;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
String uriForPhraseScrape(searchTerm) {
 | 
					String uriForPhraseScrape(String searchTerm) {
 | 
				
			||||||
  return 'https://jisho.org/word/${Uri.encodeComponent(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 document = xml.parse(pageHtml);
 | 
				
			||||||
  final result = getMeaningsOtherFormsAndNotes(document);
 | 
					  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
 | 
					  /// @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.
 | 
					  ///   complex and is not documented, so put on your trial-and-error hat.
 | 
				
			||||||
  /// @async
 | 
					  /// @async
 | 
				
			||||||
  searchForPhrase(String phrase) {
 | 
					  searchForPhrase(String phrase) async {
 | 
				
			||||||
    final uri = uriForPhraseSearch(phrase);
 | 
					    final uri = uriForPhraseSearch(phrase);
 | 
				
			||||||
    return http.get(uri).then((response) => jsonDecode(response.body).data);
 | 
					    return http.get(uri).then((response) => jsonDecode(response.body).data);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -479,7 +479,7 @@ class JishoApi {
 | 
				
			|||||||
  /// @param {string} kanji The kanji to search for.
 | 
					  /// @param {string} kanji The kanji to search for.
 | 
				
			||||||
  /// @returns {KanjiResult} Information about the searched kanji.
 | 
					  /// @returns {KanjiResult} Information about the searched kanji.
 | 
				
			||||||
  /// @async
 | 
					  /// @async
 | 
				
			||||||
  Future<KanjiResult> searchForKanji(String kanji) {
 | 
					  Future<KanjiResult> searchForKanji(String kanji) async {
 | 
				
			||||||
    final uri = uriForKanjiSearch(kanji);
 | 
					    final uri = uriForKanjiSearch(kanji);
 | 
				
			||||||
    return http.get(uri).then((response) => parseKanjiPageData(response.body, 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.
 | 
					  /// @param {string} phrase The word or phrase to search for.
 | 
				
			||||||
  /// @returns {ExampleResults}
 | 
					  /// @returns {ExampleResults}
 | 
				
			||||||
  /// @async
 | 
					  /// @async
 | 
				
			||||||
  Future<ExampleResults> searchForExamples(String phrase) {
 | 
					  Future<ExampleResults> searchForExamples(String phrase) async {
 | 
				
			||||||
    final uri = uriForExampleSearch(phrase);
 | 
					    final uri = uriForExampleSearch(phrase);
 | 
				
			||||||
    return http.get(uri).then((response) => parseExamplePageData(response.body, phrase));
 | 
					    return http.get(uri).then((response) => parseExamplePageData(response.body, phrase));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user