4 [![browser support](https://ci.testling.com/lydell/resolve-url.png)](https://ci.testling.com/lydell/resolve-url)
\r
6 Like Node.js’ [`path.resolve`]/[`url.resolve`] for the browser.
\r
9 var resolveUrl = require("resolve-url")
\r
12 // https://example.com/articles/resolving-urls/edit
\r
14 resolveUrl("remove")
\r
15 // https://example.com/articles/resolving-urls/remove
\r
17 resolveUrl("/static/scripts/app.js")
\r
18 // https://example.com/static/scripts/app.js
\r
20 // Imagine /static/scripts/app.js contains `//# sourceMappingURL=../source-maps/app.js.map`
\r
21 resolveUrl("/static/scripts/app.js", "../source-maps/app.js.map")
\r
22 // https://example.com/static/source-maps/app.js.map
\r
24 resolveUrl("/static/scripts/app.js", "../source-maps/app.js.map", "../coffee/app.coffee")
\r
25 // https://example.com/static/coffee/app.coffee
\r
27 resolveUrl("//cdn.example.com/jquery.js")
\r
28 // https://cdn.example.com/jquery.js
\r
30 resolveUrl("http://foo.org/")
\r
38 - `npm install resolve-url`
\r
39 - `bower install resolve-url`
\r
40 - `component install lydell/resolve-url`
\r
42 Works with CommonJS, AMD and browser globals, through UMD.
\r
48 ### `resolveUrl(...urls)` ###
\r
50 Pass one or more urls. Resolves the last one to an absolute url, using the
\r
51 previous ones and `window.location`.
\r
53 It’s like starting out on `window.location`, and then clicking links with the
\r
54 urls as `href` attributes in order, from left to right.
\r
56 Unlike Node.js’ [`path.resolve`], this function always goes through all of the
\r
57 arguments, from left to right. `path.resolve` goes from right to left and only
\r
58 in the worst case goes through them all. Should that matter.
\r
60 Actually, the function is _really_ like clicking a lot of links in series: An
\r
61 actual `<a>` gets its `href` attribute set for each url! This means that the
\r
62 url resolution of the browser is used, which makes this module really
\r
65 Also note that this functions deals with urls, not paths, so in that respect it
\r
66 has more in common with Node.js’ [`url.resolve`]. But the arguments are more
\r
67 like [`path.resolve`].
\r
69 [`path.resolve`]: http://nodejs.org/api/path.html#path_path_resolve_from_to
\r
70 [`url.resolve`]: http://nodejs.org/api/url.html#url_url_resolve_from_to
\r
76 Run `npm test`, which lints the code and then gives you a link to open in a
\r
77 browser of choice (using `testling`).
\r
83 [The X11 (“MIT”) License](LICENSE).
\r