From b2700b9ef9e34cebc90d669fd53bde91401cae52 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Wed, 11 Feb 2026 16:33:02 +0100 Subject: Use provided colours in map Closes #131 --- src/frontend/app/utils/colours.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/frontend/app/utils/colours.ts (limited to 'src/frontend/app/utils/colours.ts') 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"); + } +} -- cgit v1.3