Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-24 10:46:10 +01:00
forgejo/web_src/js/utils/url.js

16 lines
334 B
JavaScript
Raw Normal View History

export function pathEscapeSegments(s) {
return s.split('/').map(encodeURIComponent).join('/');
}
function stripSlash(url) {
return url.endsWith('/') ? url.slice(0, -1) : url;
}
export function isUrl(url) {
try {
return stripSlash((new URL(url).href)).trim() === stripSlash(url).trim();
} catch {
return false;
}
}