# resolve-url

> Like Node.js’ `path.resolve`/`url.resolve` for the browser.

Latest version **0.2.1** (published 2014-02-25) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install resolve-url
pnpm add resolve-url
yarn add resolve-url
bun add resolve-url
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2014-02-25 |
| First published | 2014-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 53 |
| Author | Simon Lydell |
| Maintainers | lydell |
| Keywords | resolve, url |

## Links

- npm: https://www.npmjs.com/package/resolve-url
- Repository: https://github.com/lydell/resolve-url
- Issues: https://github.com/lydell/resolve-url/issues
- npm.io page: https://npm.io/package/resolve-url

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

- 0.2.1 (latest) — 2014-02-25
- 0.2.0 — 2014-02-24
- 0.1.0 — 2014-02-23

## README

Overview
========

[![browser support](https://ci.testling.com/lydell/resolve-url.png)](https://ci.testling.com/lydell/resolve-url)

Like Node.js’ [`path.resolve`]/[`url.resolve`] for the browser.

```js
var resolveUrl = require("resolve-url")

window.location
// https://example.com/articles/resolving-urls/edit

resolveUrl("remove")
// https://example.com/articles/resolving-urls/remove

resolveUrl("/static/scripts/app.js")
// https://example.com/static/scripts/app.js

// Imagine /static/scripts/app.js contains `//# sourceMappingURL=../source-maps/app.js.map`
resolveUrl("/static/scripts/app.js", "../source-maps/app.js.map")
// https://example.com/static/source-maps/app.js.map

resolveUrl("/static/scripts/app.js", "../source-maps/app.js.map", "../coffee/app.coffee")
// https://example.com/static/coffee/app.coffee

resolveUrl("//cdn.example.com/jquery.js")
// https://cdn.example.com/jquery.js

resolveUrl("http://foo.org/")
// http://foo.org/
```


Installation
============

- `npm install resolve-url`
- `bower install resolve-url`
- `component install lydell/resolve-url`

Works with CommonJS, AMD and browser globals, through UMD.


Usage
=====

### `resolveUrl(...urls)` ###

Pass one or more urls. Resolves the last one to an absolute url, using the
previous ones and `window.location`.

It’s like starting out on `window.location`, and then clicking links with the
urls as `href` attributes in order, from left to right.

Unlike Node.js’ [`path.resolve`], this function always goes through all of the
arguments, from left to right. `path.resolve` goes from right to left and only
in the worst case goes through them all. Should that matter.

Actually, the function is _really_ like clicking a lot of links in series: An
actual `<a>` gets its `href` attribute set for each url! This means that the
url resolution of the browser is used, which makes this module really
light-weight.

Also note that this functions deals with urls, not paths, so in that respect it
has more in common with Node.js’ [`url.resolve`]. But the arguments are more
like [`path.resolve`].

[`path.resolve`]: http://nodejs.org/api/path.html#path_path_resolve_from_to
[`url.resolve`]: http://nodejs.org/api/url.html#url_url_resolve_from_to


Tests
=====

Run `npm test`, which lints the code and then gives you a link to open in a
browser of choice (using `testling`).


License
=======

[The X11 (“MIT”) License](LICENSE).

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