(path: string)
| 44 | * Extract directory name from a path |
| 45 | */ |
| 46 | export function extractDirName(path: string): string | null { |
| 47 | if (!path || typeof path !== "string") return null; |
| 48 | |
| 49 | const trimmed = path.trim().replace(/\/+$/, ""); |
| 50 | if (trimmed === "" || trimmed === "/") return null; |
| 51 | |
| 52 | const parts = trimmed.split("/"); |
| 53 | const name = parts[parts.length - 1]; |
| 54 | |
| 55 | // Skip generic names |
| 56 | const skipNames = new Set(["home", "users", "user", "root", "tmp", "var"]); |
| 57 | if (skipNames.has(name.toLowerCase())) return null; |
| 58 | |
| 59 | return sanitizeTag(name); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Extract hostname from a URL string, or return the original string on failure. |
no test coverage detected