slugify
Convert a string to a URL-friendly slug.
Installation
pnpm dlx shadcn@latest add https://reactusekit.dev/r/slugify.json
Usage
import { slugify } from "@/lib/slugify";
function App() {
const title = "Hello World! This is a Test";
const slug = slugify(title);
return (
<div>
<p>Original: {title}</p>
<p>Slugified: {slug}</p>
</div>
);
}
API
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
text | string | - | The text to slugify |
options | object | {} | Configuration options |
Returns
Type | Description |
---|---|
string | A URL-friendly slug |