Skip to content

Instantly share code, notes, and snippets.

@svenakela
Last active March 8, 2022 11:25
Show Gist options
  • Save svenakela/36cb5b6378007f77a8d739d9cc60d084 to your computer and use it in GitHub Desktop.
Save svenakela/36cb5b6378007f77a8d739d9cc60d084 to your computer and use it in GitHub Desktop.
// Cap everything
"My kid is a stupid jump rat"
.toLowerCase()
.split(' ')
.map(word => word.charAt(0).toUpperCase() + word.substring(1))
.join(' ');
// MLA Style - All words <= 3 chars are lowercase, except first and last word.
// MLA style word matching that always should be lower case. There are combinations as well, like "as long as" and "even if", that should be non cap to be perfect
const nonCaps = ["from", "into", "like", "near", "once", "onto", "over", "past", "than", "that", "till", "upon", "with", "when", "between", "against"];
"My children are snowpark rats against all odds"
.toLowerCase()
.split(' ')
.map((word, index, array) => {
return (index == 0 || index == array.length-1 || (word.length > 3 && !nonCaps.includes(word))) ?
word.charAt(0).toUpperCase() + word.substring(1) :
word;
})
.join(' ');
// Chicago and AP standards require verb checking, i.e. a list of verbs
// or API calls to text services. Both works, requires longer code though.
@kambisven
Copy link

Note that even in MLA there are rules where words with n >= 3 should not be capitalized.

  • articles; My Kid is the Jump Rat
  • prepositions; Jump with the Bike
  • conjunctions; Bikes and Jumps

To completely follow MLA, a word index must be implemented
More details here: https://www.scribbr.com/mla/titles/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment