Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Anchel123 committed Feb 5, 2025
1 parent 30af6b4 commit ec639ff
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ export function cn(...inputs: ClassValue[]) {
}

export async function securedFetch(
url: string,
input: string,
init: RequestInit,
role?: string,
toast?: any,
): Promise<Response> {

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()
Expand All @@ -45,37 +48,37 @@ 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;
let s = 0;
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
Expand Down

0 comments on commit ec639ff

Please sign in to comment.