Published on

Create a URL-Friendly Slug in JavaScript

Authors

Let's say you have a string (like a blog post title) and want to convert it to URL-friendly slug

For such cases, we can just use @sindresorhus/slugify npm package.

Here's how to do it:

Dependency

$ npm install @sindresorhus/slugify

Snippet

import slugify from '@sindresorhus/slugify';

slugify('Create a URL-Friendly Slug in Javascript');

//=> create-a-url-friendly-slug-in-javascript

Happy slugifying strings!