Skip to content

Function: urlToRelativePath() ​

ts
function urlToRelativePath(url, base): string;

Defined in: urlToRelativePath.ts:19

Constructs a relative path from a URL.

If url is already relative, or its origin differs from base, the function returns url unchanged.

Parameters ​

url ​

string

The destination URL

base ​

string

The base URL

Returns ​

string

The relative path

Example ​

ts
equal(
	urlToRelativePath(
		'http://test.com/base/segments/video/1.mp4',
		'http://test.com/base/manifest/manifest.mpd',
	),
	'../segments/video/1.mp4',
)

A Streaming Video Technology Alliance project.