From 482caf0c5b190192123d0b99decbfa4f6edffc90 Mon Sep 17 00:00:00 2001 From: Lewis Crichton Date: Sun, 10 Sep 2023 13:55:51 +0100 Subject: [PATCH] style: use switch for special case handling --- src/utils/themes/usercss/compiler.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/utils/themes/usercss/compiler.ts b/src/utils/themes/usercss/compiler.ts index d7ca3c9e..30cbe9ad 100644 --- a/src/utils/themes/usercss/compiler.ts +++ b/src/utils/themes/usercss/compiler.ts @@ -75,17 +75,24 @@ export async function compileUsercss(fileName: string) { for (const [k, v] of Object.entries(vars)) { varsToPass[k] = Settings.userCssVars[id]?.[k] ?? v.default; - if (v.type === "checkbox" && ["less", "stylus"].includes(preprocessor)) { - // For Less and Stylus, we convert from 0/1 to false/true as it works with their if statement equivalents. - // Stylus doesn't really need this to be fair (0/1 are falsy/truthy), but for consistency's sake it's best - // if we do. - // - // In default and USO, it has no special meaning, so we'll just leave it as a number. - varsToPass[k] = varsToPass[k] === "1" ? "true" : "false"; - } - if (v.type === "range") { - varsToPass[k] = `${varsToPass[k]}${v.units ?? "px"}`; + switch (v.type) { + case "checkbox": { + if (["less", "stylus"].includes(preprocessor)) { + varsToPass[k] = varsToPass[k] ? "1" : "0"; + } + break; + } + + case "range": { + varsToPass[k] = `${varsToPass[k]}${v.units ?? "px"}`; + break; + } + + case "select": { + varsToPass[k] = v.options.find(opt => opt.name === varsToPass[k])!.value; + break; + } } }