I am attempting to convert my string into title case which I'm able to do successfully. using this method:
title.toLowerCase().split(' ').map(function (s) {
return s.charAt(0).toUpperCase() + s.substring(1);
}).join(' ');
But this current logic applies well for one specific title schema. I am attempting to customize it to work better in different scenarios but when doing so none of them have an effect on the outcome of the title.
For starters as seen in the code snippet below, the word (case) is lower case and that should be capitalized too. It seems to not capitalize the first letter after parentheses.
I also attempt to have an outcome where Tv = TV
replace the word and = &
. I am approaching this using the .replace
method
How can I adjust the code snippet below in order to add these conditions?
let title = "Adjusting the title (case and test) on tv"
titleCase = title.toLowerCase().split(' ').map(function (s) {
return s.charAt(0).toUpperCase() + s.substring(1);
}).join(' ');
titleCase.replace(/ and /ig, ' & ');
titleCase.replace("Tv", "TV")
console.log(titleCase)
My expected outcome is : Adjusting The Title (Case & Test) On TV