src/utils/slug.ts
toSlug(name: string): string
Converts human-readable text into a filesystem-safe slug.
Rules (in order):
- trim
- lowercase
- remove non
[a-z0-9\s-] - replace whitespace runs with
- - collapse repeated
- - strip leading/trailing
-
Parameters
name: input string
Returns
- normalized slug
Examples
toSlug("My Cool Project!"); // "my-cool-project"
toSlug(" Hello World "); // "hello-world"