Javascript String toProperCase()
//allows proper-casing for strings String.prototype.toProperCase = function() { return this.toLowerCase().replace(/^(.)|\s(.)/g, function($1) { return $1.toUpperCase(); }); }
// http://stackoverflow.com/a/5574446/98600 String.prototype.toProperCase = function () { return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); };
String.prototype.toProperCase = function () { return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); };
String.prototype.toProperCase = function() { return this.charAt(0).toUpperCase() + this.substr(1); } module.exports = String.prototype;
String.prototype.toProperCase = function () { return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); };
function titleCase(str) { var newWord;/*w ww.j av a 2s .c om*/ var newList=[]; var newString; wordList = str.toLowerCase().split(" "); for (var word in wordList) { var firstLetter = wordList[word].charAt(0).toUpperCase(); var slicedWord = wordList[word].slice(1); newWord = firstLetter.concat(slicedWord); newList.push(newWord); } return newList.join(" "); } console.log(titleCase("I'm a little tea pot")); // functional programming solution String.prototype.toProperCase = function () { return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); };
// Util function to convert string to Title Case String.prototype.toProperCase = function () { return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); };