resolve-pathname
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:
$ npm install --save resolve-pathname
Then, use as you would anything else:
import resolvePathname from 'resolve-pathname'
var resolvePathname = require('resolve-pathname')
The UMD build is also available on unpkg:
<script src="https://unpkg.com/resolve-pathname/umd/resolve-pathname.min.js"></script>
You can find the library on window.resolvePathname
.
Usage
import resolvePathname from 'resolve-pathname'
resolvePathname('about', '/company/jobs')
resolvePathname('../jobs', '/company/team/ceo')
resolvePathname('about')
resolvePathname('/about')
resolvePathname('about', '/company/info/')
resolvePathname('cto', window.location.pathname)
resolvePathname('../jobs', window.location.pathname)
Prior Work
- url.resolve - node's
url.resolve
implementation for full URLs - resolve-url - A DOM-dependent implementation of the same algorithm