code: function string_to_slug(str, maxLength) {
    // Separate camel-cased words with a space for later processing. 
    str = str.replace(/[A-Z]/g, function(s){ 
      return " " + s; 
    }); 
      
    str = str.toLowerCase();
  
    // remove accents, swap ñ for n, etc
    var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;",
        to   = "aaaaeeeeiiiioooouuuunc------";
    for (var i=0, l=from.length ; i<l ; i++) {
      str = str.replace(from[i], to[i]);
    }
  
    str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
      .replace(/\s+/g, '-') // collapse whitespace and replace by -
      .replace(/-+/g, '-'); // collapse dashes
      
    // Trim leading and trailing whitespace and dashes. 
    str = str.replace(/^[\s|-]+|[\s|-]+$/g, '');
  
    if(maxLength && str.length > maxLength)
      str = str.substr(0, maxLength);
  
    return str;
  }
docs: Utility Functions
   
  Converts a string to a slug representation.
  Sadly, don't remember where I grabbed this from to acknowledge :(
  Modified it to accept a maximum length.
  @param  {String} str       The string to convert to slug
  @param  {Number} maxLength The maximum length of the slug
  @return {String}           Slug generated by the input stream