# resolve-pathname

> Resolve URL pathnames using JavaScript

Latest version **3.0.0** (published 2018-12-02) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2018-12-02 |
| First published | 2016-03-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 65 |
| Author | Michael Jackson |
| Maintainers | mjackson |

## Links

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

## Recent versions

- 3.0.0 (latest) — 2018-12-02
- 3.0.0-beta.0 (next) — 2018-12-02
- 2.2.0 — 2017-08-23
- 2.1.0 — 2017-04-21
- 2.0.2 — 2016-10-08
- 2.0.1 — 2016-10-08
- 2.0.0 — 2016-03-19
- 1.0.5 — 2016-03-17
- 1.0.4 — 2016-03-15
- 1.0.3 — 2016-03-14
- 1.0.2 — 2016-03-11
- 1.0.1 — 2016-03-10
- 1.0.0 — 2016-03-10

## README

# resolve-pathname [![Travis][build-badge]][build] [![npm package][npm-badge]][npm]

[build-badge]: https://img.shields.io/travis/mjackson/resolve-pathname/master.svg?style=flat-square
[build]: https://travis-ci.org/mjackson/resolve-pathname
[npm-badge]: https://img.shields.io/npm/v/resolve-pathname.svg?style=flat-square
[npm]: https://www.npmjs.org/package/resolve-pathname

[resolve-pathname](https://www.npmjs.com/package/resolve-pathname) resolves URL pathnames identical to the way browsers resolve the pathname of an `<a href>` value. The goals are:

- 100% compatibility with browser pathname resolution
- Pure JavaScript implementation (no DOM dependency)

## Installation

Using [npm](https://www.npmjs.com/):

    $ npm install --save resolve-pathname

Then, use as you would anything else:

```js
// using ES6 modules
import resolvePathname from 'resolve-pathname';

// using CommonJS modules
var resolvePathname = require('resolve-pathname');
```

The UMD build is also available on [unpkg](https://unpkg.com):

```html
<script src="https://unpkg.com/resolve-pathname"></script>
```

You can find the library on `window.resolvePathname`.

## Usage

```js
import resolvePathname from 'resolve-pathname';

// Simply pass the pathname you'd like to resolve. Second
// argument is the path we're coming from, or the current
// pathname. It defaults to "/".
resolvePathname('about', '/company/jobs'); // /company/about
resolvePathname('../jobs', '/company/team/ceo'); // /company/jobs
resolvePathname('about'); // /about
resolvePathname('/about'); // /about

// Index paths (with a trailing slash) are also supported and
// work the same way as browsers.
resolvePathname('about', '/company/info/'); // /company/info/about

// In browsers, it's easy to resolve a URL pathname relative to
// the current page. Just use window.location! e.g. if
// window.location.pathname == '/company/team/ceo' then
resolvePathname('cto', window.location.pathname); // /company/team/cto
resolvePathname('../jobs', window.location.pathname); // /company/jobs
```

## Prior Work

- [url.resolve](https://nodejs.org/api/url.html#url_url_resolve_from_to) - node's `url.resolve` implementation for full URLs
- [resolve-url](https://www.npmjs.com/package/resolve-url) - A DOM-dependent implementation of the same algorithm

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