# @jridgewell/resolve-uri

> Resolve a URI relative to an optional base URI

Latest version **3.1.2** (published 2024-02-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jridgewell/resolve-uri
pnpm add @jridgewell/resolve-uri
yarn add @jridgewell/resolve-uri
bun add @jridgewell/resolve-uri
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.1.2 |
| Published | 2024-02-14 |
| First published | 2019-07-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=6.0.0 |
| Dependencies | 0 |
| Unpacked size | 51.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Justin Ridgewell |
| Maintainers | jridgewell |
| Keywords | resolve, uri, url, path |

## Links

- npm: https://www.npmjs.com/package/@jridgewell/resolve-uri
- Repository: https://github.com/jridgewell/resolve-uri
- Homepage: https://github.com/jridgewell/resolve-uri#readme
- Issues: https://github.com/jridgewell/resolve-uri/issues
- npm.io page: https://npm.io/package/@jridgewell/resolve-uri

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 3.1.2 (latest) — 2024-02-14
- 3.1.1 — 2023-04-07
- 3.1.0 — 2022-07-05
- 3.0.8 — 2022-06-26
- 3.0.7 — 2022-05-05
- 3.0.6 — 2022-04-22
- 3.0.5 — 2022-02-11
- 3.0.4 — 2022-02-03
- 3.0.3 — 2022-01-23
- 3.0.2 — 2022-01-23
- 3.0.1 — 2022-01-23
- 3.0.0 — 2022-01-22
- 2.0.0 — 2021-03-23
- 1.0.0 — 2019-07-15
- 0.1.0 — 2019-07-14

## README

# @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

```sh
npm install @jridgewell/resolve-uri
```

## Usage

```typescript
function resolve(input: string, base?: string): string;
```

```js
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               |

---
_Source: https://npm.io/package/@jridgewell/resolve-uri · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
