Minor adjustments

This commit is contained in:
Michael Rowley 2021-12-29 19:32:39 +00:00
parent ae1b12c120
commit 2574a63975
2 changed files with 31 additions and 29 deletions

View file

@ -38,23 +38,23 @@ class ToUpperCase extends Operation {
*/
run(input, args) {
const scope = args[0];
switch (scope) {
case "Word":
return input.replace(/(\b\w)/gi, function(m) {
return m.toUpperCase();
});
case "Sentence":
return input.replace(/(?:\.|^)\s*(\b\w)/gi, function(m) {
return m.toUpperCase();
});
case "Paragraph":
return input.replace(/(?:\n|^)\s*(\b\w)/gi, function(m) {
return m.toUpperCase();
});
case "All": /* falls through */
default:
return input.toUpperCase();
if (scope === "All") {
return input.toUpperCase();
}
const scopeRegex = {
"Word": /(\b\w)/gi,
"Sentence": /(?:\.|^)\s*(\b\w)/gi,
"Paragraph": /(?:\n|^)\s*(\b\w)/gi
}[ scope ];
if (scopeRegex !== undefined) {
// Use the regexes to capitalize the input.
return input.replace(scopeRegex, function(m) {
return m.toUpperCase();
});
}
else {
// The selected scope was invalid.
throw new OperationError("Unrecognized capitalization scope");
}
}