Skip to content
FLAVIO COPES
flaviocopes.com
2026

Slugify a string in JavaScript

By Flavio Copes

Learn how to slugify a string in JavaScript using the slugify library, and how to strip dots and other punctuation with its remove regex option.

~~~

Install the slugify library

npm i slugify

Then import it

import slugify from 'slugify'

and you can do

const slug = slugify('Testing this')
console.log(slug) //testing-this

Note that if the string contains dots or other punctuation, it will not strip that.

To remove that, you can use a regex like this:

slugify('Testing. this!', { remove: /[*+~.,()'"!:@]/g })
Tagged: JavaScript ยท All topics
~~~

Related posts about js: