0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-12-13 10:53:18 +01:00
gitea/web_src/js/utils/url.ts

16 lines
334 B
TypeScript
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;
}
}