mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 08:58:30 +01:00
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
|
/**
|
||
|
* @author tlwr [toby@toby.codes]
|
||
|
* @copyright Crown Copyright 2017
|
||
|
* @license Apache-2.0
|
||
|
*/
|
||
|
|
||
|
import { camelCase } from "lodash";
|
||
|
import Operation from "../Operation";
|
||
|
import { replaceVariableNames } from "../lib/Code";
|
||
|
|
||
|
/**
|
||
|
* To Camel case operation
|
||
|
*/
|
||
|
class ToCamelCase extends Operation {
|
||
|
|
||
|
/**
|
||
|
* ToCamelCase constructor
|
||
|
*/
|
||
|
constructor() {
|
||
|
super();
|
||
|
|
||
|
this.name = "To Camel case";
|
||
|
this.module = "Code";
|
||
|
this.description = "Converts the input string to camel case.\n<br><br>\nCamel case is all lower case except letters after word boundaries which are uppercase.\n<br><br>\ne.g. thisIsCamelCase\n<br><br>\n'Attempt to be context aware' will make the operation attempt to nicely transform variable and function names.";
|
||
|
this.inputType = "string";
|
||
|
this.outputType = "string";
|
||
|
this.args = [
|
||
|
{
|
||
|
"name": "Attempt to be context aware",
|
||
|
"type": "boolean",
|
||
|
"value": false
|
||
|
}
|
||
|
];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param {string} input
|
||
|
* @param {Object[]} args
|
||
|
* @returns {string}
|
||
|
*/
|
||
|
run(input, args) {
|
||
|
const smart = args[0];
|
||
|
|
||
|
if (smart) {
|
||
|
return replaceVariableNames(input, camelCase);
|
||
|
} else {
|
||
|
return camelCase(input);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
export default ToCamelCase;
|