Created
April 1, 2019 16:03
-
-
Save panphora/809cd487a49ee0f7029ea14a0c8ccfc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function slugify (str) { | |
return str | |
.trim() | |
.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 | |
.toLowerCase(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment