1 | # @jridgewell/resolve-uri
|
---|
2 |
|
---|
3 | > Resolve a URI relative to an optional base URI
|
---|
4 |
|
---|
5 | Resolve any combination of absolute URIs, protocol-realtive URIs, absolute paths, or relative paths.
|
---|
6 |
|
---|
7 | ## Installation
|
---|
8 |
|
---|
9 | ```sh
|
---|
10 | npm install @jridgewell/resolve-uri
|
---|
11 | ```
|
---|
12 |
|
---|
13 | ## Usage
|
---|
14 |
|
---|
15 | ```typescript
|
---|
16 | function resolve(input: string, base?: string): string;
|
---|
17 | ```
|
---|
18 |
|
---|
19 | ```js
|
---|
20 | import resolve from '@jridgewell/resolve-uri';
|
---|
21 |
|
---|
22 | resolve('foo', 'https://example.com'); // => 'https://example.com/foo'
|
---|
23 | ```
|
---|
24 |
|
---|
25 | | Input | Base | Resolution | Explanation |
|
---|
26 | |-----------------------|-------------------------|--------------------------------|--------------------------------------------------------------|
|
---|
27 | | `https://example.com` | _any_ | `https://example.com/` | Input is normalized only |
|
---|
28 | | `//example.com` | `https://base.com/` | `https://example.com/` | Input inherits the base's protocol |
|
---|
29 | | `//example.com` | _rest_ | `//example.com/` | Input is normalized only |
|
---|
30 | | `/example` | `https://base.com/` | `https://base.com/example` | Input inherits the base's origin |
|
---|
31 | | `/example` | `//base.com/` | `//base.com/example` | Input inherits the base's host and remains protocol relative |
|
---|
32 | | `/example` | _rest_ | `/example` | Input is normalized only |
|
---|
33 | | `example` | `https://base.com/dir/` | `https://base.com/dir/example` | Input is joined with the base |
|
---|
34 | | `example` | `https://base.com/file` | `https://base.com/example` | Input is joined with the base without its file |
|
---|
35 | | `example` | `//base.com/dir/` | `//base.com/dir/example` | Input is joined with the base's last directory |
|
---|
36 | | `example` | `//base.com/file` | `//base.com/example` | Input is joined with the base without its file |
|
---|
37 | | `example` | `/base/dir/` | `/base/dir/example` | Input is joined with the base's last directory |
|
---|
38 | | `example` | `/base/file` | `/base/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 |
|
---|