Skip to content

Instantly share code, notes, and snippets.

@panphora panphora/slugify.js
Created Apr 1, 2019

What would you like to do?
export default function slugify (str) {
return str
.replace(/[^0-9A-Za-z\-\s]/g, " ") // keep alphanumeric, dashes, and spaces
.replace(/ +/g, " ") // replace double spaces with single space
.replace(/ /g, "-") // replace single spaces with single dash
.replace(/\-\-/g, "-") // replace double dashes with single dash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.