MCPcopy Create free account
hub / github.com/langgenius/dify / joinURL

Function joinURL

cli/src/http/url.ts:4–18  ·  view source on GitHub ↗
(base: string, path: string)

Source from the content-addressed store, hash-verified

2
3// Joins a base URL and a path, collapsing/inserting a single slash at the seam.
4export function joinURL(base: string, path: string): string {
5 if (base === '' || base === '/')
6 return path === '' ? '/' : path
7 if (path === '' || path === '/')
8 return base
9
10 const baseHasTrailing = base.endsWith('/')
11 const pathHasLeading = path.startsWith('/')
12
13 if (baseHasTrailing && pathHasLeading)
14 return base + path.slice(1)
15 if (!baseHasTrailing && !pathHasLeading)
16 return `${base}/${path}`
17 return base + path
18}
19
20// Only `undefined` is treated as "absent". Empty strings, 0, and false coerce
21// through `String(...)` and land on the wire — e.g. `{ name: '' }` becomes

Callers 2

buildRequestFunction · 0.85
url.test.tsFile · 0.85

Calls 3

endsWithMethod · 0.45
startsWithMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected