From ec639ff9343641eeb376cb9c10009cd51f3a6b20 Mon Sep 17 00:00:00 2001 From: Anchel135 Date: Wed, 5 Feb 2025 11:07:24 +0200 Subject: [PATCH] commit --- lib/utils.ts | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/utils.ts b/lib/utils.ts index b19e03e..1a6ecfe 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -12,13 +12,16 @@ export function cn(...inputs: ClassValue[]) { } export async function securedFetch( - url: string, + input: string, init: RequestInit, role?: string, toast?: any, ): Promise { - - const response = await fetch(`${url}${role && (url.includes("?") ? "&" : "?")}role=${role}`, init) + let url = input + if (role) { + url += input.includes("?") ? `&role=${role}` : `?role=${role}` + } + const response = await fetch(url, init) const { status } = response if (status >= 300) { const err = await response.text() @@ -45,12 +48,12 @@ export const defaultQuery = (q?: string) => q || "MATCH (n) OPTIONAL MATCH (n)-[ export function rgbToHSL(hex: string): string { // Remove the # if present const formattedHex = hex.replace(/^#/, ''); - + // Convert hex to RGB const r = parseInt(formattedHex.slice(0, 2), 16) / 255; const g = parseInt(formattedHex.slice(2, 4), 16) / 255; const b = parseInt(formattedHex.slice(4, 6), 16) / 255; - + const max = Math.max(r, g, b); const min = Math.min(r, g, b); let h = 0; @@ -58,24 +61,24 @@ export function rgbToHSL(hex: string): string { const l = (max + min) / 2; if (max !== min) { - const d = max - min; - s = l > 0.5 ? d / (2 - max - min) : d / (max + min); - - switch (max) { - case r: - h = (g - b) / d + (g < b ? 6 : 0); - break; - case g: - h = (b - r) / d + 2; - break; - case b: - h = (r - g) / d + 4; - break; - default: - h = 0; - break; - } - h /= 6; + const d = max - min; + s = l > 0.5 ? d / (2 - max - min) : d / (max + min); + + switch (max) { + case r: + h = (g - b) / d + (g < b ? 6 : 0); + break; + case g: + h = (b - r) / d + 2; + break; + case b: + h = (r - g) / d + 4; + break; + default: + h = 0; + break; + } + h /= 6; } // Convert to degrees and percentages