Added 'Strict mode' to 'From Base64' operation

This commit is contained in:
n1474335 2022-06-03 21:41:37 +01:00
parent f9a6402825
commit b78bb2d3d6
4 changed files with 78 additions and 68 deletions

View file

@ -5,6 +5,7 @@
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* To Upper case operation
@ -38,27 +39,29 @@ class ToUpperCase extends Operation {
*/
run(input, args) {
if (!args || args.length === 0) {
throw new OperationException("No capitalization scope was provided.");
throw new OperationError("No capitalization scope was provided.");
}
const scope = args[0];
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.
}[scope];
if (scopeRegex === undefined) {
throw new OperationError("Unrecognized capitalization scope");
}
// Use the regex to capitalize the input
return input.replace(scopeRegex, function(m) {
return m.toUpperCase();
});
}
/**