Skip to content

Instantly share code, notes, and snippets.

@davetayls
Created February 7, 2013 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davetayls/4732246 to your computer and use it in GitHub Desktop.
Save davetayls/4732246 to your computer and use it in GitHub Desktop.
String Extensions
/**
* Converts a string to Title case
* eg: hello how are you -> Hello How Are You
* @return {String}
*/
String.prototype.toTitleCase = function(){
return this.replace(/\w\S*/g, function(txt){
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment