From 25cd9a397e5ef5a7cb9396fe5e0ad1d7ec9e3fd7 Mon Sep 17 00:00:00 2001 From: JustTemmie <47639983+JustTemmie@users.noreply.github.com> Date: Mon, 14 Jul 2025 20:05:31 +0200 Subject: [PATCH] feat: implement caching for hash function --- utils/generateIrcColor.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/utils/generateIrcColor.ts b/utils/generateIrcColor.ts index 24d4946..03a30e7 100644 --- a/utils/generateIrcColor.ts +++ b/utils/generateIrcColor.ts @@ -5,11 +5,9 @@ let h64: CallableFunction; h64 = (await xxhash()).h64; })(); -export default (seed: string): string => { - const lightness = 50 - - // this should probably be cached eventually - const idHash = h64(seed) +export default (seed: string, saturation: number = 100, lightness: number = 50): string => { + const idHash = useState(`h64Hash-${seed}`, () => h64(seed)) + const hashValue: bigint = idHash.value - return `hsl(${idHash % 360n}, 100%, ${lightness}%)` + return `hsl(${hashValue % 360n}, ${saturation}%, ${lightness}%)` } \ No newline at end of file