mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -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
53
src/core/operations/ToKebabCase.mjs
Normal file
53
src/core/operations/ToKebabCase.mjs
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import { kebabCase } from "lodash";
|
||||
import Operation from "../Operation";
|
||||
import { replaceVariableNames } from "../lib/Code";
|
||||
|
||||
/**
|
||||
* To Kebab case operation
|
||||
*/
|
||||
class ToKebabCase extends Operation {
|
||||
|
||||
/**
|
||||
* ToKebabCase constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "To Kebab case";
|
||||
this.module = "Code";
|
||||
this.description = "Converts the input string to kebab case.\n<br><br>\nKebab case is all lower case with dashes as word boundaries.\n<br><br>\ne.g. this-is-kebab-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, kebabCase);
|
||||
} else {
|
||||
return kebabCase(input);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ToKebabCase;
|
Loading…
Add table
Add a link
Reference in a new issue