Slug Generator
Turn an arbitrary string into a URL-friendly slug.
Rules
- Convert the string to lowercase.
- Replace any run of whitespace with a single
-. - Strip all characters that are not ASCII letters (
a-z), digits (0-9), or-. - Collapse any run of consecutive
-into a single-. - Strip leading and trailing
-. - If the result is longer than 60 characters, truncate it. If truncation lands on a
-, also strip that trailing-. - If the result is empty, return the literal string
untitled.
Examples
"Hello, World!"→"hello-world"" multiple spaces "→"multiple-spaces""!!!"→"untitled"