Skip to content

Instantly share code, notes, and snippets.

@aprilandjan
Forked from mathewbyrne/slugify.js
Last active April 14, 2017 06:54
Show Gist options
  • Save aprilandjan/e274ff9441e97d47c04cb775d0be076f to your computer and use it in GitHub Desktop.
Save aprilandjan/e274ff9441e97d47c04cb775d0be076f to your computer and use it in GitHub Desktop.
Javascript Slugify
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