slugify
Convert a string to a URL-friendly slug.
Installation
npx react-usekit@latest init
Select: utils → TypeScript or JavaScript → path -> slugify
Usage
import { slugify } from "./utils/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 |