const MIN_LENGTH = 4 const MAX_LENGTH = 63 export function serializeID(input: string): string { const normalized = input .trim() .normalize("NFD") .replace(/\p{M}/gu, "") .toLowerCase() .replace(/[^a-z0-9]+/g, "-") .replace(/^-+|-+$/g, "") const truncated = normalized.length > MAX_LENGTH ? normalized.slice(0, MAX_LENGTH).replace(/-+$/, "") : normalized if (truncated.length < MIN_LENGTH) { throw new Error( `Cannot serialize "${input}" to a repository ID: result must be between ${MIN_LENGTH} and ${MAX_LENGTH} characters.`, ) } return truncated }