From 930e95653c940241415373f7ad92a040740317e6 Mon Sep 17 00:00:00 2001 From: Jera Date: Tue, 31 Aug 2021 09:36:05 -0400 Subject: [PATCH 1/4] Modify Title Case This should now correctly capitalize after an opening bracket --- deemix/utils/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deemix/utils/index.js b/deemix/utils/index.js index d7ed34f..5d7c8b7 100644 --- a/deemix/utils/index.js +++ b/deemix/utils/index.js @@ -25,7 +25,9 @@ function changeCase(txt, type){ case 'upper': return txt.toUpperCase() case 'start': txt = txt.split(" ") - for (let i = 0; i < txt.length; i++) txt[i] = txt[i][0].toUpperCase() + txt[i].substr(1).toLowerCase() + for (let i = 0, q = 0; i < txt.length; i++) + if (txt[i].substr(0, 1) === "(" || txt[i].substr(0, 1) === "[" || txt[i].substr(0, 1) === "{") q++; + txt[i] = txt[i][q].toUpperCase() + txt[i].substr(q + 1).toLowerCase() return txt.join(" ") case 'sentence': return txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase() default: return txt -- 2.25.1 From 0019c9656babeaaf75f7bce50ed1dc187b26918a Mon Sep 17 00:00:00 2001 From: Jera Date: Tue, 31 Aug 2021 09:48:12 -0400 Subject: [PATCH 2/4] Correctly Capatilize After Opeining Bracket fixed code indent --- deemix/utils/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deemix/utils/index.js b/deemix/utils/index.js index 5d7c8b7..9e0236f 100644 --- a/deemix/utils/index.js +++ b/deemix/utils/index.js @@ -27,7 +27,7 @@ function changeCase(txt, type){ txt = txt.split(" ") for (let i = 0, q = 0; i < txt.length; i++) if (txt[i].substr(0, 1) === "(" || txt[i].substr(0, 1) === "[" || txt[i].substr(0, 1) === "{") q++; - txt[i] = txt[i][q].toUpperCase() + txt[i].substr(q + 1).toLowerCase() + txt[i] = txt[i][q].toUpperCase() + txt[i].substr(q + 1).toLowerCase() return txt.join(" ") case 'sentence': return txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase() default: return txt -- 2.25.1 From 8125a31fce4b280b864a1e9cf18c3af47d9475e8 Mon Sep 17 00:00:00 2001 From: Jera Date: Tue, 31 Aug 2021 23:45:16 -0400 Subject: [PATCH 3/4] Correctly Capatilize After Opening Bracket Working and tested --- deemix/utils/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/deemix/utils/index.js b/deemix/utils/index.js index 9e0236f..f765e82 100644 --- a/deemix/utils/index.js +++ b/deemix/utils/index.js @@ -25,9 +25,13 @@ function changeCase(txt, type){ case 'upper': return txt.toUpperCase() case 'start': txt = txt.split(" ") - for (let i = 0, q = 0; i < txt.length; i++) - if (txt[i].substr(0, 1) === "(" || txt[i].substr(0, 1) === "[" || txt[i].substr(0, 1) === "{") q++; - txt[i] = txt[i][q].toUpperCase() + txt[i].substr(q + 1).toLowerCase() + for (let i = 0; i < txt.length; i++) { + if (txt[i].startsWith("(") || txt[i].startsWith("[") || txt[i].startsWith("{")) { + txt[i] = txt[i][0] + txt[i][1].toUpperCase() + txt[i].substr(2).toLowerCase() + } else { + txt[i] = txt[i][0].toUpperCase() + txt[i].substr(1).toLowerCase() + } + } return txt.join(" ") case 'sentence': return txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase() default: return txt -- 2.25.1 From c7dd1a0c7090999df3ea9c26022ce47b153f7183 Mon Sep 17 00:00:00 2001 From: Jera Date: Wed, 1 Sep 2021 01:59:10 -0400 Subject: [PATCH 4/4] Code Cleanup cleaned up the if condition --- deemix/utils/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deemix/utils/index.js b/deemix/utils/index.js index f765e82..388536f 100644 --- a/deemix/utils/index.js +++ b/deemix/utils/index.js @@ -26,7 +26,7 @@ function changeCase(txt, type){ case 'start': txt = txt.split(" ") for (let i = 0; i < txt.length; i++) { - if (txt[i].startsWith("(") || txt[i].startsWith("[") || txt[i].startsWith("{")) { + if (bracket = ['(', '{', '['].some(bracket => txt[i].startsWith(bracket))) { txt[i] = txt[i][0] + txt[i][1].toUpperCase() + txt[i].substr(2).toLowerCase() } else { txt[i] = txt[i][0].toUpperCase() + txt[i].substr(1).toLowerCase() -- 2.25.1