mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
ESM: Ported case converters, generic beautifier and syntax highlighting
This commit is contained in:
parent
176e83a79f
commit
905bc6699e
6 changed files with 428 additions and 0 deletions
52
src/core/operations/ToSnakeCase.mjs
Normal file
52
src/core/operations/ToSnakeCase.mjs
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* @author tlwr [toby@toby.codes]
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import { snakeCase } from "lodash";
|
||||
import Operation from "../Operation";
|
||||
import { replaceVariableNames } from "../lib/Code";
|
||||
|
||||
/**
|
||||
* To Snake case operation
|
||||
*/
|
||||
class ToSnakeCase extends Operation {
|
||||
|
||||
/**
|
||||
* ToSnakeCase constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "To Snake case";
|
||||
this.module = "Code";
|
||||
this.description = "Converts the input string to snake case.\n<br><br>\nSnake case is all lower case with underscores as word boundaries.\n<br><br>\ne.g. this_is_snake_case\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, snakeCase);
|
||||
} else {
|
||||
return snakeCase(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ToSnakeCase;
|
Loading…
Add table
Add a link
Reference in a new issue