Slugify a String
React.js
medium
20 mins
Slugs are widely used in blogs, e-commerce, and CMS platforms for clean and SEO-friendly URLs.
Things to do
- Create an input where the user can type text.
- Implement a slugify function that follows these rules:
- Convert all characters to lowercase.
- Remove accents/diacritics (e.g., Café → cafe).
- Replace any sequence of spaces or special characters with a single -.
- Return an empty string if the input is only whitespace.
- Display the resulting slug below the input.
ClassNames
Use this classnames in your code
- Input -> input-box
- Result -> result
Examples
input: "My First Blog!" output: "my-first-blog"
input: "Café del Mar!" output: "cafe-del-mar"
input: " " output: ""
Testing Instructions
Please use the following data-testid attributes in your React component:
- input-box → for the input field
- result → for the slug output
Preview what you need to build
Companies:
startups
tcs
shopify
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
