fixed changeCase for strings with trailing whitespace

This commit is contained in:
RemixDev 2022-01-02 14:14:31 +01:00
parent 2e30a59a8f
commit 43c6165f18

View file

@ -24,12 +24,14 @@ function changeCase(txt, type){
case 'lower': return txt.toLowerCase() case 'lower': return txt.toLowerCase()
case 'upper': return txt.toUpperCase() case 'upper': return txt.toUpperCase()
case 'start': case 'start':
txt = txt.split(" ") txt = txt.trim().split(" ")
for (let i = 0; i < txt.length; i++) { for (let i = 0; i < txt.length; i++) {
if (['(', '{', '['].some(bracket => ( txt[i].length > 1 && txt[i].startsWith(bracket) ) )) { if (['(', '{', '[', "'", '"'].some(bracket => ( txt[i].length > 1 && txt[i].startsWith(bracket) ) )) {
txt[i] = txt[i][0] + txt[i][1].toUpperCase() + txt[i].substr(2).toLowerCase() txt[i] = txt[i][0] + txt[i][1].toUpperCase() + txt[i].substr(2).toLowerCase()
} else { } else if (txt[i].length > 1) {
txt[i] = txt[i][0].toUpperCase() + txt[i].substr(1).toLowerCase() txt[i] = txt[i][0].toUpperCase() + txt[i].substr(1).toLowerCase()
} else {
txt[i] = txt[i][0].toUpperCase()
} }
} }
return txt.join(" ") return txt.join(" ")