slugify
Converts a string into a URL-friendly slug by removing accents, special characters, and replacing spaces with hyphens.
Syntax
typescript
slugify(str: string): stringParameters
| Parameter | Type | Description |
|---|---|---|
str | string | The input string. |
Returns
| Type | Description |
|---|---|
string | The slug generated from the input string. |
Example
typescript
slugify("Olá, mundo!"); // "ola-mundo"
slugify("Café com Leite"); // "cafe-com-leite"
slugify(" Exemplo de Slug "); // "exemplo-de-slug"Notes
- Throws
TypeErrorif the argument is not a string. - Removes punctuation, accents, and converts to lowercase.
- Replaces consecutive spaces with a single hyphen.
