From adc24a29aa988eb581237ddac32bd02d3e80640b Mon Sep 17 00:00:00 2001 From: Sv443 Date: Sat, 19 Oct 2024 20:43:19 +0200 Subject: [PATCH] ref: unimportant stuff --- src/components/MarkdownDialog.ts | 4 +--- src/utils/misc.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/components/MarkdownDialog.ts b/src/components/MarkdownDialog.ts index 9532604712..0fd2e870e8 100644 --- a/src/components/MarkdownDialog.ts +++ b/src/components/MarkdownDialog.ts @@ -36,9 +36,7 @@ export class MarkdownDialog extends BytmDialog { const bodyEl = document.createElement("div"); bodyEl.classList.add("bytm-md-dialog-body"); - const mdCont = typeof this.opts.body === "string" - ? this.opts.body - : await consumeStringGen(this.opts.body); + const mdCont = await consumeStringGen(this.opts.body); const markdownEl = document.createElement("div"); markdownEl.classList.add("bytm-markdown-dialog-content", "bytm-markdown-container"); diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 1536e7d271..0d7c50d0aa 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -194,7 +194,13 @@ export function getOS() { /** Turns the passed StringGen (either a string, stringifiable object or a sync or async function returning a string or stringifiable object) into a string */ export async function consumeStringGen(strGen: StringGen): Promise { - return String(typeof strGen === "function" ? await strGen() : strGen); + return typeof strGen === "string" + ? strGen + : String( + typeof strGen === "function" + ? await strGen() + : strGen + ); } /** Formats a number based on the config or the passed {@linkcode notation} */ @@ -242,12 +248,11 @@ export async function getResourceUrl(name: ResourceKey | "_") { * Prioritizes `navigator.language`, then `navigator.languages`, then `"en-US"` as a fallback. */ export function getPreferredLocale(): TrLocale { - const nvLang = navigator.language; const nvLangs = navigator.languages .filter(lang => lang.match(/^[a-z]{2}(-|_)[A-Z]$/) !== null); - if(Object.entries(langMapping).find(([key]) => key === nvLang)) - return nvLang as TrLocale; + if(Object.entries(langMapping).find(([key]) => key === navigator.language)) + return navigator.language as TrLocale; for(const loc of nvLangs) { if(Object.entries(langMapping).find(([key]) => key === loc))