From bb72532d64bd3eab99079a6735f23b7c10e28a94 Mon Sep 17 00:00:00 2001
From: Mov <154533182+man-o-valor@users.noreply.github.com>
Date: Sat, 30 Nov 2024 12:47:54 -0500
Subject: [PATCH 01/13] Add sentence reporters to Text
Added Sentence Case, camelCase, Randomcase, Surround, Enter, Tab, and Reverse
Also, my first commit/pr in another repo :) excuse me if my code is a little less clean than cst's
---
extensions/text.js | 124 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 123 insertions(+), 1 deletion(-)
diff --git a/extensions/text.js b/extensions/text.js
index e03c7705a9..eac7290e45 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -1,7 +1,7 @@
// Name: Text
// ID: strings
// Description: Manipulate characters and text.
-// Original: CST1229
+// Original: CST1229 and Man-o-Valor
// License: MIT AND MPL-2.0
(function (Scratch) {
@@ -13,6 +13,9 @@
MIXEDCASE: "mixedcase",
TITLECASE: "titlecase",
EXACTTITLECASE: "exacttitlecase",
+ RANDOMCASE: "randomcase",
+ SENTENCECASE: "sentencecase",
+ CAMELCASE: "camelcase"
};
let splitCache;
@@ -37,6 +40,13 @@
}),
value: CaseParam.UPPERCASE,
},
+ {
+ text: Scratch.translate({
+ default: "Sentence case",
+ description: "Starts words after ., !, and ? with captialized letters",
+ }),
+ value: CaseParam.SENTENCECASE,
+ },
{
text: Scratch.translate({
default: "Title Case",
@@ -61,6 +71,20 @@
}),
value: CaseParam.MIXEDCASE,
},
+ {
+ text: Scratch.translate({
+ default: "RAndoMCaSe",
+ description: "If your language has randomcase, style it accordingly",
+ }),
+ value: CaseParam.RANDOMCASE,
+ },
+ {
+ text: Scratch.translate({
+ default: "camelCase",
+ description: "Removes all spaces and capitalizes all words after the first",
+ }),
+ value: CaseParam.CAMELCASE,
+ },
];
}
@@ -186,9 +210,49 @@
},
},
},
+ {
+ opcode: 'surround',
+ blockType: Scratch.BlockType.REPORTER,
+ text: Scratch.translate("surround [TEXT] with [QUOTE]"),
+ arguments: {
+ TEXT: {
+ type: Scratch.ArgumentType.STRING,
+ defaultValue: "apple"
+ },
+ QUOTE: {
+ type: Scratch.ArgumentType.STRING,
+ menu: "QUOTES"
+ }
+ },
+ },
+
+ {
+ opcode: 'reverse',
+ blockType: Scratch.BlockType.REPORTER,
+ text: Scratch.translate("reverse [TEXT]"),
+ arguments: {
+ TEXT: {
+ type: Scratch.ArgumentType.STRING,
+ defaultValue: "apple"
+ }
+ },
+ },
"---",
+ {
+ opcode: 'enter',
+ blockType: Scratch.BlockType.REPORTER,
+ text: Scratch.translate("enter"),
+ },
+ {
+ opcode: 'tab',
+ blockType: Scratch.BlockType.REPORTER,
+ text: Scratch.translate("tab"),
+ },
+
+ "---",
+
{
opcode: "unicodeof",
blockType: Scratch.BlockType.REPORTER,
@@ -378,6 +442,10 @@
acceptReporters: true,
items: this._initCaseMenu(),
},
+ quotes: {
+ acceptReporters: true,
+ items: ["\"", "'", "`", "-", "*", "()", "{}", "[]", "<>", "^$"],
+ },
},
};
}
@@ -609,10 +677,64 @@
return word[0].toUpperCase() + word.substring(1).toLowerCase();
})
.join("");
+ case CaseParam.SENTENCECASE:
+ let sum = "";
+ let capflag = false
+ for (let i = 0; i < string.length; i++) {
+ if (/^\s*$/.test(string[i-1] ?? " ") && !capflag && string[i].toUpperCase() != string[i].toLowerCase()) {
+ sum +=string[i].toUpperCase();
+ capflag = true
+ } else {
+ if (string[i] == "." || string[i] == "!" || string[i] == "?") {
+ capflag = false
+ }
+ sum += string[i].toLowerCase();
+ }
+ }
+ return sum;
+ case CaseParam.RANDOMCASE:
+ let sum = "";
+ for (let i = 0; i < string.length; i++) {
+ if (Math.random()>0.5) {
+ sum += string[i].toUpperCase()
+ } else {
+ sum += string[i].toLowerCase()
+ }
+ }
+ return sum;
+ case CaseParam.CAMELCASE:
+ let sum = "";
+ for (let i = 0; i < string.length; i++) {
+ if (/^\s*$/.test(string[i-1] ?? "x")) {
+ sum += string[i].toUpperCase();
+ } else {
+ sum += string[i].toLowerCase();
+ }
+ }
+ return sum.replace(/\s/g, "");
default:
return string;
}
}
+
+ surround(args) {
+ if (args.QUOTE.length == 0) {
+ return args.TEXT
+ } else if (args.QUOTE.length == 1) {
+ return args.QUOTE + args.TEXT + args.QUOTE
+ } else if (args.QUOTE.length > 1) {
+ return args.QUOTE[0] + args.TEXT + args.QUOTE[1]
+ }
+ }
+ }
+ enter() {
+ return "\n"
+ }
+ tab() {
+ return " "
+ }
+ reverse(args) {
+ return args.TEXT.split("").reverse().join("")
}
Scratch.extensions.register(new StringsExt());
From 1e60044ec49f322a1bea9ea99edbd6ef857bc52c Mon Sep 17 00:00:00 2001
From: Mov <154533182+man-o-valor@users.noreply.github.com>
Date: Sat, 30 Nov 2024 13:00:04 -0500
Subject: [PATCH 02/13] Small changes to make linter happy
added some semicolons and renamed sum variables to be unique
---
extensions/text.js | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/extensions/text.js b/extensions/text.js
index eac7290e45..3271789a29 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -678,40 +678,40 @@
})
.join("");
case CaseParam.SENTENCECASE:
- let sum = "";
+ let sentencesum = "";
let capflag = false
for (let i = 0; i < string.length; i++) {
if (/^\s*$/.test(string[i-1] ?? " ") && !capflag && string[i].toUpperCase() != string[i].toLowerCase()) {
- sum +=string[i].toUpperCase();
+ sentencesum +=string[i].toUpperCase();
capflag = true
} else {
if (string[i] == "." || string[i] == "!" || string[i] == "?") {
capflag = false
}
- sum += string[i].toLowerCase();
+ sentencesum += string[i].toLowerCase();
}
}
- return sum;
+ return sentencesum;
case CaseParam.RANDOMCASE:
- let sum = "";
+ let randomsum = "";
for (let i = 0; i < string.length; i++) {
if (Math.random()>0.5) {
- sum += string[i].toUpperCase()
+ randomsum += string[i].toUpperCase()
} else {
- sum += string[i].toLowerCase()
+ randomsum += string[i].toLowerCase()
}
}
- return sum;
+ return randomsum;
case CaseParam.CAMELCASE:
- let sum = "";
+ let camelsum = "";
for (let i = 0; i < string.length; i++) {
if (/^\s*$/.test(string[i-1] ?? "x")) {
- sum += string[i].toUpperCase();
+ camelsum += string[i].toUpperCase();
} else {
- sum += string[i].toLowerCase();
+ camelsum += string[i].toLowerCase();
}
}
- return sum.replace(/\s/g, "");
+ return camelsum.replace(/\s/g, "");
default:
return string;
}
@@ -719,22 +719,22 @@
surround(args) {
if (args.QUOTE.length == 0) {
- return args.TEXT
+ return args.TEXT;
} else if (args.QUOTE.length == 1) {
- return args.QUOTE + args.TEXT + args.QUOTE
+ return args.QUOTE + args.TEXT + args.QUOTE;
} else if (args.QUOTE.length > 1) {
- return args.QUOTE[0] + args.TEXT + args.QUOTE[1]
+ return args.QUOTE[0] + args.TEXT + args.QUOTE[1];
}
}
}
enter() {
- return "\n"
+ return "\n";
}
tab() {
- return " "
+ return " ";
}
reverse(args) {
- return args.TEXT.split("").reverse().join("")
+ return args.TEXT.split("").reverse().join("");
}
Scratch.extensions.register(new StringsExt());
From 5f952cc9c35d5c5a61197fb09044ea397d72d513 Mon Sep 17 00:00:00 2001
From: Mov <154533182+man-o-valor@users.noreply.github.com>
Date: Sat, 30 Nov 2024 15:39:26 -0500
Subject: [PATCH 03/13] =?UTF-8?q?whoops,=20the=20last=203=20functions=20we?=
=?UTF-8?q?re=20outside=20the=20class=20=F0=9F=AB=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
tab, enter, and reverse were outside a bracket
---
extensions/text.js | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/extensions/text.js b/extensions/text.js
index 3271789a29..ff0b64441b 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -726,15 +726,15 @@
return args.QUOTE[0] + args.TEXT + args.QUOTE[1];
}
}
- }
- enter() {
- return "\n";
- }
- tab() {
- return " ";
- }
- reverse(args) {
- return args.TEXT.split("").reverse().join("");
+ enter() {
+ return "\n";
+ }
+ tab() {
+ return " ";
+ }
+ reverse(args) {
+ return args.TEXT.split("").reverse().join("");
+ }
}
Scratch.extensions.register(new StringsExt());
From 2c59569afb647df32f239298966977a1416467c2 Mon Sep 17 00:00:00 2001
From: Mov <154533182+man-o-valor@users.noreply.github.com>
Date: Sat, 30 Nov 2024 15:49:47 -0500
Subject: [PATCH 04/13] Got declarations out of case statements and added the
rest of the 'cases to IsCase bool
---
extensions/text.js | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/extensions/text.js b/extensions/text.js
index ff0b64441b..252572a206 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -642,6 +642,12 @@
word[0].toUpperCase() + word.substring(1).toLowerCase();
return word === titleCased;
});
+ case CaseParam.CAMELCASE:
+ return string.test(/^[^A-Z\s][^\s]*$/);
+ case CaseParam.RANDOMCASE:
+ return true;
+ case CaseParam.SENTENCECASE:
+ return string.test(/^[A-Z][^?.!]*(?:[?.!]\s+[A-Z][^?.!]*)*$/);
default:
return false;
}
@@ -650,6 +656,7 @@
toCase(args, util) {
const string = args.STRING.toString();
const textCase = args.TEXTCASE.toString();
+ let sum = "";
switch (textCase) {
case CaseParam.LOWERCASE:
return string.toLowerCase();
@@ -678,40 +685,37 @@
})
.join("");
case CaseParam.SENTENCECASE:
- let sentencesum = "";
let capflag = false
for (let i = 0; i < string.length; i++) {
if (/^\s*$/.test(string[i-1] ?? " ") && !capflag && string[i].toUpperCase() != string[i].toLowerCase()) {
- sentencesum +=string[i].toUpperCase();
+ sum +=string[i].toUpperCase();
capflag = true
} else {
if (string[i] == "." || string[i] == "!" || string[i] == "?") {
capflag = false
}
- sentencesum += string[i].toLowerCase();
+ sum += string[i].toLowerCase();
}
}
- return sentencesum;
+ return sum;
case CaseParam.RANDOMCASE:
- let randomsum = "";
for (let i = 0; i < string.length; i++) {
if (Math.random()>0.5) {
- randomsum += string[i].toUpperCase()
+ sum += string[i].toUpperCase()
} else {
- randomsum += string[i].toLowerCase()
+ sum += string[i].toLowerCase()
}
}
- return randomsum;
+ return sum;
case CaseParam.CAMELCASE:
- let camelsum = "";
for (let i = 0; i < string.length; i++) {
if (/^\s*$/.test(string[i-1] ?? "x")) {
- camelsum += string[i].toUpperCase();
+ sum += string[i].toUpperCase();
} else {
- camelsum += string[i].toLowerCase();
+ sum += string[i].toLowerCase();
}
}
- return camelsum.replace(/\s/g, "");
+ return sum.replace(/\s/g, "");
default:
return string;
}
From a79588432f5a24d7ca806e3fc08c6579d203ce22 Mon Sep 17 00:00:00 2001
From: Mov <154533182+man-o-valor@users.noreply.github.com>
Date: Sat, 30 Nov 2024 15:51:16 -0500
Subject: [PATCH 05/13] Removed another let from case
---
extensions/text.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/extensions/text.js b/extensions/text.js
index 252572a206..0a72093360 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -657,6 +657,7 @@
const string = args.STRING.toString();
const textCase = args.TEXTCASE.toString();
let sum = "";
+ let capflag = false
switch (textCase) {
case CaseParam.LOWERCASE:
return string.toLowerCase();
@@ -685,7 +686,6 @@
})
.join("");
case CaseParam.SENTENCECASE:
- let capflag = false
for (let i = 0; i < string.length; i++) {
if (/^\s*$/.test(string[i-1] ?? " ") && !capflag && string[i].toUpperCase() != string[i].toLowerCase()) {
sum +=string[i].toUpperCase();
From 2be2332857939077367bc793214e0001a59aeaea Mon Sep 17 00:00:00 2001
From: Mov <154533182+man-o-valor@users.noreply.github.com>
Date: Sat, 30 Nov 2024 15:59:51 -0500
Subject: [PATCH 06/13] Fix credits to be formatted correctly
---
extensions/text.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/extensions/text.js b/extensions/text.js
index 0a72093360..a43f992477 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -1,7 +1,8 @@
// Name: Text
// ID: strings
// Description: Manipulate characters and text.
-// Original: CST1229 and Man-o-Valor
+// Original: CST1229
+// By: Man-o-Valor
// License: MIT AND MPL-2.0
(function (Scratch) {
From 4598e6963f74411fce136b1203ffe06c33b2433f Mon Sep 17 00:00:00 2001
From: Miyo Sho <135030944+yuri-kiss@users.noreply.github.com>
Date: Wed, 25 Dec 2024 02:49:40 -0500
Subject: [PATCH 07/13] patch-1
---
extensions/text.js | 14 --------------
1 file changed, 14 deletions(-)
diff --git a/extensions/text.js b/extensions/text.js
index 9ec8b4cb62..55712640b4 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -2,7 +2,6 @@
// ID: strings
// Description: Manipulate characters and text.
// Original: CST1229
-// By: Man-o-Valor
// License: MIT AND MPL-2.0
(function (Scratch) {
@@ -238,19 +237,6 @@
}
},
},
-
- "---",
-
- {
- opcode: 'enter',
- blockType: Scratch.BlockType.REPORTER,
- text: Scratch.translate("enter"),
- },
- {
- opcode: 'tab',
- blockType: Scratch.BlockType.REPORTER,
- text: Scratch.translate("tab"),
- },
"---",
From cb1f254edea901893b56882db14db2c3ee616252 Mon Sep 17 00:00:00 2001
From: yuri-kiss <135030944+yuri-kiss@users.noreply.github.com>
Date: Wed, 25 Dec 2024 02:54:28 -0500
Subject: [PATCH 08/13] Format
---
extensions/text.js | 89 +++++++++++++++++++++++++---------------------
1 file changed, 48 insertions(+), 41 deletions(-)
diff --git a/extensions/text.js b/extensions/text.js
index 55712640b4..21f72004b2 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -15,7 +15,7 @@
EXACTTITLECASE: "exacttitlecase",
RANDOMCASE: "randomcase",
SENTENCECASE: "sentencecase",
- CAMELCASE: "camelcase"
+ CAMELCASE: "camelcase",
};
let splitCache;
@@ -43,7 +43,8 @@
{
text: Scratch.translate({
default: "Sentence case",
- description: "Starts words after ., !, and ? with captialized letters",
+ description:
+ "Starts words after ., !, and ? with captialized letters",
}),
value: CaseParam.SENTENCECASE,
},
@@ -74,14 +75,16 @@
{
text: Scratch.translate({
default: "RAndoMCaSe",
- description: "If your language has randomcase, style it accordingly",
+ description:
+ "If your language has randomcase, style it accordingly",
}),
value: CaseParam.RANDOMCASE,
},
{
text: Scratch.translate({
default: "camelCase",
- description: "Removes all spaces and capitalizes all words after the first",
+ description:
+ "Removes all spaces and capitalizes all words after the first",
}),
value: CaseParam.CAMELCASE,
},
@@ -211,33 +214,33 @@
},
},
{
- opcode: 'surround',
+ opcode: "surround",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("surround [TEXT] with [QUOTE]"),
arguments: {
TEXT: {
type: Scratch.ArgumentType.STRING,
- defaultValue: "apple"
+ defaultValue: "apple",
},
QUOTE: {
type: Scratch.ArgumentType.STRING,
- menu: "QUOTES"
- }
+ menu: "QUOTES",
+ },
},
},
{
- opcode: 'reverse',
+ opcode: "reverse",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("reverse [TEXT]"),
arguments: {
- TEXT: {
- type: Scratch.ArgumentType.STRING,
- defaultValue: "apple"
- }
+ TEXT: {
+ type: Scratch.ArgumentType.STRING,
+ defaultValue: "apple",
+ },
},
},
-
+
"---",
{
@@ -484,7 +487,7 @@
},
quotes: {
acceptReporters: true,
- items: ["\"", "'", "`", "-", "*", "()", "{}", "[]", "<>", "^$"],
+ items: ['"', "'", "`", "-", "*", "()", "{}", "[]", "<>", "^$"],
},
positions: {
acceptReporters: true,
@@ -727,7 +730,7 @@
const string = args.STRING.toString();
const textCase = args.TEXTCASE.toString();
let sum = "";
- let capflag = false
+ let capflag = false;
switch (textCase) {
case CaseParam.LOWERCASE:
return string.toLowerCase();
@@ -757,33 +760,37 @@
.join("");
case CaseParam.SENTENCECASE:
for (let i = 0; i < string.length; i++) {
- if (/^\s*$/.test(string[i-1] ?? " ") && !capflag && string[i].toUpperCase() != string[i].toLowerCase()) {
- sum +=string[i].toUpperCase();
- capflag = true
- } else {
- if (string[i] == "." || string[i] == "!" || string[i] == "?") {
- capflag = false
- }
- sum += string[i].toLowerCase();
+ if (
+ /^\s*$/.test(string[i - 1] ?? " ") &&
+ !capflag &&
+ string[i].toUpperCase() != string[i].toLowerCase()
+ ) {
+ sum += string[i].toUpperCase();
+ capflag = true;
+ } else {
+ if (string[i] == "." || string[i] == "!" || string[i] == "?") {
+ capflag = false;
}
+ sum += string[i].toLowerCase();
+ }
}
return sum;
case CaseParam.RANDOMCASE:
for (let i = 0; i < string.length; i++) {
- if (Math.random()>0.5) {
- sum += string[i].toUpperCase()
- } else {
- sum += string[i].toLowerCase()
- }
+ if (Math.random() > 0.5) {
+ sum += string[i].toUpperCase();
+ } else {
+ sum += string[i].toLowerCase();
+ }
}
return sum;
case CaseParam.CAMELCASE:
for (let i = 0; i < string.length; i++) {
- if (/^\s*$/.test(string[i-1] ?? "x")) {
- sum += string[i].toUpperCase();
- } else {
- sum += string[i].toLowerCase();
- }
+ if (/^\s*$/.test(string[i - 1] ?? "x")) {
+ sum += string[i].toUpperCase();
+ } else {
+ sum += string[i].toLowerCase();
+ }
}
return sum.replace(/\s/g, "");
default:
@@ -791,13 +798,13 @@
}
}
surround(args) {
- if (args.QUOTE.length == 0) {
- return args.TEXT;
- } else if (args.QUOTE.length == 1) {
- return args.QUOTE + args.TEXT + args.QUOTE;
- } else if (args.QUOTE.length > 1) {
- return args.QUOTE[0] + args.TEXT + args.QUOTE[1];
- }
+ if (args.QUOTE.length == 0) {
+ return args.TEXT;
+ } else if (args.QUOTE.length == 1) {
+ return args.QUOTE + args.TEXT + args.QUOTE;
+ } else if (args.QUOTE.length > 1) {
+ return args.QUOTE[0] + args.TEXT + args.QUOTE[1];
+ }
}
posWith(args) {
const STRING = args.STRING.toString();
From e8d5a5a3796fcb044fe2e0eee6d0f36955f2e294 Mon Sep 17 00:00:00 2001
From: SharkPool <139097378+SharkPool-SP@users.noreply.github.com>
Date: Wed, 25 Dec 2024 00:04:23 -0800
Subject: [PATCH 09/13] remove duplicate block
---
extensions/text.js | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/extensions/text.js b/extensions/text.js
index 21f72004b2..850d2d97bf 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -229,18 +229,6 @@
},
},
- {
- opcode: "reverse",
- blockType: Scratch.BlockType.REPORTER,
- text: Scratch.translate("reverse [TEXT]"),
- arguments: {
- TEXT: {
- type: Scratch.ArgumentType.STRING,
- defaultValue: "apple",
- },
- },
- },
-
"---",
{
From 0ade455a29337609dceee4ac63010e4cf9efd4d1 Mon Sep 17 00:00:00 2001
From: Miyo Sho <135030944+yuri-kiss@users.noreply.github.com>
Date: Wed, 25 Dec 2024 03:37:35 -0500
Subject: [PATCH 10/13] Partial revert of
4598e6963f74411fce136b1203ffe06c33b2433f
---
extensions/text.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/extensions/text.js b/extensions/text.js
index 850d2d97bf..68c1f50184 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -2,6 +2,7 @@
// ID: strings
// Description: Manipulate characters and text.
// Original: CST1229
+// By: Man-o-Valor
// License: MIT AND MPL-2.0
(function (Scratch) {
From 8e92f7408f470677e2a74cec91fe778cf1e2ea0c Mon Sep 17 00:00:00 2001
From: SharkPool <139097378+SharkPool-SP@users.noreply.github.com>
Date: Sat, 28 Dec 2024 00:23:23 -0800
Subject: [PATCH 11/13] text.js -- remove "surround" block
---
extensions/text.js | 28 ----------------------------
1 file changed, 28 deletions(-)
diff --git a/extensions/text.js b/extensions/text.js
index d555d92a67..ecfe15f1a7 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -215,21 +215,6 @@
},
},
},
- {
- opcode: "surround",
- blockType: Scratch.BlockType.REPORTER,
- text: Scratch.translate("surround [TEXT] with [QUOTE]"),
- arguments: {
- TEXT: {
- type: Scratch.ArgumentType.STRING,
- defaultValue: "apple",
- },
- QUOTE: {
- type: Scratch.ArgumentType.STRING,
- menu: "QUOTES",
- },
- },
- },
"---",
@@ -475,10 +460,6 @@
acceptReporters: true,
items: this._initCaseMenu(),
},
- quotes: {
- acceptReporters: true,
- items: ['"', "'", "`", "-", "*", "()", "{}", "[]", "<>", "^$"],
- },
positions: {
acceptReporters: true,
items: [
@@ -787,15 +768,6 @@
return string;
}
}
- surround(args) {
- if (args.QUOTE.length == 0) {
- return args.TEXT;
- } else if (args.QUOTE.length == 1) {
- return args.QUOTE + args.TEXT + args.QUOTE;
- } else if (args.QUOTE.length > 1) {
- return args.QUOTE[0] + args.TEXT + args.QUOTE[1];
- }
- }
posWith(args) {
const STRING = args.STRING.toString();
const SUBSTRING = args.SUBSTRING.toString();
From 02d2a0e7c26de8956ad99535bfaffcf4a9c12247 Mon Sep 17 00:00:00 2001
From: Mov
Date: Sat, 28 Dec 2024 09:19:00 -0500
Subject: [PATCH 12/13] Made variable names more clear and fixed regex test
function
Renamed sum to workingText and capflag to sentenceCapitalFlag
---
extensions/text.js | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/extensions/text.js b/extensions/text.js
index ecfe15f1a7..767e64855c 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -691,7 +691,7 @@
case CaseParam.RANDOMCASE:
return true;
case CaseParam.SENTENCECASE:
- return string.test(/^[A-Z][^?.!]*(?:[?.!]\s+[A-Z][^?.!]*)*$/);
+ return /^[A-Z][^?.!]*(?:[?.!]\s+[A-Z][^?.!]*)*$/.test(string);
default:
return false;
}
@@ -700,8 +700,8 @@
toCase(args, util) {
const string = args.STRING.toString();
const textCase = args.TEXTCASE.toString();
- let sum = "";
- let capflag = false;
+ let workingText = "";
+ let sentenceCapitalFlag = false;
switch (textCase) {
case CaseParam.LOWERCASE:
return string.toLowerCase();
@@ -733,37 +733,37 @@
for (let i = 0; i < string.length; i++) {
if (
/^\s*$/.test(string[i - 1] ?? " ") &&
- !capflag &&
+ !sentenceCapitalFlag &&
string[i].toUpperCase() != string[i].toLowerCase()
) {
- sum += string[i].toUpperCase();
- capflag = true;
+ workingText += string[i].toUpperCase();
+ sentenceCapitalFlag = true;
} else {
if (string[i] == "." || string[i] == "!" || string[i] == "?") {
- capflag = false;
+ sentenceCapitalFlag = false;
}
- sum += string[i].toLowerCase();
+ workingText += string[i].toLowerCase();
}
}
- return sum;
+ return workingText;
case CaseParam.RANDOMCASE:
for (let i = 0; i < string.length; i++) {
if (Math.random() > 0.5) {
- sum += string[i].toUpperCase();
+ workingText += string[i].toUpperCase();
} else {
- sum += string[i].toLowerCase();
+ workingText += string[i].toLowerCase();
}
}
- return sum;
+ return workingText;
case CaseParam.CAMELCASE:
for (let i = 0; i < string.length; i++) {
if (/^\s*$/.test(string[i - 1] ?? "x")) {
- sum += string[i].toUpperCase();
+ workingText += string[i].toUpperCase();
} else {
- sum += string[i].toLowerCase();
+ workingText += string[i].toLowerCase();
}
}
- return sum.replace(/\s/g, "");
+ return workingText.replace(/\s/g, "");
default:
return string;
}
From 607928142d256a593de2698d21a2ebc73807c6c4 Mon Sep 17 00:00:00 2001
From: Mov
Date: Sat, 28 Dec 2024 13:23:58 -0500
Subject: [PATCH 13/13] Fixed the other regex test error
---
extensions/text.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/extensions/text.js b/extensions/text.js
index 767e64855c..217d6f1706 100644
--- a/extensions/text.js
+++ b/extensions/text.js
@@ -687,7 +687,7 @@
return word === titleCased;
});
case CaseParam.CAMELCASE:
- return string.test(/^[^A-Z\s][^\s]*$/);
+ return /^[^A-Z\s][^\s]*$/.test(string);
case CaseParam.RANDOMCASE:
return true;
case CaseParam.SENTENCECASE: