Skip to content

Resolve a URI relative to an optional base URI

License

Notifications You must be signed in to change notification settings

jridgewell/resolve-uri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Feb 14, 2024
caa7a29 · Feb 14, 2024
Feb 5, 2022
Feb 14, 2024
Jul 5, 2022
Jul 14, 2019
Jun 27, 2022
Jul 14, 2019
Feb 5, 2022
Jul 15, 2019
Jan 23, 2022
Jul 14, 2019
Feb 14, 2024
Feb 14, 2024
Mar 14, 2021
Jul 15, 2019
Feb 5, 2022
Mar 14, 2021
Jun 26, 2022

Repository files navigation

@jridgewell/resolve-uri

Resolve a URI relative to an optional base URI

Resolve any combination of absolute URIs, protocol-realtive URIs, absolute paths, or relative paths.

Installation

npm install @jridgewell/resolve-uri

Usage

function resolve(input: string, base?: string): string;
import resolve from '@jridgewell/resolve-uri';

resolve('foo', 'https://example.com'); // => 'https://example.com/foo'
Input Base Resolution Explanation
https://example.com any https://example.com/ Input is normalized only
//example.com https://base.com/ https://example.com/ Input inherits the base's protocol
//example.com rest //example.com/ Input is normalized only
/example https://base.com/ https://base.com/example Input inherits the base's origin
/example //base.com/ //base.com/example Input inherits the base's host and remains protocol relative
/example rest /example Input is normalized only
example https://base.com/dir/ https://base.com/dir/example Input is joined with the base
example https://base.com/file https://base.com/example Input is joined with the base without its file
example //base.com/dir/ //base.com/dir/example Input is joined with the base's last directory
example //base.com/file //base.com/example Input is joined with the base without its file
example /base/dir/ /base/dir/example Input is joined with the base's last directory
example /base/file /base/example Input is joined with the base without its file
example base/dir/ base/dir/example Input is joined with the base's last directory
example base/file base/example Input is joined with the base without its file