(path: unknown)
| 24 | } |
| 25 | |
| 26 | export function isValidPath(path: unknown): boolean { |
| 27 | const isString = typeof path === 'string'; |
| 28 | |
| 29 | if (!isString || path.trim() === '') { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | // Calling new URL() will throw if the path string is malformed |
| 34 | try { |
| 35 | const url = new URL(path); |
| 36 | return true; |
| 37 | } catch { |
| 38 | return false; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | export function normalizePath(path: string): string { |
| 43 | return path.endsWith('/') ? path.slice(0, -1) : path; |
no outgoing calls
no test coverage detected