mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 23:36:16 -04:00
Merge remote-tracking branch 'upstream/master' into feature-exif
This commit is contained in:
commit
71796e3dbf
7 changed files with 281 additions and 2 deletions
|
@ -272,6 +272,9 @@ const Categories = [
|
|||
"CSS selector",
|
||||
"Strip HTML tags",
|
||||
"Diff",
|
||||
"To Snake case",
|
||||
"To Camel case",
|
||||
"To Kebab case",
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -3250,6 +3250,69 @@ const OperationConfig = {
|
|||
},
|
||||
]
|
||||
},
|
||||
"To Snake case": {
|
||||
description: [
|
||||
"Converts the input string to snake case.",
|
||||
"<br><br>",
|
||||
"Snake case is all lower case with underscores as word boundaries.",
|
||||
"<br><br>",
|
||||
"e.g. this_is_snake_case",
|
||||
"<br><br>",
|
||||
"'Attempt to be context aware' will make the operation attempt to nicely transform variable and function names.",
|
||||
].join("\n"),
|
||||
run: Code.runToSnakeCase,
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Attempt to be context aware",
|
||||
type: "boolean",
|
||||
value: false,
|
||||
},
|
||||
]
|
||||
},
|
||||
"To Camel case": {
|
||||
description: [
|
||||
"Converts the input string to camel case.",
|
||||
"<br><br>",
|
||||
"Camel case is all lower case except letters after word boundaries which are uppercase.",
|
||||
"<br><br>",
|
||||
"e.g. thisIsCamelCase",
|
||||
"<br><br>",
|
||||
"'Attempt to be context aware' will make the operation attempt to nicely transform variable and function names.",
|
||||
].join("\n"),
|
||||
run: Code.runToCamelCase,
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Attempt to be context aware",
|
||||
type: "boolean",
|
||||
value: false,
|
||||
},
|
||||
]
|
||||
},
|
||||
"To Kebab case": {
|
||||
description: [
|
||||
"Converts the input string to kebab case.",
|
||||
"<br><br>",
|
||||
"Kebab case is all lower case with dashes as word boundaries.",
|
||||
"<br><br>",
|
||||
"e.g. this-is-kebab-case",
|
||||
"<br><br>",
|
||||
"'Attempt to be context aware' will make the operation attempt to nicely transform variable and function names.",
|
||||
].join("\n"),
|
||||
run: Code.runToKebabCase,
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Attempt to be context aware",
|
||||
type: "boolean",
|
||||
value: false,
|
||||
},
|
||||
]
|
||||
},
|
||||
"Extract EXIF": {
|
||||
description: [
|
||||
].join("\n"),
|
||||
|
@ -3257,7 +3320,7 @@ const OperationConfig = {
|
|||
inputType: "byteArray",
|
||||
outputType: "string",
|
||||
args: [
|
||||
]
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import {camelCase, kebabCase, snakeCase} from "lodash";
|
||||
|
||||
import Utils from "../Utils.js";
|
||||
import vkbeautify from "vkbeautify";
|
||||
import {DOMParser as dom} from "xmldom";
|
||||
|
@ -415,6 +417,84 @@ const Code = {
|
|||
.join(delimiter);
|
||||
},
|
||||
|
||||
/**
|
||||
* This tries to rename variable names in a code snippet according to a function.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {function} replacer - this function will be fed the token which should be renamed.
|
||||
* @returns {string}
|
||||
*/
|
||||
_replaceVariableNames(input, replacer) {
|
||||
let tokenRegex = /\\"|"(?:\\"|[^"])*"|(\b[a-z0-9\-_]+\b)/ig;
|
||||
|
||||
return input.replace(tokenRegex, (...args) => {
|
||||
let match = args[0],
|
||||
quotes = args[1];
|
||||
|
||||
if (!quotes) {
|
||||
return match;
|
||||
} else {
|
||||
return replacer(match);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Converts to snake_case.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
runToSnakeCase(input, args) {
|
||||
let smart = args[0];
|
||||
|
||||
if (smart) {
|
||||
return Code._replaceVariableNames(input, snakeCase);
|
||||
} else {
|
||||
return snakeCase(input);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Converts to camelCase.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
runToCamelCase(input, args) {
|
||||
let smart = args[0];
|
||||
|
||||
if (smart) {
|
||||
return Code._replaceVariableNames(input, camelCase);
|
||||
} else {
|
||||
return camelCase(input);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Converts to kebab-case.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
runToKebabCase(input, args) {
|
||||
let smart = args[0];
|
||||
|
||||
if (smart) {
|
||||
return Code._replaceVariableNames(input, kebabCase);
|
||||
} else {
|
||||
return kebabCase(input);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default Code;
|
||||
|
|
|
@ -592,7 +592,6 @@ const StrUtils = {
|
|||
|
||||
return output;
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
export default StrUtils;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue