aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/utils/colours.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/app/utils/colours.ts')
-rw-r--r--src/frontend/app/utils/colours.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/frontend/app/utils/colours.ts b/src/frontend/app/utils/colours.ts
new file mode 100644
index 0000000..aa939f7
--- /dev/null
+++ b/src/frontend/app/utils/colours.ts
@@ -0,0 +1,26 @@
+// TODO: Standardise this shit server-side
+export function formatHex(hex: string, poundSign = true): string {
+ if (hex.length === 6) {
+ return (poundSign ? "#" : "") + hex;
+ } else if (hex.length === 3) {
+ return (
+ (poundSign ? "#" : "") +
+ hex
+ .split("")
+ .map((c) => c + c)
+ .join("")
+ );
+ } else if (hex.length === 7 && hex.startsWith("#")) {
+ return poundSign ? hex : hex.substring(1);
+ } else if (hex.length === 4 && hex.startsWith("#")) {
+ return poundSign
+ ? hex
+ : hex
+ .substring(1)
+ .split("")
+ .map((c) => c + c)
+ .join("");
+ } else {
+ throw new Error("Invalid hex color format");
+ }
+}