Coder Social home page Coder Social logo

resolve-url's Introduction

Deprecated

Is npm bugging you about this module being deprecated? You are probably depending on this module via the source-map-resolve package, which is deprecated too.

If you are looking for a way to resolve URLs in the browser, use URL.

Overview

browser support

Like Node.js’ path.resolve/url.resolve for the browser.

var resolveUrl = require("resolve-url")

window.location
// https://example.com/articles/resolving-urls/edit

resolveUrl("remove")
// https://example.com/articles/resolving-urls/remove

resolveUrl("/static/scripts/app.js")
// https://example.com/static/scripts/app.js

// Imagine /static/scripts/app.js contains `//# sourceMappingURL=../source-maps/app.js.map`
resolveUrl("/static/scripts/app.js", "../source-maps/app.js.map")
// https://example.com/static/source-maps/app.js.map

resolveUrl("/static/scripts/app.js", "../source-maps/app.js.map", "../coffee/app.coffee")
// https://example.com/static/coffee/app.coffee

resolveUrl("//cdn.example.com/jquery.js")
// https://cdn.example.com/jquery.js

resolveUrl("http://foo.org/")
// http://foo.org/

Installation

  • npm install resolve-url
  • bower install resolve-url
  • component install lydell/resolve-url

Works with CommonJS, AMD and browser globals, through UMD.

Usage

resolveUrl(...urls)

Pass one or more urls. Resolves the last one to an absolute url, using the previous ones and window.location.

It’s like starting out on window.location, and then clicking links with the urls as href attributes in order, from left to right.

Unlike Node.js’ path.resolve, this function always goes through all of the arguments, from left to right. path.resolve goes from right to left and only in the worst case goes through them all. Should that matter.

Actually, the function is really like clicking a lot of links in series: An actual <a> gets its href attribute set for each url! This means that the url resolution of the browser is used, which makes this module really light-weight.

Also note that this function deals with urls, not paths, so in that respect it has more in common with Node.js’ url.resolve. But the arguments are more like path.resolve.

Development

Tests

First off, run npm install to install testing modules.

npm test lints the code and then gives you a link to open in a browser of choice (using testling).

x-package.json5

package.json, component.json and bower.json are all generated from x-package.json5 by using xpkg. Only edit x-package.json5, and remember to run xpkg before commiting!

License

The X11 (“MIT”) License.

resolve-url's People

Contributors

lydell 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

Watchers

 avatar  avatar  avatar  avatar  avatar

resolve-url's Issues

Security issue found regarding url href replacement.

Hey, it looks like this code is showing up in automatic code analyzers as having an XSS DOM and Open Redirect vulnerability at these lines in resolve-url.js:

for (var index = 1; index < numUrls; index++) {
  a.href = arguments[index]
  resolved = a.href
  base.href = resolved
}

I don't know the entire context of how these lines are used, but one option is to run some sort of sanity checker or url white-list. Any thoughts? The idea is that you can inject javascript into an href tag (see bookmarklets).

Webpack 2.2.1 - Module build failed: ReferenceError: document is not defined

Updating to the latest Webpack version, we start getting the following errors for our scss files:

  ERROR in ./~/css-loader!./~/resolve-url/resolve-url.js!./~/sass-loader!./src
  /shared/components/NAME/NAME/steps/input/style.scss
   Module build failed: ReferenceError: document is not defined
        at Object.resolveUrl (C:\Temp\workspace\NAME\node_modules\resolve-
url\resolve-url.js:21:25)

Comment: browser-builtins

Just wanted to let you know, this kind of thing already exists in browser-builtins, which is what browserify and webpack use to polyfill node.js things they package for the browser. This includes a reproduction of the entire path module from node.js for the browser. All the path functions should work on URLs as well as normal file paths. If this were my repo, I'd put a deprecation message linking to that module and use it instead.

Add `files` in package.json

Heyo:

Currently your package is shipping a bunch of redundant files:

node_modules/resolve-url
├── LICENSE
├── bower.json
├── changelog.md
├── component.json
├── package.json
├── readme.md
├── resolve-url.js
└── test
    └── resolve-url.js

Please consider adding files to package.json, in this case files: [] will do as the main is always included when bunding.

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.