Vanilla JavaScript Slugify + Accent removal - Just another JavaScript Slugifier with an extra line for Accent Removal
function slugify(text) { | |
return text.toString().toLowerCase().trim() | |
.normalize('NFD') // separate accent from letter | |
.replace(/[\u0300-\u036f]/g, '') // remove all separated accents | |
.replace(/\s+/g, '-') // replace spaces with - | |
.replace(/&/g, '-and-') // replace & with 'and' | |
.replace(/[^\w\-]+/g, '') // remove all non-word 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
This comment has been minimized.
Wont work in IE...because (as expected) it doesn't support normalize(), otherwise nice to know =)