Skip to content

Instantly share code, notes, and snippets.

@leocavalcante
Created June 25, 2012 15:19
Show Gist options
  • Save leocavalcante/2989219 to your computer and use it in GitHub Desktop.
Save leocavalcante/2989219 to your computer and use it in GitHub Desktop.
slug strings
(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