mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
15 lines
374 B
TypeScript
15 lines
374 B
TypeScript
export const buildURL = (baseUrl: string, relativePath: string): string => {
|
|
try {
|
|
return new URL(relativePath).toString();
|
|
} catch {
|
|
try {
|
|
return new URL(
|
|
relativePath.replace(/^\//, ''),
|
|
baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`,
|
|
).toString();
|
|
} catch {
|
|
throw new Error(`Invalid base URL: ${baseUrl}`);
|
|
}
|
|
}
|
|
};
|