# relative-to-absolute-iri

> Resolve relative IRIs to absolute IRIs given a base IRI

Latest version **1.0.8** (published 2026-03-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install relative-to-absolute-iri
pnpm add relative-to-absolute-iri
yarn add relative-to-absolute-iri
bun add relative-to-absolute-iri
```

## Health

**Score 55/100 (C)** — status: stable.

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

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2026-03-05 |
| First published | 2018-10-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 31.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Ruben Taelman |
| Maintainers | rubensworks |
| Keywords | iri, uri, url, relative, absolute, base, resolve, RFC3986 |

## Links

- npm: https://www.npmjs.com/package/relative-to-absolute-iri
- Repository: https://github.com/rubensworks/relative-to-absolute-iri.js
- Homepage: https://github.com/rubensworks/relative-to-absolute-iri.js#readme
- Issues: https://github.com/rubensworks/relative-to-absolute-iri.js/issues
- Funding: https://github.com/sponsors/rubensworks/
- npm.io page: https://npm.io/package/relative-to-absolute-iri

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

- 1.0.8 (latest) — 2026-03-05
- 1.0.7 — 2022-11-09
- 1.0.6 — 2020-06-19
- 1.0.5 — 2019-06-20
- 1.0.4 — 2019-06-18
- 1.0.3 — 2019-06-12
- 1.0.2 — 2019-01-14
- 1.0.1 — 2018-12-06
- 1.0.0 — 2018-10-31

## README

# Relative to Absolute IRI

[![Build status](https://github.com/rubensworks/relative-to-absolute-iri.js/workflows/CI/badge.svg)](https://github.com/rubensworks/relative-to-absolute-iri.js/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/github/rubensworks/relative-to-absolute-iri.js/badge.svg?branch=master)](https://coveralls.io/github/rubensworks/relative-to-absolute-iri.js?branch=master)
[![npm version](https://badge.fury.io/js/relative-to-absolute-iri.svg)](https://www.npmjs.com/package/relative-to-absolute-iri)

Resolve relative IRIs to absolute IRIs given a base IRI,
conforming to [RFC3986](https://www.ietf.org/rfc/rfc3986.txt).

## Installation

```bash
$ yarn install relative-to-absolute-iri
```

This package also works out-of-the-box in browsers via tools such as [webpack](https://webpack.js.org/) and [browserify](http://browserify.org/).

## Require

```javascript
import {resolve} from "relative-to-absolute-iri";
```

_or_

```javascript
const resolve = require("relative-to-absolute-iri").resolve;
```

## Usage

### Parameters

This library exposes a single `resolve` function
that must be called with a relative IRI (string) as first argument,
and an optional base IRI (string) as second argument.
It will output an absolute IRI (string).

```javascript
resolve('relative', 'http://base.org/'); // Outputs 'http://base.org/relative'
```

### Relative IRIs

IRIs that are already relative will remain relative:

```javascript
resolve('http://example.org/'); // Outputs 'http://example.org/'
resolve('http://example.org/', 'http://base.org/'); // Outputs 'http://example.org/'
```

### Hashes

Fragments/hashes in relative IRIs are also taken into account.

```javascript
resolve('#abc', 'http://base.org/'); // Outputs 'http://base.org/#abc'
```

### Invalid base IRI

Invalid base IRIs cause an error to be thrown.

```javascript
resolve('abc', 'def'); // Error
```

### Relative to scheme

When a relative IRI starts with a `//`, then the scheme of the base IRI will be used.

```javascript
resolve('//abc', 'http://base.org/'); // Outputs 'http://abc'
```

### Absolute relative IRIs

Relative IRIs that starts with a `/` erase the path of the base IRI.

```javascript
resolve('/abc/def/', 'http://base.org/123/456/'); // Outputs 'http://base.org/abc/def/'
```

### Collapsing of dots

Relative IRIs that point to the current directory (`.`)
or parent directory (`..`) are collapsed.

```javascript
resolve('xyz', 'http://aa/parent/parent/../../a'); // Outputs 'http://aa/xyz'
resolve('xyz', 'http://aa/././a'); // Outputs 'http://aa/xyz'
```

## License
This software is written by [Ruben Taelman](http://rubensworks.net/).

This code is released under the [MIT license](http://opensource.org/licenses/MIT).

---
_Source: https://npm.io/package/relative-to-absolute-iri · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
