···11+import { DefaultedFetcherOptions } from "@movie-web/providers";
22+33+export function makeFullUrl(
44+ url: string,
55+ ops?: DefaultedFetcherOptions,
66+): string {
77+ // glue baseUrl and rest of url together
88+ let leftSide = ops?.baseUrl ?? "";
99+ let rightSide = url;
1010+1111+ // left side should always end with slash, if its set
1212+ if (leftSide.length > 0 && !leftSide.endsWith("/")) leftSide += "/";
1313+1414+ // right side should never start with slash
1515+ if (rightSide.startsWith("/")) rightSide = rightSide.slice(1);
1616+1717+ const fullUrl = leftSide + rightSide;
1818+ if (!fullUrl.startsWith("http://") && !fullUrl.startsWith("https://"))
1919+ throw new Error(
2020+ `Invald URL -- URL doesn't start with a http scheme: '${fullUrl}'`,
2121+ );
2222+2323+ const parsedUrl = new URL(fullUrl);
2424+ Object.entries(ops?.query ?? {}).forEach(([k, v]) => {
2525+ parsedUrl.searchParams.set(k, v as string);
2626+ });
2727+2828+ return parsedUrl.toString();
2929+}