3.0.0 • Published 5 years ago

resolve-pathname v3.0.0

Weekly downloads
4,308,192
License
MIT
Repository
github
Last release
5 years ago

resolve-pathname Travis npm 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:

$ 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.

Usage

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 - node's url.resolve implementation for full URLs
  • resolve-url - A DOM-dependent implementation of the same algorithm
tjvhistory-with-raw-location@everything-registry/sub-chunk-2657history-ts@feature-hub/history-service@gift-adv/taro-components@gift-adv/taro-router@gong.h.liang/components@heng1025/epub-parse@harrysong/components@harrysong/components-react@hosoft/hos-plugin-doc-gen@financial-times/scout-history-workaround@flatfishjs/components@gtarojs/components@jooble-front/history@jieee/historyeodoes-eocodeeodoes-eodo-arxiveodoeodoeseodoes-coreeodoes-eventseodoes-microeventseodoes-muonseodoes-eodo-gcpfis-msprd-history_4_5_1fancy-historyhistory-with-queryhistory-fixhistory-palantir@tarojs/components@kokoro/tarojs-components@likun7981/history@infinitebrahmanuniverse/nolb-reso@mcro/router@respond-framework-test/link@robusgauli/react-history@robertwebbmodular/utils@rtarojs/components@rtarojs/components-react@recore/history@respond-framework-test/rudy@respond-framework/link@respond-framework/react@respond-framework/rudy@parallel-line/taro-components-react@pinweb/components@sifbuilder/eodo-eospace@sifbuilder/eodo-eotheme@sifbuilder/eodo-netlicore@sifbuilder/eodo-netlisrc@sifbuilder/eodo-netlitheme@sifbuilder/eodoes-core@sifbuilder/eodoes-events@sifbuilder/eodoes-microevents@sifbuilder/eodoes-muons@sifbuilder/eodoes-netlicore@sifbuilder/eodoes-netlisrc@sifbuilder/eodoes-netlitheme@sifbuilder/eodo-cli@sifbuilder/eodo-eocode@sifbuilder/eodo-eocore@sifbuilder/eodo-eodoer@sifbuilder/eodo-eorial@sifbuilder/events@sifbuilder/microevents@sifbuilder/report@sifbuilder/tears@teochengyong/docsify-server-renderer@smartface/router@vnxjs/components@vnxjs/components-react@wacii/history@wendal2841/scripts@wendal2841/history@wakeapp/taro-components-react@wakeda/taro-components-react@zstack/history@zalastax/nolb-reso@upmpjs/components@tymate/cra-template-tymate@yak-spirit/yak-swap-uidocsify-server-rendererdoc-scriptsdoczify-server-rendererdepot-historydocsify-builddocsify-easyswoole-rendererdp-taro-componentsdp-taro-routerrudy-historyi-redux-navigationrespond-framworkrr4il2forlernamy-api-compattigajsmy-compactmy-compat-api
3.0.0

5 years ago

3.0.0-beta.0

5 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago