Files
MickaelK 003c4a9737 fix (filename): weird filenames
I've tried a lot of things to make the URL look nice but somehow there's
always a bug to handle all possible scenarios. Eg:

/test/test#test%20with a: space.txt

maybe one day, we can make the urls looks nicer but this would need a
significant revamp, until that happen, that will do.

tip: don't understimate the work it takes to do it nicely, I've tried to
do this 2 times quickly and everytime there's a edge case that make
things not working and breaking other odd stuff
2024-12-10 21:51:17 +11:00

22 lines
674 B
JavaScript

export function basename(str, sep = "/") {
return str.substr(str.lastIndexOf(sep) + 1);
}
export function extname(str) {
return str.substr(str.lastIndexOf(".") + 1).toLowerCase();
}
export function join(baseURL, segment) {
const url = new URL(segment, baseURL);
return decodeURIComponent(url.pathname + url.hash);
}
export function forwardURLParams(url, allowed = []) {
const _url = new URL(window.location.origin + "/" + url);
for (const [key, value] of new URLSearchParams(location.search)) {
if (allowed.indexOf(key) < 0) continue;
_url.searchParams.set(key, value);
}
return _url.pathname.substring(1) + _url.search;
}