(name: string)
| 13 | * - trim to reasonable length |
| 14 | */ |
| 15 | export function sanitizeTag(name: string): string | null { |
| 16 | if (!name || typeof name !== "string") return null; |
| 17 | |
| 18 | const sanitized = name |
| 19 | .toLowerCase() |
| 20 | .trim() |
| 21 | .replace(/[\s_]+/g, "-") // spaces/underscores -> hyphens |
| 22 | .replace(/[^a-z0-9-]/g, "") // remove special chars |
| 23 | .replace(/-+/g, "-") // collapse multiple hyphens |
| 24 | .replace(/^-|-$/g, "") // trim leading/trailing hyphens |
| 25 | .slice(0, 30); // max 30 chars |
| 26 | |
| 27 | return sanitized.length >= 2 ? sanitized : null; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Extract repo name from a git root path |
no test coverage detected