Created
August 20, 2013 16:55
-
-
Save Flolagale/6284119 to your computer and use it in GitHub Desktop.
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
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