Skip to content

Commit

Permalink
ref: unimportant stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Sv443 committed Oct 19, 2024
1 parent ba48eef commit adc24a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/components/MarkdownDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
13 changes: 9 additions & 4 deletions src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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} */
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit adc24a2

Please sign in to comment.