Coder Social home page Coder Social logo

resolve-pathname's Introduction

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

resolve-pathname's People

Contributors

greenkeeperio-bot avatar mjackson avatar npmcdn-to-unpkg-bot avatar timdorr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

resolve-pathname's Issues

Absolute path check

Should following
const isAbsolute = (pathname) =>
pathname.charAt(0) === '/'

instead be
const isAbsolute = (pathname) =>
pathname.charAt(0) !== '/'

breaking change from 2.1.0 to 2.2.0

there is a breaking change between 2.1.0 and 2.2.0 in the way of importing this package

For 2.1.0, we need do it this way:

import * as resolvepath from 'resolve-pathname'

and for 2.2.0:

import resolvepath from 'resolve-pathname'

and if we had add this as a dependencies without accurately specify the version like yarn add [email protected], then the next time we do yarn or npm install, it will install version 2.2.0, which makes our code not working anymore.

Add licence file

Hi, can you please add a licence file to the project? Also, am I correct assuming the project is under MIT licence just the file is missing? (package.json indicates MIT, that's why I think so)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.