Created
July 11, 2012 14:31
-
-
Save chrismanderson/3090735 to your computer and use it in GitHub Desktop.
Titleize.coffee
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String::titleize = -> | |
titleized = this.split(" ") | |
UNCAPITALIZED = ['a', 'an'] | |
titleized = ( | |
for word, index in titleized | |
if word in UNCAPITALIZED && index != 0 | |
word | |
else | |
word[0].toUpperCase() + word.slice(1) if word | |
) | |
titleized.join(" ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment