Skip to content

Instantly share code, notes, and snippets.

@Flolagale
Created August 20, 2013 16:55
Show Gist options
  • Save Flolagale/6284119 to your computer and use it in GitHub Desktop.
Save Flolagale/6284119 to your computer and use it in GitHub Desktop.
Slugify
var slugify function(str) {
var from = "ąàáäâãåæćęèéëêìíïîłńòóöôõøśùúüûñçżź",
to = "aaaaaaaaceeeeeiiiilnoooooosuuuunczz",
regex = new RegExp('[' + from.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1') + ']', 'g');
if (str == null) return '';
str = String(str).toLowerCase().replace(regex, function(c) {
return to.charAt(from.indexOf(c)) || '-';
});
return str.replace(/[^\w\s-]/g, '').replace(/([A-Z])/g, '-$1').replace(/[-_\s]+/g, '-').toLowerCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment