Big update!Announcing Socket for GitHub 1.0. Learn more
Socket
BlogLoveFAQ
Install
Log in

resolve-url

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Issues
File Explorer

Advanced tools

resolve-url

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

    0.2.1latest

Version published
Maintainers
1
Weekly downloads
18,340,427
decreased by-3.56%

Weekly downloads

Changelog

Source

Version 0.2.1 (2014-02-25) ###

  • Fix edge case when (accidentally) supplying only one argument, and that argument happens to be a falsy value such as undefined or null.

Readme

Source

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

Tests

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

License

The X11 (“MIT”) License.

Keywords

FAQs

What is resolve-url?

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

Is resolve-url popular?

The npm package resolve-url receives a total of 17,268,506 weekly downloads. As such, resolve-url popularity was classified as popular.

Is resolve-url well maintained?

We found that resolve-url demonstrated a not healthy version release cadence and project activity. It has 1 open source maintainer collaborating on the project.

Last updated on 25 Feb 2014
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc