chore: split out helpers

This commit is contained in:
Cory Dransfeldt 2023-07-21 15:51:07 -07:00
parent 341221c78c
commit 528a61ce77
No known key found for this signature in database
3 changed files with 58 additions and 51 deletions

23
src/utils/grammar.js Normal file
View file

@ -0,0 +1,23 @@
const titleCaseExceptions = require('./../_data/json/title-case-exceptions.json')
module.exports = {
/**
* Accepts a string that is then transformed to title case and returned.
*
* @name titleCase
* @param {string} string
* @returns {string}
*/
titleCase: (string) => {
if (!string) return ''
return string
.toLowerCase()
.split(' ')
.map((word, i) => {
return titleCaseExceptions.exceptions.includes(word) && i !== 0
? word
: word.charAt(0).toUpperCase().concat(word.substring(1))
})
.join(' ')
},
}