slugify
Converts a string to a URL-friendly slug by lowercasing, stripping accents, and replacing non-alphanumeric characters with hyphens.
Import
Section titled “Import”import { slugify } from "1o1-utils";import { slugify } from "1o1-utils/slugify";Signature
Section titled “Signature”function slugify({ str }: SlugifyParams): stringParameters
Section titled “Parameters”| Name | Type | Required | Description |
|---|---|---|---|
| str | string | Yes | The string to slugify |
Returns
Section titled “Returns”string — A lowercase, hyphen-separated slug.
Examples
Section titled “Examples”slugify({ str: "Hello World!" });// => "hello-world"
slugify({ str: "Café au lait" });// => "cafe-au-lait"
slugify({ str: " --Multiple Spaces-- " });// => "multiple-spaces"Edge Cases
Section titled “Edge Cases”- Throws if
stris not a string. - Handles Unicode normalization (NFD) to strip accents.
- Removes leading/trailing hyphens.
- Collapses multiple non-alphanumeric characters into a single hyphen.
Also known as
Section titled “Also known as”url slug, url friendly, permalink, dash case url
Prompt suggestion
Section titled “Prompt suggestion”I'm using 1o1-utils (npm: https://www.npmjs.com/package/1o1-utils, GitHub: https://github.com/pedrotroccoli/1o1-utils, LLM context: https://pedrotroccoli.github.io/1o1-utils/llms.txt). Show me how to use slugify to generate URL slugs from article titles