joinUrl

Join URL path segments into a single path, collapsing duplicate slashes so concatenated routes and endpoints stay well formed.

Usage

joinUrl joins URL path segments together.

import { joinUrl } from '@movk/core'

joinUrl('https://example.com', 'api', 'users')
// 'https://example.com/api/users'

joinUrl('https://example.com/', '/api/', '/users/')
// 'https://example.com/api/users/'

joinUrl('/api', 'users', '123')
// '/api/users/123'

API

joinUrl(...parts)

Join URL path segments.

Parameters

parts
string[] required
The URL segments to join.

Returns

returns
string
The joined URL.

Changelog

No recent changes
Copyright © 2024 - 2026 YiXuan - MIT License