Created
January 30, 2013 14:46
-
-
Save jmealo/4673750 to your computer and use it in GitHub Desktop.
This function returns the capitalized abbreviation of the passed string according to APA rules for title case (http://blog.apastyle.org/apastyle/2012/03/title-case-and-sentence-case-capitalization-in-apa-style.html). It omits the following minor words: and, or, nor, but, a, an, the, as, at, by, for, in, of, on, per and to.
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
function strToAbbr(str) { | |
str = str.toUpperCase(); | |
str = str.replace(/\b(AND|OR|NOR|BUT|A|AN|THE|AS|AT|BY|FOR|IN|OF|ON|PER|TO)\b/g, ''); | |
var words = str.split(/\s+/), abbr = ''; | |
for(var x = 0; x < words.length; x++) abbr += words[x].substr(0,1); | |
return abbr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment