Emmanuil c2e0590820 31.07.2020 | 4 years ago | |
---|---|---|
.. | ||
cjs | 4 years ago | |
esm | 4 years ago | |
umd | 4 years ago | |
LICENSE | 4 years ago | |
README.md | 4 years ago | |
index.js | 4 years ago | |
package.json | 4 years ago |
resolve-pathname resolves URL pathnames identical to the way browsers resolve the pathname of an <a href>
value. The goals are:
Using npm:
$ npm install --save resolve-pathname
Then, use as you would anything else:
// using ES6 modules
import resolvePathname from 'resolve-pathname';
// using CommonJS modules
var resolvePathname = require('resolve-pathname');
The UMD build is also available on unpkg:
<script src="https://unpkg.com/resolve-pathname"></script>
You can find the library on window.resolvePathname
.
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
url.resolve
implementation for full URLs