Last active
March 8, 2022 11:25
-
-
Save svenakela/36cb5b6378007f77a8d739d9cc60d084 to your computer and use it in GitHub Desktop.
This file contains 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
// 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that even in MLA there are rules where words with n >= 3 should not be capitalized.
To completely follow MLA, a word index must be implemented
More details here: https://www.scribbr.com/mla/titles/