export const uint8ToDataURL = (uint8: Uint8Array, type: string) =>
  `data:${type},${btoa(new TextDecoder().decode(uint8))}`;
export function withParams(
  url: string,
  params: Record<string, string | number | boolean | undefined> = {},
) {
  const reg = /\?.*/;
  const searchParams = new URLSearchParams(
    Object.entries(params)
      .filter(([, v]) => v !== undefined)
      .map(([k, v]) => [k, String(v)]),
  );
  for (const [k, v] of new URLSearchParams(url.match(reg)?.[0].slice(1))) {
    searchParams.append(k, v);
  }
  url = url.replace(reg, '');
  if (!searchParams.size) {
    return url;
  }
  return `${url}?${searchParams}`;
}
