1
1
mirror of https://github.com/go-gitea/gitea synced 2024-12-28 19:44:27 +00:00
gitea/web_src/js/utils/url.ts

16 lines
383 B
TypeScript
Raw Normal View History

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