diff options
Diffstat (limited to 'app/assets/javascripts/lib/utils/url_utility.js')
-rw-r--r-- | app/assets/javascripts/lib/utils/url_utility.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js index 12462a2575e..335cd6a16e5 100644 --- a/app/assets/javascripts/lib/utils/url_utility.js +++ b/app/assets/javascripts/lib/utils/url_utility.js @@ -18,6 +18,20 @@ function resetRegExp(regex) { return regex; } +/** + * Returns the absolute pathname for a relative or absolute URL string. + * + * A few examples of inputs and outputs: + * 1) 'http://a.com/b/c/d' => '/b/c/d' + * 2) '/b/c/d' => '/b/c/d' + * 3) 'b/c/d' => '/b/c/d' or '[path]/b/c/d' depending of the current path of the + * document.location + */ +export const parseUrlPathname = (url) => { + const { pathname } = new URL(url, document.location.href); + return pathname; +}; + // Returns a decoded url parameter value // - Treats '+' as '%20' function decodeUrlParameter(val) { |