Skip to content

relativeURLToAbsolute

Converts a relative URL to an absolute URL using the current document base URI.

Available since v1.0.0

import { relativeURLToAbsolute } from '@helpers4/url';
relativeURLToAbsolute(relativeUrl: string): string
ParameterTypeDescription
relativeUrlstringThe relative URL to convert

string — The absolute URL

Prepends the base URI to a relative path, cleaning duplicate slashes.

relativeURLToAbsolute('/api/data')
// => 'http://localhost/api/data' (depends on document.baseURI)

View source on GitHub