Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jridgewell/resolve-uri
Resolve a URI relative to an optional base URI
https://github.com/jridgewell/resolve-uri
Last synced: 4 days ago
JSON representation
Resolve a URI relative to an optional base URI
- Host: GitHub
- URL: https://github.com/jridgewell/resolve-uri
- Owner: jridgewell
- License: mit
- Created: 2019-07-14T20:11:48.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-02T18:23:57.000Z (23 days ago)
- Last Synced: 2024-12-13T16:04:18.841Z (12 days ago)
- Language: JavaScript
- Size: 840 KB
- Stars: 11
- Watchers: 3
- Forks: 7
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
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 |