Files
NapCatQQ/.pnpm-store/v3/files/7e/a8477e9a879945ad95185f01ea20184e66d0e5ce2ad5939caacd68d2766eba37dab17b80bde55a9ec4bc936f27aa766e767f325dfd0510782a472dd5d98cf6
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

27 lines
581 B
Plaintext

import { isAbsoluteUrl } from './isAbsoluteUrl'
const withoutTrailingSlash = (url: string) => url.replace(/\/$/, '')
const withoutLeadingSlash = (url: string) => url.replace(/^\//, '')
export function joinUrls(
base: string | undefined,
url: string | undefined,
): string {
if (!base) {
return url!
}
if (!url) {
return base
}
if (isAbsoluteUrl(url)) {
return url
}
const delimiter = base.endsWith('/') || !url.startsWith('?') ? '/' : ''
base = withoutTrailingSlash(base)
url = withoutLeadingSlash(url)
return `${base}${delimiter}${url}`
}