Skip to content

Instantly share code, notes, and snippets.

@ricealexander
Created December 24, 2020 21:55
Show Gist options
  • Save ricealexander/471761607828e0b7d5febfa717465e9a to your computer and use it in GitHub Desktop.
Save ricealexander/471761607828e0b7d5febfa717465e9a to your computer and use it in GitHub Desktop.
When you receive a list of sponsors in ALL CAPS
const sponsors = [
'BARNES JEWISH HOSPITAL',
'BARNES JEWISH WEST COUNTY HOSPITAL',
'BELLEVILLE NEWS DEMOCRAT',
'BESPOKE APPAREL',
'BETTER BUSINESS BUREAU',
'BIG BOW EVENTS',
'BIG O LIQUEUR',
]
const capitalize = string => {
if (string.length < 2) return string.toUpperCase()
return string[0].toUpperCase() + string.slice(1).toLowerCase()
}
const cleanSponsors = sponsors.map(name => {
const words = name.split(' ')
return words.map(word => {
if (word === word.toUpperCase()) {
return capitalize(word)
}
return word
}).join(' ')
})
copy(cleanSponsors)
// remember to manually review the results.
// some words, such as "of" and "the" may need to be lowercased
// others, such as "LLC" may need to be caps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment