Skip to content

addLeadingSlash

Simple helper that adds a leading slash / if not yet present.

Available since v1.0.1

import { addLeadingSlash } from '@helpers4/url';
addLeadingSlash(url: string): string
ParameterTypeDescription
urlstringA valid URL.

string — The URL with a leading slash, unchanged if it already had one.

addLeadingSlash('your/path/without/leading/slash');
// => '/your/path/without/leading/slash'

View on npm