Capitalize a phrase (helper)

String.prototype.capitalize = function() { return this.replace(/([\w'-]+)\s?/g, function(word) { return word[0].toUpperCase() + word.slice(1); }); // End of replacing with callback }; // End of Capitalize method // USE CASE //----------- console.log("hell no, i'm the awesome capitan-o, ok?".capitalize()); // Outputs -> "Hell No, I'm The Awesome Capitan-o, Ok?"
Helper function to capitalize a string ─ This snippet is a piece of a JavaScript library I'm working on, you can see it here: https://github.com/luishendrix92/WindowbirdJS

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.