1 | # @jridgewell/resolve-uri
|
---|
2 | [![Build Status](https://travis-ci.org/jridgewell/resolve-uri.svg?branch=master)](https://travis-ci.org/jridgewell/resolve-uri)
|
---|
3 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/jridgewell/resolve-uri/blob/master/LICENSE)
|
---|
4 |
|
---|
5 | > Resolve a URI relative to an optional base URI
|
---|
6 |
|
---|
7 | Resolve any combination of absolute URIs, protocol-realtive URIs, absolute paths, or relative paths.
|
---|
8 |
|
---|
9 | ## Installation
|
---|
10 |
|
---|
11 | ```sh
|
---|
12 | npm install @jridgewell/resolve-uri
|
---|
13 | ```
|
---|
14 |
|
---|
15 | ## Usage
|
---|
16 |
|
---|
17 | ```typescript
|
---|
18 | function resolve(input: string, base?: string): string;
|
---|
19 | ```
|
---|
20 |
|
---|
21 | ```js
|
---|
22 | import resolve from '@jridgewell/resolve-uri';
|
---|
23 |
|
---|
24 | resolve('foo', 'https://example.com'); // => 'https://example.com/foo'
|
---|
25 | ```
|
---|
26 |
|
---|
27 | | Input | Base | Resolution | Explanation |
|
---|
28 | |-----------------------|-------------------------|--------------------------------|--------------------------------------------------------------|
|
---|
29 | | `https://example.com` | _any_ | `https://example.com/` | Input is normalized only |
|
---|
30 | | `//example.com` | `https://base.com/` | `https://example.com/` | Input inherits the base's protocol |
|
---|
31 | | `//example.com` | _rest_ | `//example.com/` | Input is normalized only |
|
---|
32 | | `/example` | `https://base.com/` | `https://base.com/example` | Input inherits the base's origin |
|
---|
33 | | `/example` | `//base.com/` | `//base.com/example` | Input inherits the base's host and remains protocol relative |
|
---|
34 | | `/example` | _rest_ | `/example` | Input is normalized only |
|
---|
35 | | `example` | `https://base.com/dir/` | `https://base.com/dir/example` | Input is joined with the base |
|
---|
36 | | `example` | `https://base.com/file` | `https://base.com/example` | Input is joined with the base without its file |
|
---|
37 | | `example` | `//base.com/dir/` | `//base.com/dir/example` | Input is joined with the base's last directory |
|
---|
38 | | `example` | `//base.com/file` | `//base.com/example` | Input is joined with the base without its file |
|
---|
39 | | `example` | `/base/dir/` | `/base/dir/example` | Input is joined with the base's last directory |
|
---|
40 | | `example` | `/base/file` | `/base/example` | Input is joined with the base without its file |
|
---|
41 | | `example` | `base/dir/` | `base/dir/example` | Input is joined with the base's last directory |
|
---|
42 | | `example` | `base/file` | `base/example` | Input is joined with the base without its file |
|
---|