|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
581 bytes
|
| Line | |
|---|
| 1 | import { isAbsoluteUrl } from './isAbsoluteUrl'
|
|---|
| 2 |
|
|---|
| 3 | const withoutTrailingSlash = (url: string) => url.replace(/\/$/, '')
|
|---|
| 4 | const withoutLeadingSlash = (url: string) => url.replace(/^\//, '')
|
|---|
| 5 |
|
|---|
| 6 | export function joinUrls(
|
|---|
| 7 | base: string | undefined,
|
|---|
| 8 | url: string | undefined,
|
|---|
| 9 | ): string {
|
|---|
| 10 | if (!base) {
|
|---|
| 11 | return url!
|
|---|
| 12 | }
|
|---|
| 13 | if (!url) {
|
|---|
| 14 | return base
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | if (isAbsoluteUrl(url)) {
|
|---|
| 18 | return url
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | const delimiter = base.endsWith('/') || !url.startsWith('?') ? '/' : ''
|
|---|
| 22 | base = withoutTrailingSlash(base)
|
|---|
| 23 | url = withoutLeadingSlash(url)
|
|---|
| 24 |
|
|---|
| 25 | return `${base}${delimiter}${url}`
|
|---|
| 26 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.