added "buildURL" helper function

This commit is contained in:
Kartik Buttan
2024-09-17 21:01:23 +05:30
parent f891155b0b
commit daa2e0611f
2 changed files with 16 additions and 3 deletions

View File

@@ -26,3 +26,14 @@ export const getFromQuery = ({
return defaultValue;
}
};
export const buildURL = (baseUrl: string, relativePath: string): string => {
try {
new URL(baseUrl);
} catch {
throw new Error(`Invalid base URL: ${baseUrl}`);
}
const url = new URL(relativePath, baseUrl);
return url.toString();
};