diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2022-05-19 20:16:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-19 20:16:40 -0400 |
commit | ae0ad227c0fd293609a21e5cc1d2a4b85fe7c520 (patch) | |
tree | 46f4058993764708ec9b9e1176f4328e205c1eb4 /ext | |
parent | 6e239638bb7f89353f0dd2c67600966aeec726f2 (diff) |
Add mode documentation about the types used by Translator (#2147)
Diffstat (limited to 'ext')
-rw-r--r-- | ext/js/background/backend.js | 12 | ||||
-rw-r--r-- | ext/js/language/translator.js | 68 |
2 files changed, 26 insertions, 54 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 54e8ff08..66f80351 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -1958,6 +1958,13 @@ class Backend { this._applyOptions(source); } + /** + * Creates an options object for use with `Translator.findTerms`. + * @param {string} mode The display mode for the dictionary entries. + * @param {{matchType: string, deinflect: boolean}} details Custom info for finding terms. + * @param {object} options The options. + * @returns {FindTermsOptions} An options object. + */ _getTranslatorFindTermsOptions(mode, details, options) { let {matchType, deinflect} = details; if (typeof matchType !== 'string') { matchType = 'exact'; } @@ -2006,6 +2013,11 @@ class Backend { }; } + /** + * Creates an options object for use with `Translator.findKanji`. + * @param {object} options The options. + * @returns {FindKanjiOptions} An options object. + */ _getTranslatorFindKanjiOptions(options) { const enabledDictionaryMap = this._getTranslatorEnabledDictionaryMap(options); return {enabledDictionaryMap}; diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index 9ccec9dd..fafd1bfb 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -27,8 +27,9 @@ class Translator { /** * Creates a new Translator instance. - * @param japaneseUtil An instance of JapaneseUtil. - * @param database An instance of DictionaryDatabase. + * @param {object} details The details for the class. + * @param {JapaneseUtil} details.japaneseUtil An instance of JapaneseUtil. + * @param {DictionaryDatabase} details.database An instance of DictionaryDatabase. */ constructor({japaneseUtil, database}) { this._japaneseUtil = japaneseUtil; @@ -42,7 +43,7 @@ class Translator { /** * Initializes the instance for use. The public API should not be used until * this function has been called. - * @param deinflectionReasons The raw deinflections reasons data that the Deinflector uses. + * @param {object} deinflectionReasons The raw deinflections reasons data that the Deinflector uses. */ prepare(deinflectionReasons) { this._deinflector = new Deinflector(deinflectionReasons); @@ -57,42 +58,11 @@ class Translator { /** * Finds term definitions for the given text. - * @param mode The mode to use for finding terms, which determines the format of the resulting array. + * @param {string} mode The mode to use for finding terms, which determines the format of the resulting array. * One of: 'group', 'merge', 'split', 'simple' - * @param text The text to find terms for. - * @param options An object using the following structure: - * ``` - * { - * matchType: (enum: 'exact', 'prefix', 'suffix'), - * mainDictionary: (string), - * sortFrequencyDictionary: (null or string), - * sortFrequencyDictionaryOrder: (enum: 'ascending', 'descending'), - * removeNonJapaneseCharacters: (boolean), - * convertHalfWidthCharacters: (enum: 'false', 'true', 'variant'), - * convertNumericCharacters: (enum: 'false', 'true', 'variant'), - * convertAlphabeticCharacters: (enum: 'false', 'true', 'variant'), - * convertHiraganaToKatakana: (enum: 'false', 'true', 'variant'), - * convertKatakanaToHiragana: (enum: 'false', 'true', 'variant'), - * collapseEmphaticSequences: (enum: 'false', 'true', 'full'), - * textReplacements: [ - * (null or [ - * {pattern: (RegExp), replacement: (string)} - * ... - * ]) - * ... - * ], - * enabledDictionaryMap: (Map of [ - * (string), - * { - * index: (number), - * priority: (number), - * allowSecondarySearches: (boolean) - * } - * ]), - * excludeDictionaryDefinitions: (Set of (string) or null) - * } - * ``` - * @returns An object of the structure `{dictionaryEntries, originalTextLength}`. + * @param {string} text The text to find terms for. + * @param {Translation.FindTermsOptions} options A object describing settings about the lookup. + * @returns {{dictionaryEntries: Translation.TermDictionaryEntry[], originalTextLength: number}} An object containing dictionary entries and the length of the original source text. */ async findTerms(mode, text, options) { const {enabledDictionaryMap, excludeDictionaryDefinitions, sortFrequencyDictionary, sortFrequencyDictionaryOrder} = options; @@ -136,20 +106,11 @@ class Translator { /** * Finds kanji definitions for the given text. - * @param text The text to find kanji definitions for. This string can be of any length, + * @param {string} text The text to find kanji definitions for. This string can be of any length, * but is typically just one character, which is a single kanji. If the string is multiple * characters long, each character will be searched in the database. - * @param options An object using the following structure: - * { - * enabledDictionaryMap: (Map of [ - * (string), - * { - * index: (number), - * priority: (number) - * } - * ]) - * } - * @returns An array of definitions. See the _createKanjiDefinition() function for structure details. + * @param {Translation.FindKanjiOptions} options A object describing settings about the lookup. + * @returns {Translation.KanjiDictionaryEntry[]} An array of definitions. See the _createKanjiDefinition() function for structure details. */ async findKanji(text, options) { const {enabledDictionaryMap} = options; @@ -185,11 +146,10 @@ class Translator { /** * Gets a list of frequency information for a given list of term-reading pairs * and a list of dictionaries. - * @param termReadingList An array of `{term, reading}` pairs. If reading is null, + * @param {{term: string, reading: string|null}[]} termReadingList An array of `{term, reading}` pairs. If reading is null, * the reading won't be compared. - * @param dictionaries An array of dictionary names. - * @returns An array of objects with the format - * `{term, reading, dictionary, hasReading, frequency}`. + * @param {Iterable<string>} dictionaries An array of dictionary names. + * @returns {TermFrequency[]} An array of term frequencies. */ async getTermFrequencies(termReadingList, dictionaries) { const dictionarySet = new Set(); |