ca7c1f0a3cf214e2ec60e2414e1a0c833b82cd3febddf4f320993b2564f351f7.json 1.4 KB

1
  1. {"ast":null,"code":"import getCurrentScriptSource from \"./getCurrentScriptSource.js\";\n\n/**\n * @param {string} resourceQuery\n * @returns {{ [key: string]: string | boolean }}\n */\nfunction parseURL(resourceQuery) {\n /** @type {{ [key: string]: string }} */\n var options = {};\n if (typeof resourceQuery === \"string\" && resourceQuery !== \"\") {\n var searchParams = resourceQuery.slice(1).split(\"&\");\n for (var i = 0; i < searchParams.length; i++) {\n var pair = searchParams[i].split(\"=\");\n options[pair[0]] = decodeURIComponent(pair[1]);\n }\n } else {\n // Else, get the url from the <script> this file was called with.\n var scriptSource = getCurrentScriptSource();\n var scriptSourceURL;\n try {\n // The placeholder `baseURL` with `window.location.href`,\n // is to allow parsing of path-relative or protocol-relative URLs,\n // and will have no effect if `scriptSource` is a fully valid URL.\n scriptSourceURL = new URL(scriptSource, self.location.href);\n } catch (error) {\n // URL parsing failed, do nothing.\n // We will still proceed to see if we can recover using `resourceQuery`\n }\n if (scriptSourceURL) {\n options = scriptSourceURL;\n options.fromCurrentScript = true;\n }\n }\n return options;\n}\nexport default parseURL;","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}