Skip to content

withoutLeadingSlash

Removes the leading slash / from the given URL if it is present.

This function is useful for ensuring that URLs are properly formatted without a leading slash, which is often required in web development for consistency and to avoid issues with relative paths.

Available since v1.0.0

import { withoutLeadingSlash } from '@helpers4/url';
withoutLeadingSlash(url: string): string
ParameterTypeDescription
urlstringThe URL string to be processed. Can be string, undefined, or null.

string — The URL string without a leading slash, or undefined if the input is undefined, or null if the input is null.

Strips the leading slash from a URL path.

withoutLeadingSlash('/path/to/resource')
// => 'path/to/resource'

View source on GitHub