source: trip-planner-front/node_modules/resolve-url/readme.md@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[6a3a178]1Overview
2========
3
4[![browser support](https://ci.testling.com/lydell/resolve-url.png)](https://ci.testling.com/lydell/resolve-url)
5
6Like Node.js’ [`path.resolve`]/[`url.resolve`] for the browser.
7
8```js
9var resolveUrl = require("resolve-url")
10
11window.location
12// https://example.com/articles/resolving-urls/edit
13
14resolveUrl("remove")
15// https://example.com/articles/resolving-urls/remove
16
17resolveUrl("/static/scripts/app.js")
18// https://example.com/static/scripts/app.js
19
20// Imagine /static/scripts/app.js contains `//# sourceMappingURL=../source-maps/app.js.map`
21resolveUrl("/static/scripts/app.js", "../source-maps/app.js.map")
22// https://example.com/static/source-maps/app.js.map
23
24resolveUrl("/static/scripts/app.js", "../source-maps/app.js.map", "../coffee/app.coffee")
25// https://example.com/static/coffee/app.coffee
26
27resolveUrl("//cdn.example.com/jquery.js")
28// https://cdn.example.com/jquery.js
29
30resolveUrl("http://foo.org/")
31// http://foo.org/
32```
33
34
35Installation
36============
37
38- `npm install resolve-url`
39- `bower install resolve-url`
40- `component install lydell/resolve-url`
41
42Works with CommonJS, AMD and browser globals, through UMD.
43
44
45Usage
46=====
47
48### `resolveUrl(...urls)` ###
49
50Pass one or more urls. Resolves the last one to an absolute url, using the
51previous ones and `window.location`.
52
53It’s like starting out on `window.location`, and then clicking links with the
54urls as `href` attributes in order, from left to right.
55
56Unlike Node.js’ [`path.resolve`], this function always goes through all of the
57arguments, from left to right. `path.resolve` goes from right to left and only
58in the worst case goes through them all. Should that matter.
59
60Actually, the function is _really_ like clicking a lot of links in series: An
61actual `<a>` gets its `href` attribute set for each url! This means that the
62url resolution of the browser is used, which makes this module really
63light-weight.
64
65Also note that this functions deals with urls, not paths, so in that respect it
66has more in common with Node.js’ [`url.resolve`]. But the arguments are more
67like [`path.resolve`].
68
69[`path.resolve`]: http://nodejs.org/api/path.html#path_path_resolve_from_to
70[`url.resolve`]: http://nodejs.org/api/url.html#url_url_resolve_from_to
71
72
73Tests
74=====
75
76Run `npm test`, which lints the code and then gives you a link to open in a
77browser of choice (using `testling`).
78
79
80License
81=======
82
83[The X11 (“MIT”) License](LICENSE).
Note: See TracBrowser for help on using the repository browser.