This commit is contained in:
Edoardo Sichelli 2022-06-13 10:06:20 +04:30 committed by GitHub
commit 79663d2c23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 2 deletions

View file

@ -65,7 +65,8 @@
"JSON to CSV",
"Avro to JSON",
"CBOR Encode",
"CBOR Decode"
"CBOR Decode",
"Inverting characters case"
]
},
{
@ -221,7 +222,8 @@
"Unicode Text Format",
"Remove Diacritics",
"Unescape Unicode Characters",
"Convert to NATO alphabet"
"Convert to NATO alphabet",
"Inverting characters case"
]
},
{

View file

@ -0,0 +1,62 @@
/**
* @author Sichej [edoardo.sichelli@gmail.com]
* @copyright Crown Copyright 2022
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* Inverting characters case operation
*/
class InvertingCharactersCase extends Operation {
/**
* InvertingCharactersCase constructor
*/
constructor() {
super();
this.name = "Inverting characters case";
this.module = "Default";
this.description = "Inverting characters case <code>vgHPCYbcyxnLnJqGBwvHBNmGC29TzxrOAw5NlG==</code> becomes <code>VGhpcyBCYXNlNjQgbWVhbnMgc29tZXRoaW5nLg==</code>";
this.infoURL = "";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
let result = "";
for (let i = 0; i < input.length; i++) {
result += this.checkAndChangeCase(input[i]);
}
return result;
}
/**
* Check if a character is Uppercase or Lowercase
* and returns the opposite
*/
checkAndChangeCase(character) {
try {
if (character.charCodeAt(0) > 64 && character.charCodeAt(0) < 91)
return character.toLowerCase();
else if (character.charCodeAt(0) > 96 && character.charCodeAt(0) < 123)
return character.toUpperCase();
else
return character;
} catch (error) {
throw new OperationError("Error, something went wrong");
}
}
}
export default InvertingCharactersCase;