You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
811 B
35 lines
811 B
"use strict";
|
|
|
|
/* eslint-disable */
|
|
function normalizeUrl(pathComponents) {
|
|
return pathComponents.reduce(function (accumulator, item) {
|
|
switch (item) {
|
|
case "..":
|
|
accumulator.pop();
|
|
break;
|
|
|
|
case ".":
|
|
break;
|
|
|
|
default:
|
|
accumulator.push(item);
|
|
}
|
|
|
|
return accumulator;
|
|
}, []).join("/");
|
|
}
|
|
|
|
module.exports = function (urlString) {
|
|
urlString = urlString.trim();
|
|
|
|
if (/^data:/i.test(urlString)) {
|
|
return urlString;
|
|
}
|
|
|
|
var protocol = urlString.indexOf("//") !== -1 ? urlString.split("//")[0] + "//" : "";
|
|
var components = urlString.replace(new RegExp(protocol, "i"), "").split("/");
|
|
var host = components[0].toLowerCase().replace(/\.$/, "");
|
|
components[0] = "";
|
|
var path = normalizeUrl(components);
|
|
return protocol + host + path;
|
|
};
|