From 43c6165f1805e193464f9199ae02004107c98b12 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sun, 2 Jan 2022 14:14:31 +0100 Subject: [PATCH] fixed changeCase for strings with trailing whitespace --- deemix/utils/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/deemix/utils/index.js b/deemix/utils/index.js index 296c2e0..b9d5ae4 100644 --- a/deemix/utils/index.js +++ b/deemix/utils/index.js @@ -24,12 +24,14 @@ function changeCase(txt, type){ case 'lower': return txt.toLowerCase() case 'upper': return txt.toUpperCase() case 'start': - txt = txt.split(" ") + txt = txt.trim().split(" ") 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() - } else { + } else if (txt[i].length > 1) { txt[i] = txt[i][0].toUpperCase() + txt[i].substr(1).toLowerCase() + } else { + txt[i] = txt[i][0].toUpperCase() } } return txt.join(" ")