Converted all modules from CommonJS to ES6

This commit is contained in:
n1474335 2017-03-23 17:52:20 +00:00
parent 0f2a5014be
commit 131b3a83c1
75 changed files with 395 additions and 282 deletions

View file

@ -1,9 +1,9 @@
var Utils = require("../core/Utils.js"),
Chef = require("../core/Chef.js"),
Manager = require("./Manager.js"),
HTMLCategory = require("./HTMLCategory.js"),
HTMLOperation = require("./HTMLOperation.js"),
Split = require("split.js");
import Utils from "../core/Utils.js";
import Chef from "../core/Chef.js";
import Manager from "./Manager.js";
import HTMLCategory from "./HTMLCategory.js";
import HTMLOperation from "./HTMLOperation.js";
import Split from "split.js";
/**
@ -20,7 +20,7 @@ var Utils = require("../core/Utils.js"),
* @param {String[]} defaultFavourites - A list of default favourite operations.
* @param {Object} options - Default setting for app options.
*/
var HTMLApp = module.exports = function(categories, operations, defaultFavourites, defaultOptions) {
var App = function(categories, operations, defaultFavourites, defaultOptions) {
this.categories = categories;
this.operations = operations;
this.dfavourites = defaultFavourites;
@ -43,7 +43,7 @@ var HTMLApp = module.exports = function(categories, operations, defaultFavourite
*
* @fires Manager#appstart
*/
HTMLApp.prototype.setup = function() {
App.prototype.setup = function() {
document.dispatchEvent(this.manager.appstart);
this.initialiseSplitter();
this.loadLocalStorage();
@ -60,7 +60,7 @@ HTMLApp.prototype.setup = function() {
*
* @param {Error} err
*/
HTMLApp.prototype.handleError = function(err) {
App.prototype.handleError = function(err) {
console.error(err);
var msg = err.displayStr || err.toString();
this.alert(msg, "danger", this.options.errorTimeout, !this.options.showErrors);
@ -73,7 +73,7 @@ HTMLApp.prototype.handleError = function(err) {
* @param {boolean} [step] - Set to true if we should only execute one operation instead of the
* whole recipe.
*/
HTMLApp.prototype.bake = function(step) {
App.prototype.bake = function(step) {
var response;
try {
@ -112,7 +112,7 @@ HTMLApp.prototype.bake = function(step) {
/**
* Runs Auto Bake if it is set.
*/
HTMLApp.prototype.autoBake = function() {
App.prototype.autoBake = function() {
if (this.autoBake_) {
this.bake();
}
@ -128,7 +128,7 @@ HTMLApp.prototype.autoBake = function() {
*
* @returns {number} - The number of miliseconds it took to run the silent bake.
*/
HTMLApp.prototype.silentBake = function() {
App.prototype.silentBake = function() {
var startTime = new Date().getTime(),
recipeConfig = this.getRecipeConfig();
@ -145,7 +145,7 @@ HTMLApp.prototype.silentBake = function() {
*
* @returns {string}
*/
HTMLApp.prototype.getInput = function() {
App.prototype.getInput = function() {
var input = this.manager.input.get();
// Save to session storage in case we need to restore it later
@ -161,7 +161,7 @@ HTMLApp.prototype.getInput = function() {
*
* @param {string} input - The string to set the input to
*/
HTMLApp.prototype.setInput = function(input) {
App.prototype.setInput = function(input) {
sessionStorage.setItem("inputLength", input.length);
sessionStorage.setItem("input", input);
this.manager.input.set(input);
@ -174,7 +174,7 @@ HTMLApp.prototype.setInput = function(input) {
*
* @fires Manager#oplistcreate
*/
HTMLApp.prototype.populateOperationsList = function() {
App.prototype.populateOperationsList = function() {
// Move edit button away before we overwrite it
document.body.appendChild(document.getElementById("edit-favourites"));
@ -210,7 +210,7 @@ HTMLApp.prototype.populateOperationsList = function() {
/**
* Sets up the adjustable splitter to allow the user to resize areas of the page.
*/
HTMLApp.prototype.initialiseSplitter = function() {
App.prototype.initialiseSplitter = function() {
this.columnSplitter = Split(["#operations", "#recipe", "#IO"], {
sizes: [20, 30, 50],
minSize: [240, 325, 440],
@ -234,7 +234,7 @@ HTMLApp.prototype.initialiseSplitter = function() {
* Loads the information previously saved to the HTML5 local storage object so that user options
* and favourites can be restored.
*/
HTMLApp.prototype.loadLocalStorage = function() {
App.prototype.loadLocalStorage = function() {
// Load options
var lOptions;
if (localStorage.options !== undefined) {
@ -252,7 +252,7 @@ HTMLApp.prototype.loadLocalStorage = function() {
* Favourites category with them.
* If the user currently has no saved favourites, the defaults from the view constructor are used.
*/
HTMLApp.prototype.loadFavourites = function() {
App.prototype.loadFavourites = function() {
var favourites = localStorage.favourites &&
localStorage.favourites.length > 2 ?
JSON.parse(localStorage.favourites) :
@ -283,7 +283,7 @@ HTMLApp.prototype.loadFavourites = function() {
* @param {string[]} favourites - A list of the user's favourite operations
* @returns {string[]} A list of the valid favourites
*/
HTMLApp.prototype.validFavourites = function(favourites) {
App.prototype.validFavourites = function(favourites) {
var validFavs = [];
for (var i = 0; i < favourites.length; i++) {
if (this.operations.hasOwnProperty(favourites[i])) {
@ -302,7 +302,7 @@ HTMLApp.prototype.validFavourites = function(favourites) {
*
* @param {string[]} favourites - A list of the user's favourite operations
*/
HTMLApp.prototype.saveFavourites = function(favourites) {
App.prototype.saveFavourites = function(favourites) {
localStorage.setItem("favourites", JSON.stringify(this.validFavourites(favourites)));
};
@ -311,7 +311,7 @@ HTMLApp.prototype.saveFavourites = function(favourites) {
* Resets favourite operations back to the default as specified in the view constructor and
* refreshes the operation list.
*/
HTMLApp.prototype.resetFavourites = function() {
App.prototype.resetFavourites = function() {
this.saveFavourites(this.dfavourites);
this.loadFavourites();
this.populateOperationsList();
@ -324,7 +324,7 @@ HTMLApp.prototype.resetFavourites = function() {
*
* @param {string} name - The name of the operation
*/
HTMLApp.prototype.addFavourite = function(name) {
App.prototype.addFavourite = function(name) {
var favourites = JSON.parse(localStorage.favourites);
if (favourites.indexOf(name) >= 0) {
@ -343,7 +343,7 @@ HTMLApp.prototype.addFavourite = function(name) {
/**
* Checks for input and recipe in the URI parameters and loads them if present.
*/
HTMLApp.prototype.loadURIParams = function() {
App.prototype.loadURIParams = function() {
// Load query string from URI
this.queryString = (function(a) {
if (a === "") return {};
@ -408,7 +408,7 @@ HTMLApp.prototype.loadURIParams = function() {
*
* @returns {number}
*/
HTMLApp.prototype.nextIngId = function() {
App.prototype.nextIngId = function() {
return this.ingId++;
};
@ -418,7 +418,7 @@ HTMLApp.prototype.nextIngId = function() {
*
* @returns {Object[]}
*/
HTMLApp.prototype.getRecipeConfig = function() {
App.prototype.getRecipeConfig = function() {
var recipeConfig = this.manager.recipe.getConfig();
sessionStorage.setItem("recipeConfig", JSON.stringify(recipeConfig));
return recipeConfig;
@ -430,7 +430,7 @@ HTMLApp.prototype.getRecipeConfig = function() {
*
* @param {Object[]} recipeConfig - The recipe configuration
*/
HTMLApp.prototype.setRecipeConfig = function(recipeConfig) {
App.prototype.setRecipeConfig = function(recipeConfig) {
sessionStorage.setItem("recipeConfig", JSON.stringify(recipeConfig));
document.getElementById("rec-list").innerHTML = null;
@ -471,7 +471,7 @@ HTMLApp.prototype.setRecipeConfig = function(recipeConfig) {
/**
* Resets the splitter positions to default.
*/
HTMLApp.prototype.resetLayout = function() {
App.prototype.resetLayout = function() {
this.columnSplitter.setSizes([20, 30, 50]);
this.ioSplitter.setSizes([50, 50]);
@ -483,7 +483,7 @@ HTMLApp.prototype.resetLayout = function() {
/**
* Sets the compile message.
*/
HTMLApp.prototype.setCompileMessage = function() {
App.prototype.setCompileMessage = function() {
// Display time since last build and compile message
var now = new Date(),
timeSinceCompile = Utils.fuzzyTime(now.getTime() - window.compileTime),
@ -522,7 +522,7 @@ HTMLApp.prototype.setCompileMessage = function() {
* // that will disappear after 5 seconds.
* this.alert("Happy Christmas!", "info", 5000);
*/
HTMLApp.prototype.alert = function(str, style, timeout, silent) {
App.prototype.alert = function(str, style, timeout, silent) {
var time = new Date();
console.log("[" + time.toLocaleString() + "] " + str);
@ -576,7 +576,7 @@ HTMLApp.prototype.alert = function(str, style, timeout, silent) {
* // Pops up a box asking if the user would like a cookie. Prints the answer to the console.
* this.confirm("Question", "Would you like a cookie?", function(answer) {console.log(answer);});
*/
HTMLApp.prototype.confirm = function(title, body, callback, scope) {
App.prototype.confirm = function(title, body, callback, scope) {
scope = scope || this;
document.getElementById("confirm-title").innerHTML = title;
document.getElementById("confirm-body").innerHTML = body;
@ -604,7 +604,7 @@ HTMLApp.prototype.confirm = function(title, body, callback, scope) {
* Handler for the alert close button click event.
* Closes the alert box.
*/
HTMLApp.prototype.alertCloseClick = function() {
App.prototype.alertCloseClick = function() {
document.getElementById("alert").style.display = "none";
};
@ -616,7 +616,7 @@ HTMLApp.prototype.alertCloseClick = function() {
* @listens Manager#statechange
* @param {event} e
*/
HTMLApp.prototype.stateChange = function(e) {
App.prototype.stateChange = function(e) {
this.autoBake();
// Update the current history state (not creating a new one)
@ -633,7 +633,7 @@ HTMLApp.prototype.stateChange = function(e) {
*
* @param {event} e
*/
HTMLApp.prototype.popState = function(e) {
App.prototype.popState = function(e) {
if (window.location.href.split("#")[0] !== this.lastStateUrl) {
this.loadURIParams();
}
@ -643,7 +643,7 @@ HTMLApp.prototype.popState = function(e) {
/**
* Function to call an external API from this view.
*/
HTMLApp.prototype.callApi = function(url, type, data, dataType, contentType) {
App.prototype.callApi = function(url, type, data, dataType, contentType) {
type = type || "POST";
data = data || {};
dataType = dataType || undefined;
@ -674,3 +674,5 @@ HTMLApp.prototype.callApi = function(url, type, data, dataType, contentType) {
response: response
};
};
export default App;

View file

@ -1,4 +1,4 @@
var Utils = require("../core/Utils.js");
import Utils from "../core/Utils.js";
/**
@ -9,10 +9,10 @@ var Utils = require("../core/Utils.js");
* @license Apache-2.0
*
* @constructor
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
* @param {Manager} manager - The CyberChef event manager.
*/
var ControlsWaiter = module.exports = function(app, manager) {
var ControlsWaiter = function(app, manager) {
this.app = app;
this.manager = manager;
};
@ -358,3 +358,5 @@ ControlsWaiter.prototype.supportButtonClick = function() {
"* User-Agent: \n" + navigator.userAgent + "\n" +
"* [Link to reproduce](" + saveLink + ")\n\n";
};
export default ControlsWaiter;

View file

@ -9,7 +9,7 @@
* @param {string} name - The name of the category.
* @param {boolean} selected - Whether this category is pre-selected or not.
*/
var HTMLCategory = module.exports = function(name, selected) {
var HTMLCategory = function(name, selected) {
this.name = name;
this.selected = selected;
this.opList = [];
@ -48,3 +48,5 @@ HTMLCategory.prototype.toHtml = function() {
html += "</ul></div></div>";
return html;
};
export default HTMLCategory;

View file

@ -7,10 +7,10 @@
*
* @constructor
* @param {Object} config - The configuration object for this ingredient.
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
* @param {Manager} manager - The CyberChef event manager.
*/
var HTMLIngredient = module.exports = function(config, app, manager) {
var HTMLIngredient = function(config, app, manager) {
this.app = app;
this.manager = manager;
@ -210,3 +210,5 @@ HTMLIngredient.prototype.editableOptionChange = function(e) {
this.manager.recipe.ingChange();
};
export default HTMLIngredient;

View file

@ -1,4 +1,4 @@
var HTMLIngredient = require("./HTMLIngredient.js");
import HTMLIngredient from "./HTMLIngredient.js";
/**
@ -11,10 +11,10 @@ var HTMLIngredient = require("./HTMLIngredient.js");
* @constructor
* @param {string} name - The name of the operation.
* @param {Object} config - The configuration object for this operation.
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
* @param {Manager} manager - The CyberChef event manager.
*/
var HTMLOperation = module.exports = function(name, config, app, manager) {
var HTMLOperation = function(name, config, app, manager) {
this.app = app;
this.manager = manager;
@ -115,3 +115,5 @@ HTMLOperation.prototype.highlightSearchString = function(searchStr, namePos, des
this.description.slice(descPos + searchStr.length);
}
};
export default HTMLOperation;

View file

@ -1,4 +1,4 @@
var Utils = require("../core/Utils.js");
import Utils from "../core/Utils.js";
/**
@ -9,9 +9,9 @@ var Utils = require("../core/Utils.js");
* @license Apache-2.0
*
* @constructor
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
*/
var HighlighterWaiter = module.exports = function(app) {
var HighlighterWaiter = function(app) {
this.app = app;
this.mouseButtonDown = false;
@ -507,3 +507,5 @@ HighlighterWaiter.prototype.highlight = function(textarea, highlighter, pos) {
highlighter.scrollTop = textarea.scrollTop;
highlighter.scrollLeft = textarea.scrollLeft;
};
export default HighlighterWaiter;

View file

@ -1,4 +1,4 @@
var Utils = require("../core/Utils.js");
import Utils from "../core/Utils.js";
/**
@ -9,10 +9,10 @@ var Utils = require("../core/Utils.js");
* @license Apache-2.0
*
* @constructor
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
* @param {Manager} manager - The CyberChef event manager.
*/
var InputWaiter = module.exports = function(app, manager) {
var InputWaiter = function(app, manager) {
this.app = app;
this.manager = manager;
@ -218,3 +218,5 @@ InputWaiter.prototype.clearIoClick = function() {
document.getElementById("output-selection-info").innerHTML = "";
window.dispatchEvent(this.manager.statechange);
};
export default InputWaiter;

View file

@ -1,12 +1,12 @@
var WindowWaiter = require("./WindowWaiter.js"),
ControlsWaiter = require("./ControlsWaiter.js"),
RecipeWaiter = require("./RecipeWaiter.js"),
OperationsWaiter = require("./OperationsWaiter.js"),
InputWaiter = require("./InputWaiter.js"),
OutputWaiter = require("./OutputWaiter.js"),
OptionsWaiter = require("./OptionsWaiter.js"),
HighlighterWaiter = require("./HighlighterWaiter.js"),
SeasonalWaiter = require("./SeasonalWaiter.js");
import WindowWaiter from "./WindowWaiter.js";
import ControlsWaiter from "./ControlsWaiter.js";
import RecipeWaiter from "./RecipeWaiter.js";
import OperationsWaiter from "./OperationsWaiter.js";
import InputWaiter from "./InputWaiter.js";
import OutputWaiter from "./OutputWaiter.js";
import OptionsWaiter from "./OptionsWaiter.js";
import HighlighterWaiter from "./HighlighterWaiter.js";
import SeasonalWaiter from "./SeasonalWaiter.js";
/**
@ -17,9 +17,9 @@ var WindowWaiter = require("./WindowWaiter.js"),
* @license Apache-2.0
*
* @constructor
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
*/
var Manager = module.exports = function(app) {
var Manager = function(app) {
this.app = app;
// Define custom events
@ -274,3 +274,5 @@ Manager.prototype.dynamicListenerHandler = function(e) {
}
}
};
export default Manager;

View file

@ -1,5 +1,5 @@
var HTMLOperation = require("./HTMLOperation.js"),
Sortable = require("sortablejs");
import HTMLOperation from "./HTMLOperation.js";
import Sortable from "sortablejs";
/**
@ -10,10 +10,10 @@ var HTMLOperation = require("./HTMLOperation.js"),
* @license Apache-2.0
*
* @constructor
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
* @param {Manager} manager - The CyberChef event manager.
*/
var OperationsWaiter = module.exports = function(app, manager) {
var OperationsWaiter = function(app, manager) {
this.app = app;
this.manager = manager;
@ -283,3 +283,5 @@ OperationsWaiter.prototype.opIconMouseleave = function(e) {
$(opEl).popover("show");
}
};
export default OperationsWaiter;

View file

@ -6,9 +6,9 @@
* @license Apache-2.0
*
* @constructor
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
*/
var OptionsWaiter = module.exports = function(app) {
var OptionsWaiter = function(app) {
this.app = app;
};
@ -130,3 +130,5 @@ OptionsWaiter.prototype.setWordWrap = function() {
document.getElementById("output-highlighter").classList.add("word-wrap");
}
};
export default OptionsWaiter;

View file

@ -1,4 +1,4 @@
var Utils = require("../core/Utils.js");
import Utils from "../core/Utils.js";
/**
@ -9,10 +9,10 @@ var Utils = require("../core/Utils.js");
* @license Apache-2.0
*
* @constructor
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
* @param {Manager} manager - The CyberChef event manager.
*/
var OutputWaiter = module.exports = function(app, manager) {
var OutputWaiter = function(app, manager) {
this.app = app;
this.manager = manager;
};
@ -189,3 +189,5 @@ OutputWaiter.prototype.maximiseOutputClick = function(e) {
this.app.resetLayout();
}
};
export default OutputWaiter;

View file

@ -1,5 +1,5 @@
var HTMLOperation = require("./HTMLOperation.js"),
Sortable = require("sortablejs");
import HTMLOperation from "./HTMLOperation.js";
import Sortable from "sortablejs";
/**
@ -10,10 +10,10 @@ var HTMLOperation = require("./HTMLOperation.js"),
* @license Apache-2.0
*
* @constructor
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
* @param {Manager} manager - The CyberChef event manager.
*/
var RecipeWaiter = module.exports = function(app, manager) {
var RecipeWaiter = function(app, manager) {
this.app = app;
this.manager = manager;
this.removeIntent = false;
@ -424,3 +424,5 @@ RecipeWaiter.prototype.opAdd = function(e) {
RecipeWaiter.prototype.opRemove = function(e) {
window.dispatchEvent(this.manager.statechange);
};
export default RecipeWaiter;

View file

@ -6,10 +6,10 @@
* @license Apache-2.0
*
* @constructor
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
* @param {Manager} manager - The CyberChef event manager.
*/
var SeasonalWaiter = module.exports = function(app, manager) {
var SeasonalWaiter = function(app, manager) {
this.app = app;
this.manager = manager;
};
@ -150,3 +150,5 @@ SeasonalWaiter.treeWalk = (function() {
}
};
})();
export default SeasonalWaiter;

View file

@ -6,9 +6,9 @@
* @license Apache-2.0
*
* @constructor
* @param {HTMLApp} app - The main view object for CyberChef.
* @param {App} app - The main view object for CyberChef.
*/
var WindowWaiter = module.exports = function(app) {
var WindowWaiter = function(app) {
this.app = app;
};
@ -50,3 +50,5 @@ WindowWaiter.prototype.windowFocus = function() {
this.app.silentBake();
}
};
export default WindowWaiter;

View file

@ -6,13 +6,13 @@
* @license Apache-2.0
*/
require("google-code-prettify/src/prettify.css");
import "google-code-prettify/src/prettify.css";
require("./lib/bootstrap.less");
require("bootstrap-switch/src/less/bootstrap3/build.less");
require("bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css");
import "./lib/bootstrap.less";
import "bootstrap-switch/src/less/bootstrap3/build.less";
import "bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css";
require("./structure/overrides.css");
require("./structure/layout.css");
require("./structure/utils.css");
require("./themes/classic.css");
import "./structure/overrides.css";
import "./structure/layout.css";
import "./structure/utils.css";
import "./themes/classic.css";

View file

@ -45,7 +45,7 @@
@import "~bootstrap/less/panels.less";
// @import "~bootstrap/less/responsive-embed.less";
// @import "~bootstrap/less/wells.less";
// @import "~bootstrap/less/close.less";
@import "~bootstrap/less/close.less";
// Components w/ JavaScript
@import "~bootstrap/less/modals.less";

View file

@ -4,10 +4,10 @@
* @license Apache-2.0
*/
var HTMLApp = require("./HTMLApp.js"),
Categories = require("../core/config/Categories.js"),
OperationConfig = require("../core/config/OperationConfig.js"),
CanvasComponents = require("../core/lib/canvascomponents.js");
import App from "./App.js";
import Categories from "../core/config/Categories.js";
import OperationConfig from "../core/config/OperationConfig.js";
import CanvasComponents from "../core/lib/canvascomponents.js";
/**
* Main function used to build the CyberChef web app.
@ -38,7 +38,7 @@ var main = function() {
};
document.removeEventListener("DOMContentLoaded", main, false);
window.app = new HTMLApp(Categories, OperationConfig, defaultFavourites, defaultOptions);
window.app = new App(Categories, OperationConfig, defaultFavourites, defaultOptions);
window.app.setup();
};