|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | /**
|
|---|
| 4 | * @param {string[]} pathComponents path components
|
|---|
| 5 | * @returns {string} normalized url
|
|---|
| 6 | */
|
|---|
| 7 | function normalizeUrlInner(pathComponents) {
|
|---|
| 8 | return pathComponents.reduce(function (accumulator, item) {
|
|---|
| 9 | switch (item) {
|
|---|
| 10 | case "..":
|
|---|
| 11 | accumulator.pop();
|
|---|
| 12 | break;
|
|---|
| 13 | case ".":
|
|---|
| 14 | break;
|
|---|
| 15 | default:
|
|---|
| 16 | accumulator.push(item);
|
|---|
| 17 | }
|
|---|
| 18 | return accumulator;
|
|---|
| 19 | }, /** @type {string[]} */[]).join("/");
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | /**
|
|---|
| 23 | * @param {string} urlString url string
|
|---|
| 24 | * @returns {string} normalized url string
|
|---|
| 25 | */
|
|---|
| 26 | module.exports = function normalizeUrl(urlString) {
|
|---|
| 27 | urlString = urlString.trim();
|
|---|
| 28 | if (/^data:/i.test(urlString)) {
|
|---|
| 29 | return urlString;
|
|---|
| 30 | }
|
|---|
| 31 | var protocol =
|
|---|
| 32 | // eslint-disable-next-line unicorn/prefer-includes
|
|---|
| 33 | urlString.indexOf("//") !== -1 ? "".concat(urlString.split("//")[0], "//") : "";
|
|---|
| 34 | var components = urlString.replace(new RegExp(protocol, "i"), "").split("/");
|
|---|
| 35 | var host = components[0].toLowerCase().replace(/\.$/, "");
|
|---|
| 36 | components[0] = "";
|
|---|
| 37 | var path = normalizeUrlInner(components);
|
|---|
| 38 | return protocol + host + path;
|
|---|
| 39 | }; |
|---|
Note:
See
TracBrowser
for help on using the repository browser.