aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/utils
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2026-02-11 16:33:02 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2026-02-11 16:33:02 +0100
commitb2700b9ef9e34cebc90d669fd53bde91401cae52 (patch)
tree32de878517fe04bd77f4bd40bf55e0f54bfeedae /src/frontend/app/utils
parenta187bcf97de6d043cb663dd973c83cc887665d3a (diff)
Use provided colours in map
Closes #131
Diffstat (limited to 'src/frontend/app/utils')
-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");
+ }
+}