From 56f1f8384dba7da6f1373768129bd37c24147520 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Mon, 10 Feb 2020 00:09:29 +0200 Subject: use parseUrl in Backend --- ext/mixed/js/core.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ext/mixed') diff --git a/ext/mixed/js/core.js b/ext/mixed/js/core.js index 0142d594..ca9e98e5 100644 --- a/ext/mixed/js/core.js +++ b/ext/mixed/js/core.js @@ -128,6 +128,14 @@ function stringReverse(string) { return string.split('').reverse().join('').replace(/([\uDC00-\uDFFF])([\uD800-\uDBFF])/g, '$2$1'); } +function parseUrl(url) { + const parsedUrl = new URL(url); + const baseUrl = `${parsedUrl.origin}${parsedUrl.pathname}`; + const queryParams = Array.from(parsedUrl.searchParams.entries()) + .reduce((a, [k, v]) => Object.assign({}, a, {[k]: v}), {}); + return {baseUrl, queryParams}; +} + /* * Async utilities -- cgit v1.2.3