Skip to content

slugify

Converts a string to a URL-friendly slug by lowercasing, stripping accents, and replacing non-alphanumeric characters with hyphens.

import { slugify } from "1o1-utils";
import { slugify } from "1o1-utils/slugify";
function slugify({ str }: SlugifyParams): string
NameTypeRequiredDescription
strstringYesThe string to slugify

string — A lowercase, hyphen-separated slug.

slugify({ str: "Hello World!" });
// => "hello-world"
slugify({ str: "Café au lait" });
// => "cafe-au-lait"
slugify({ str: " --Multiple Spaces-- " });
// => "multiple-spaces"
  • Throws if str is not a string.
  • Handles Unicode normalization (NFD) to strip accents.
  • Removes leading/trailing hyphens.
  • Collapses multiple non-alphanumeric characters into a single hyphen.

url slug, url friendly, permalink, dash case url

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