summaryrefslogtreecommitdiff
path: root/ext/js/data
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2022-05-20 10:28:38 -0400
committerGitHub <noreply@github.com>2022-05-20 10:28:38 -0400
commit31e20c889e467aa4ba64b0b5baf602adc1359371 (patch)
treea033db935a817b2d407ec20843176610a87a6e16 /ext/js/data
parentae0ad227c0fd293609a21e5cc1d2a4b85fe7c520 (diff)
ESlint JSdoc (#2148)
* Install eslint-plugin-jsdoc * Initial rules setup * Update lists * Use @returns rather than @return * Remove error throwing code which is never executed * Fix issues relating to @throws * General error fixes * Update Display type documentation * Various doc fixes * Fix invalid tuple syntax * Doc updates * Remove unused * Doc updates * Enable jsdoc/require-returns * Update rules * Update remaining rules
Diffstat (limited to 'ext/js/data')
-rw-r--r--ext/js/data/anki-util.js36
-rw-r--r--ext/js/data/sandbox/anki-note-data-creator.js22
-rw-r--r--ext/js/data/sandbox/string-util.js16
3 files changed, 33 insertions, 41 deletions
diff --git a/ext/js/data/anki-util.js b/ext/js/data/anki-util.js
index faccbc84..bb375230 100644
--- a/ext/js/data/anki-util.js
+++ b/ext/js/data/anki-util.js
@@ -22,8 +22,8 @@ class AnkiUtil {
/**
* Gets the root deck name of a full deck name. If the deck is a root deck,
* the same name is returned. Nested decks are separated using '::'.
- * @param deckName A string of the deck name.
- * @returns A string corresponding to the name of the root deck.
+ * @param {string} deckName A string of the deck name.
+ * @returns {string} A string corresponding to the name of the root deck.
*/
static getRootDeckName(deckName) {
const index = deckName.indexOf('::');
@@ -32,8 +32,8 @@ class AnkiUtil {
/**
* Checks whether or not any marker is contained in a string.
- * @param string A string to check.
- * @return `true` if the text contains an Anki field marker, `false` otherwise.
+ * @param {string} string A string to check.
+ * @returns {boolean} `true` if the text contains an Anki field marker, `false` otherwise.
*/
static stringContainsAnyFieldMarker(string) {
const result = this._markerPattern.test(string);
@@ -43,8 +43,8 @@ class AnkiUtil {
/**
* Gets a list of all markers that are contained in a string.
- * @param string A string to check.
- * @return An array of marker strings.
+ * @param {string} string A string to check.
+ * @returns {string[]} An array of marker strings.
*/
static getFieldMarkers(string) {
const pattern = this._markerPattern;
@@ -58,25 +58,9 @@ class AnkiUtil {
}
/**
- * Checks whether an object of key-value pairs has a value which contains a specific marker.
- * @param fieldsObject An object with key-value pairs, where the value corresponds to the field value.
- * @param marker The marker string to check for, excluding brackets.
- * @returns `true` if any of the fields contains the marker, `false` otherwise.
- */
- static fieldsObjectContainsMarker(fieldsObject, marker) {
- marker = `{${marker}}`;
- for (const [, fieldValue] of fieldsObject) {
- if (fieldValue.includes(marker)) {
- return true;
- }
- }
- return false;
- }
-
- /**
* Returns a regular expression which can be used to find markers in a string.
- * @param global Whether or not the regular expression should have the global flag.
- * @returns A new `RegExp` instance.
+ * @param {boolean} global Whether or not the regular expression should have the global flag.
+ * @returns {RegExp} A new `RegExp` instance.
*/
static cloneFieldMarkerPattern(global) {
return new RegExp(this._markerPattern.source, global ? 'g' : '');
@@ -84,8 +68,8 @@ class AnkiUtil {
/**
* Checks whether or not a note object is valid.
- * @param note A note object to check.
- * @return `true` if the note is valid, `false` otherwise.
+ * @param {*} note A note object to check.
+ * @returns {boolean} `true` if the note is valid, `false` otherwise.
*/
static isNoteDataValid(note) {
if (!isObject(note)) { return false; }
diff --git a/ext/js/data/sandbox/anki-note-data-creator.js b/ext/js/data/sandbox/anki-note-data-creator.js
index 96f97896..e1c32193 100644
--- a/ext/js/data/sandbox/anki-note-data-creator.js
+++ b/ext/js/data/sandbox/anki-note-data-creator.js
@@ -26,7 +26,7 @@
class AnkiNoteDataCreator {
/**
* Creates a new instance.
- * @param japaneseUtil An instance of `JapaneseUtil`.
+ * @param {JapaneseUtil} japaneseUtil An instance of `JapaneseUtil`.
*/
constructor(japaneseUtil) {
this._japaneseUtil = japaneseUtil;
@@ -34,8 +34,16 @@ class AnkiNoteDataCreator {
/**
* Creates a compatibility representation of the specified data.
- * @param marker The marker that is being used for template rendering.
- * @returns An object used for rendering Anki templates.
+ * @param {string} marker The marker that is being used for template rendering.
+ * @param {object} details Information which is used to generate the data.
+ * @param {Translation.DictionaryEntry} details.dictionaryEntry The dictionary entry.
+ * @param {string} details.resultOutputMode The result output mode.
+ * @param {string} details.mode The mode being used to generate the Anki data.
+ * @param {string} details.glossaryLayoutMode The glossary layout mode.
+ * @param {boolean} details.compactTags Whether or not compact tags mode is enabled.
+ * @param {{documentTitle: string, query: string, fullQuery: string}} details.context Contextual information about the source of the dictionary entry.
+ * @param {object} details.media Media data.
+ * @returns {object} An object used for rendering Anki templates.
*/
create(marker, {
dictionaryEntry,
@@ -83,8 +91,8 @@ class AnkiNoteDataCreator {
/**
* Creates a deferred-evaluation value.
- * @param getter The function to invoke to get the return value.
- * @returns An object which can be passed into `getCachedValue`.
+ * @param {Function} getter The function to invoke to get the return value.
+ * @returns {{getter: Function, hasValue: false, value: undefined}} An object which can be passed into `getCachedValue`.
*/
createCachedValue(getter) {
return {getter, hasValue: false, value: void 0};
@@ -92,8 +100,8 @@ class AnkiNoteDataCreator {
/**
* Gets the value of a cached object.
- * @param item An object that was returned from `createCachedValue`.
- * @returns The result of evaluating the getter, which is cached after the first invocation.
+ * @param {{getter: Function, hasValue: boolean, value: *}} item An object that was returned from `createCachedValue`.
+ * @returns {*} The result of evaluating the getter, which is cached after the first invocation.
*/
getCachedValue(item) {
if (item.hasValue) { return item.value; }
diff --git a/ext/js/data/sandbox/string-util.js b/ext/js/data/sandbox/string-util.js
index 5c395be7..de6933cd 100644
--- a/ext/js/data/sandbox/string-util.js
+++ b/ext/js/data/sandbox/string-util.js
@@ -21,8 +21,8 @@
class StringUtil {
/**
* Decodes the contents of an ArrayBuffer using UTF8.
- * @param arrayBuffer The input ArrayBuffer.
- * @returns A UTF8-decoded string.
+ * @param {ArrayBuffer} arrayBuffer The input ArrayBuffer.
+ * @returns {string} A UTF8-decoded string.
*/
static arrayBufferUtf8Decode(arrayBuffer) {
try {
@@ -34,8 +34,8 @@ class StringUtil {
/**
* Converts the contents of an ArrayBuffer to a base64 string.
- * @param arrayBuffer The input ArrayBuffer.
- * @returns A base64 string representing the binary content.
+ * @param {ArrayBuffer} arrayBuffer The input ArrayBuffer.
+ * @returns {string} A base64 string representing the binary content.
*/
static arrayBufferToBase64(arrayBuffer) {
return btoa(this.arrayBufferToBinaryString(arrayBuffer));
@@ -43,8 +43,8 @@ class StringUtil {
/**
* Converts the contents of an ArrayBuffer to a binary string.
- * @param arrayBuffer The input ArrayBuffer.
- * @returns A string representing the binary content.
+ * @param {ArrayBuffer} arrayBuffer The input ArrayBuffer.
+ * @returns {string} A string representing the binary content.
*/
static arrayBufferToBinaryString(arrayBuffer) {
const bytes = new Uint8Array(arrayBuffer);
@@ -61,8 +61,8 @@ class StringUtil {
/**
* Converts a base64 string to an ArrayBuffer.
- * @param content The binary content string encoded in base64.
- * @returns A new `ArrayBuffer` object corresponding to the specified content.
+ * @param {string} content The binary content string encoded in base64.
+ * @returns {ArrayBuffer} A new `ArrayBuffer` object corresponding to the specified content.
*/
static base64ToArrayBuffer(content) {
const binaryContent = atob(content);