chore: split out helpers
This commit is contained in:
parent
341221c78c
commit
528a61ce77
3 changed files with 58 additions and 51 deletions
23
src/utils/grammar.js
Normal file
23
src/utils/grammar.js
Normal 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(' ')
|
||||
},
|
||||
}
|
Reference in a new issue