```typescript function slugifyHandle(input: string, maxLen: number = 40): string { const slug = input.toLowerCase() .replace(/[^a-z0-9]+/g, '-') // Replace non-alphanumeric runs with a hyphen .replace(/^-+|-+$/g, ''); // Trim hyphens from start/end return slug.length > maxLen ? slug.substring(0, maxLen).replace(/-+$/g, '') : slug; } ``` This TypeScript function converts a string into a slug by lowercasing it, replacing non-alphanumeric runs with hyphens, trimming exterior hyphens, and optionally truncating it to a given maximum length, defaulting to 40 characters.