normalizeUrl

Normalize a URL path by removing redundant slashes and resolving dot and double-dot segments, producing a clean canonical form.

Usage

normalizeUrl normalizes a URL path by removing redundant slashes and resolving . and .. segments.

import { normalizeUrl } from '@movk/core'

normalizeUrl('https://example.com//api///users/')
// 'https://example.com/api/users/'

normalizeUrl('https://example.com/api/../users')
// 'https://example.com/users'

normalizeUrl('/api/./users/../posts')
// '/api/posts'

API

normalizeUrl(url)

Normalize a URL path.

Parameters

url
string required
The URL string.

Returns

returns
string
The normalized URL.

Changelog

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