Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
811 bytes
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | /* eslint-disable */
|
---|
4 | function normalizeUrl(pathComponents) {
|
---|
5 | return pathComponents.reduce(function (accumulator, item) {
|
---|
6 | switch (item) {
|
---|
7 | case "..":
|
---|
8 | accumulator.pop();
|
---|
9 | break;
|
---|
10 |
|
---|
11 | case ".":
|
---|
12 | break;
|
---|
13 |
|
---|
14 | default:
|
---|
15 | accumulator.push(item);
|
---|
16 | }
|
---|
17 |
|
---|
18 | return accumulator;
|
---|
19 | }, []).join("/");
|
---|
20 | }
|
---|
21 |
|
---|
22 | module.exports = function (urlString) {
|
---|
23 | urlString = urlString.trim();
|
---|
24 |
|
---|
25 | if (/^data:/i.test(urlString)) {
|
---|
26 | return urlString;
|
---|
27 | }
|
---|
28 |
|
---|
29 | var protocol = urlString.indexOf("//") !== -1 ? urlString.split("//")[0] + "//" : "";
|
---|
30 | var components = urlString.replace(new RegExp(protocol, "i"), "").split("/");
|
---|
31 | var host = components[0].toLowerCase().replace(/\.$/, "");
|
---|
32 | components[0] = "";
|
---|
33 | var path = normalizeUrl(components);
|
---|
34 | return protocol + host + path;
|
---|
35 | }; |
---|
Note:
See
TracBrowser
for help on using the repository browser.