renovate/lib/util/url.ts
2020-12-09 13:05:31 +01:00

19 lines
450 B
TypeScript

import urlJoin from 'url-join';
export function ensureTrailingSlash(url: string): string {
return url.replace(/\/?$/, '/');
}
export function resolveBaseUrl(baseUrl: string, input: string | URL): string {
const inputString = input.toString();
let host;
let pathname;
try {
({ host, pathname } = new URL(inputString));
} catch (e) {
pathname = inputString;
}
return host ? inputString : urlJoin(baseUrl, pathname || '');
}