2024-08-25 00:45:44 +00:00
|
|
|
import { type ClassValue, clsx } from "clsx"
|
|
|
|
|
import { twMerge } from "tailwind-merge"
|
|
|
|
|
|
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
|
|
|
return twMerge(clsx(inputs))
|
|
|
|
|
}
|
2024-08-25 02:39:59 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a list of (potentially undefined) query parameters to a path.
|
|
|
|
|
*
|
|
|
|
|
* @param path The path to add the query parameters to.
|
|
|
|
|
* @param queryParams A list of key-value pairs (key=param name, value=param value) to add to the path.
|
|
|
|
|
* @returns The path with the query parameters added.
|
|
|
|
|
*/
|
|
|
|
|
export const createPathWithQueryParams = (path: string, ...queryParams: [string, string | null][]) => {
|
|
|
|
|
// Filter out undefined values
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
|
queryParams = queryParams.filter(([_key, value]) => value !== null);
|
|
|
|
|
|
|
|
|
|
if (queryParams.length === 0) {
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const queryString = queryParams.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value ?? '')}`).join('&');
|
|
|
|
|
return `${path}?${queryString}`;
|
|
|
|
|
}
|