mirror of
https://github.com/gchq/CyberChef
synced 2025-12-15 07:43:22 +00:00
Ported rest of Code ops & enabled/fixed some tests
This commit is contained in:
48
src/core/operations/JSONBeautify.mjs
Normal file
48
src/core/operations/JSONBeautify.mjs
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import vkbeautify from "vkbeautify";
|
||||
import Operation from "../Operation";
|
||||
|
||||
/**
|
||||
* JSON Beautify operation
|
||||
*/
|
||||
class JSONBeautify extends Operation {
|
||||
|
||||
/**
|
||||
* JSONBeautify constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "JSON Beautify";
|
||||
this.module = "Code";
|
||||
this.description = "Indents and prettifies JavaScript Object Notation (JSON) code.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Indent string",
|
||||
"type": "binaryShortString",
|
||||
"value": "\\t"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const indentStr = args[0];
|
||||
if (!input) return "";
|
||||
return vkbeautify.json(input, indentStr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default JSONBeautify;
|
||||
Reference in New Issue
Block a user