Created
June 25, 2012 15:19
-
-
Save leocavalcante/2989219 to your computer and use it in GitHub Desktop.
slug strings
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 ( global, undefined ) { | |
function slugify ( str ) { | |
return str | |
.toLowerCase() | |
.replace( /á|à|â|ã/g, 'a' ) | |
.replace( /é|è|ê/g, 'e' ) | |
.replace( /í|ì|î/g, 'i' ) | |
.replace( /ó|ò|ô|õ/g, 'o' ) | |
.replace( /ú|ù|û/g, 'u' ) | |
.replace( /ç/g , 'c' ) | |
.replace( /\s+/g, '_' ) | |
.replace( /\W/g, '' ) | |
.replace( /_+/g, '-' ) | |
.replace( /^-|-$/g, '' ); | |
} | |
global.slugify = global.slugify || slugify; | |
} ( this )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment