3.0.0 • Published 7 years ago

resolve-pathname v3.0.0

Weekly downloads
4,308,192
License
MIT
Repository
github
Last release
7 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-tstarojs-react-componentstaro-router-kdtaro-componenttaro-jh-virtual-listwk-taro-componentswk-taro-components-reactwodax-umi-historyworker-react-routervscode-theme-to@docusaurus/utils@cloudimage-strapi/content-plugin@developerportalsg/docsify-server-renderer@dev-tsc/history@rtarojs/components@rtarojs/components-reacttwitch-historyumi-historytigajstmp-history@arcblock/gatsby-theme-docs@artkravchenko/rudy-history@agreejs/components@alicloud/xconsole-rc-base-link@beforeyoubid/alpha@aetherall/react-router-relative-link@cerebras/ui128981semzubyo-routerzubtesttodayunplugin-markdown-2-htmlurljoin.js@parallel-line/taro-components-react@financial-times/scout-history-workaround@feature-hub/history-service@gtarojs/components@harrysong/components@harrysong/components-react@hosoft/hos-plugin-doc-gen@heng1025/epub-parse@hexagon6/solid-kit@flatfishjs/components@gong.h.liang/components@gift-adv/taro-components@gift-adv/taro-router@infinitebrahmanuniverse/nolb-reso@likun7981/history@nader3456/zigbee2mqtt-frontend@mcro/router@jieee/history@jooble-front/history@kokoro/tarojs-components@pinweb/components@recore/history@respond-framework-test/link@respond-framework-test/rudy@respond-framework/link@respond-framework/react@respond-framework/rudy@smartface/router@robertwebbmodular/utils@robusgauli/react-history@sifbuilder/eodo-cli@sifbuilder/eodo-eocode@sifbuilder/eodo-eocore@sifbuilder/eodo-eodoer@sifbuilder/eodo-eorial@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/events@sifbuilder/microevents@sifbuilder/report@sifbuilder/tearsmy-api-compatmy-compactmy-compat-apimp-loadermodify-umi-historyminiapp-rax-frameworkminiapp-framework-webminiapp-frameworkmetalsmith-linkcheckmypluginlolparse-epubpc-miniapp-frameworkrr4irudy-history
3.0.0

7 years ago

3.0.0-beta.0

7 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago