aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustice Almanzar <superdash993@gmail.com>2023-07-15 22:50:21 +0000
committerGitHub <noreply@github.com>2023-07-16 00:50:21 +0200
commita7e74ee4d5db9f47f88c1c88352aa85b65df4a2a (patch)
treee45154e4989fefe4c9dec5509f202f58e540907f
parent1340f023a3c7f5e16e9fc476c7198a6afaa2f475 (diff)
downloadVencord-a7e74ee4d5db9f47f88c1c88352aa85b65df4a2a.tar.gz
Vencord-a7e74ee4d5db9f47f88c1c88352aa85b65df4a2a.tar.bz2
Vencord-a7e74ee4d5db9f47f88c1c88352aa85b65df4a2a.zip
classNameFactory: Allow (& ignore) all sorts of falsy values (#1427)
-rw-r--r--src/api/Styles.ts6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/api/Styles.ts b/src/api/Styles.ts
index 6b189ca..6b0ac2c 100644
--- a/src/api/Styles.ts
+++ b/src/api/Styles.ts
@@ -141,7 +141,7 @@ export const compileStyle = (style: Style) => {
*/
export const classNameToSelector = (name: string, prefix = "") => name.split(" ").map(n => `.${prefix}${n}`).join("");
-type ClassNameFactoryArg = string | string[] | Record<string, unknown>;
+type ClassNameFactoryArg = string | string[] | Record<string, unknown> | false | null | undefined | 0 | "";
/**
* @param prefix The prefix to add to each class, defaults to `""`
* @returns A classname generator function
@@ -154,9 +154,9 @@ type ClassNameFactoryArg = string | string[] | Record<string, unknown>;
export const classNameFactory = (prefix: string = "") => (...args: ClassNameFactoryArg[]) => {
const classNames = new Set<string>();
for (const arg of args) {
- if (typeof arg === "string") classNames.add(arg);
+ if (arg && typeof arg === "string") classNames.add(arg);
else if (Array.isArray(arg)) arg.forEach(name => classNames.add(name));
- else if (typeof arg === "object") Object.entries(arg).forEach(([name, value]) => value && classNames.add(name));
+ else if (arg && typeof arg === "object") Object.entries(arg).forEach(([name, value]) => value && classNames.add(name));
}
return Array.from(classNames, name => prefix + name).join(" ");
};