-
-
Save aprilandjan/e274ff9441e97d47c04cb775d0be076f to your computer and use it in GitHub Desktop.
Javascript Slugify
This file contains 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
function slugify(text) | |
{ | |
return text.toString().trim().toLowerCase() | |
.replace(/\s+/g, '-') // Replace spaces with - | |
// .replace(/[^\w\-]+/g, '') // Remove all non-word chars | |
.replace(/[^a-zA-Z0-9_\u3400-\u9FBF\s-]/g,'') // remove all non-word & non-chinese chars | |
.replace(/\-\-+/g, '-') // Replace multiple - with single - | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment