style: use switch for special case handling

This commit is contained in:
Lewis Crichton 2023-09-10 13:55:51 +01:00
parent b1bdc48769
commit 482caf0c5b
No known key found for this signature in database

View file

@ -75,17 +75,24 @@ export async function compileUsercss(fileName: string) {
for (const [k, v] of Object.entries(vars)) { for (const [k, v] of Object.entries(vars)) {
varsToPass[k] = Settings.userCssVars[id]?.[k] ?? v.default; 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. switch (v.type) {
// Stylus doesn't really need this to be fair (0/1 are falsy/truthy), but for consistency's sake it's best case "checkbox": {
// if we do. if (["less", "stylus"].includes(preprocessor)) {
// varsToPass[k] = varsToPass[k] ? "1" : "0";
// 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"; break;
} }
if (v.type === "range") { case "range": {
varsToPass[k] = `${varsToPass[k]}${v.units ?? "px"}`; varsToPass[k] = `${varsToPass[k]}${v.units ?? "px"}`;
break;
}
case "select": {
varsToPass[k] = v.options.find(opt => opt.name === varsToPass[k])!.value;
break;
}
} }
} }