From 2c6c39ea1adc179afacbaacdd85a3d0ed6e84cea Mon Sep 17 00:00:00 2001 From: Vipra Date: Tue, 1 Aug 2023 11:58:36 +0200 Subject: [PATCH] adjust lots type hints --- src/content_scripts/protoots.js | 13 +++++++------ src/libs/protootshelpers.js | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/content_scripts/protoots.js b/src/content_scripts/protoots.js index 7eecdd6..2e6f3df 100644 --- a/src/content_scripts/protoots.js +++ b/src/content_scripts/protoots.js @@ -201,9 +201,9 @@ async function addProplate(element) { /** * Generates a proplate and adds it as a sibling of the given nameTagEl - * @param {string} statusId Id of the target object - * @param {string} accountName Name of the account the plate is for - * @param {HTMLElement} nametagEl Element to add the proplate next to + * @param {string|undefined} statusId Id of the target object + * @param {string|null} accountName Name of the account the plate is for + * @param {HTMLElement|null} nametagEl Element to add the proplate next to * @param {string} type type of the target object * @returns */ @@ -234,7 +234,7 @@ async function addProplate(element) { /** * Gets the data-id from the given element * @param {HTMLElement} element Element with data-id attribute - * @returns {string} + * @returns {string|undefined} */ function getID(element) { let id = element.dataset.id; @@ -270,11 +270,12 @@ async function addProplate(element) { /** * Gets the given element's textcontent or given attribute - * @param {HTMLElement} element Element which textcontent is the account name + * @param {HTMLElement|null} element Element which textcontent is the account name * @param {string} attribute Attribute from which to pull the account name * @returns {string|null} Normalised account name or null if it can't be found. */ function getAccountName(element, attribute = "textContent") { + if (!element) return null; let accountName = element.textContent; if (attribute != "textContent") { accountName = element.getAttribute(attribute); @@ -282,7 +283,7 @@ async function addProplate(element) { if (!accountName) { warn( - "Could not extract the account name from the element, aborting pronoun extraction:", + `Could not extract the account name from the element, using attribute ${attribute} aborting pronoun extraction:`, element, ); return null; diff --git a/src/libs/protootshelpers.js b/src/libs/protootshelpers.js index 6ebf0fb..ff664ab 100644 --- a/src/libs/protootshelpers.js +++ b/src/libs/protootshelpers.js @@ -21,10 +21,11 @@ export function normaliseAccountName(name) { * Turns a link to an account on a remote instance into a username. * * e.g. `https://example.com/@test` -> `@test@example.com` - * @param {string} url URL to an account on their own instance + * @param {string|null} url URL to an account on their own instance * @returns {string} username (not normalised) */ export function accountNameFromURL(url) { + if (!url) return null; const splitURL = url.split("/"); const username = [splitURL.pop(), splitURL.pop()].join("@");