source: frontend/node_modules/webpack-dev-server/client/utils/parseURL.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import getCurrentScriptSource from "./getCurrentScriptSource.js";
2
3/**
4 * @param {string} resourceQuery
5 * @returns {{ [key: string]: string | boolean }}
6 */
7function parseURL(resourceQuery) {
8 /** @type {{ [key: string]: string }} */
9 var options = {};
10 if (typeof resourceQuery === "string" && resourceQuery !== "") {
11 var searchParams = resourceQuery.slice(1).split("&");
12 for (var i = 0; i < searchParams.length; i++) {
13 var pair = searchParams[i].split("=");
14 options[pair[0]] = decodeURIComponent(pair[1]);
15 }
16 } else {
17 // Else, get the url from the <script> this file was called with.
18 var scriptSource = getCurrentScriptSource();
19 var scriptSourceURL;
20 try {
21 // The placeholder `baseURL` with `window.location.href`,
22 // is to allow parsing of path-relative or protocol-relative URLs,
23 // and will have no effect if `scriptSource` is a fully valid URL.
24 scriptSourceURL = new URL(scriptSource, self.location.href);
25 } catch (error) {
26 // URL parsing failed, do nothing.
27 // We will still proceed to see if we can recover using `resourceQuery`
28 }
29 if (scriptSourceURL) {
30 options = scriptSourceURL;
31 options.fromCurrentScript = true;
32 }
33 }
34 return options;
35}
36export default parseURL;
Note: See TracBrowser for help on using the repository browser.