mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Converted JS operations
Deleted legacy files, neatened args in other ported ops
This commit is contained in:
parent
95f81ad740
commit
176e83a79f
13 changed files with 236 additions and 554 deletions
57
src/core/operations/JavaScriptMinify.mjs
Normal file
57
src/core/operations/JavaScriptMinify.mjs
Normal file
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import * as esprima from "esprima";
|
||||
import escodegen from "escodegen";
|
||||
import esmangle from "esmangle";
|
||||
|
||||
/**
|
||||
* JavaScript Minify operation
|
||||
*/
|
||||
class JavaScriptMinify extends Operation {
|
||||
|
||||
/**
|
||||
* JavaScriptMinify constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "JavaScript Minify";
|
||||
this.module = "Code";
|
||||
this.description = "Compresses JavaScript code.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
let result = "";
|
||||
const AST = esprima.parseScript(input),
|
||||
optimisedAST = esmangle.optimize(AST, null),
|
||||
mangledAST = esmangle.mangle(optimisedAST);
|
||||
|
||||
result = escodegen.generate(mangledAST, {
|
||||
format: {
|
||||
renumber: true,
|
||||
hexadecimal: true,
|
||||
escapeless: true,
|
||||
compact: true,
|
||||
semicolons: false,
|
||||
parentheses: false
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default JavaScriptMinify;
|
Loading…
Add table
Add a link
Reference in a new issue