Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer const 1 of 5 #127

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/core/operations/Code.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ const Code = {
* @returns {string}
*/
_replaceVariableNames(input, replacer) {
let tokenRegex = /\\"|"(?:\\"|[^"])*"|(\b[a-z0-9\-_]+\b)/ig;
const tokenRegex = /\\"|"(?:\\"|[^"])*"|(\b[a-z0-9\-_]+\b)/ig;

return input.replace(tokenRegex, (...args) => {
let match = args[0],
Expand All @@ -450,7 +450,7 @@ const Code = {
*
*/
runToSnakeCase(input, args) {
let smart = args[0];
const smart = args[0];

if (smart) {
return Code._replaceVariableNames(input, snakeCase);
Expand All @@ -469,7 +469,7 @@ const Code = {
*
*/
runToCamelCase(input, args) {
let smart = args[0];
const smart = args[0];

if (smart) {
return Code._replaceVariableNames(input, camelCase);
Expand All @@ -488,7 +488,7 @@ const Code = {
*
*/
runToKebabCase(input, args) {
let smart = args[0];
const smart = args[0];

if (smart) {
return Code._replaceVariableNames(input, kebabCase);
Expand Down
7 changes: 1 addition & 6 deletions src/core/operations/Entropy.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,12 @@ const Entropy = {
runFreqDistrib: function (input, args) {
if (!input.length) return "No data";

let distrib = new Array(256),
let distrib = new Array(256).fill(0),
percentages = new Array(256),
len = input.length,
showZeroes = args[0],
i;

// Initialise distrib to 0
for (i = 0; i < 256; i++) {
distrib[i] = 0;
}

// Count bytes
for (i = 0; i < len; i++) {
distrib[input[i]]++;
Expand Down
6 changes: 1 addition & 5 deletions src/core/operations/IP.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,9 @@ const IP = {
ip2 = IP._strToIpv6(range[14]);

let t = "",
total = new Array(128),
total = new Array(128).fill(),
i;

// Initialise total array to "0"
for (i = 0; i < 128; i++)
total[i] = "0";

for (i = 0; i < 8; i++) {
t = (ip2[i] - ip1[i]).toString(2);
if (t !== "0") {
Expand Down
8 changes: 3 additions & 5 deletions src/core/operations/StrUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,7 @@ const StrUtils = {
}

// Initialise output strings
for (s = 0; s < samples.length; s++) {
outputs[s] = "";
}
outputs.fill("", 0, samples.length);

// Loop through each character in the first sample
for (i = 0; i < samples[0].length; i++) {
Expand Down Expand Up @@ -473,7 +471,7 @@ const StrUtils = {
number = args[1];

delimiter = Utils.charRep[delimiter];
let splitInput = input.split(delimiter);
const splitInput = input.split(delimiter);

return splitInput
.filter((line, lineIndex) => {
Expand Down Expand Up @@ -501,7 +499,7 @@ const StrUtils = {
number = args[1];

delimiter = Utils.charRep[delimiter];
let splitInput = input.split(delimiter);
const splitInput = input.split(delimiter);

return splitInput
.filter((line, lineIndex) => {
Expand Down
90 changes: 45 additions & 45 deletions src/web/ControlsWaiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const ControlsWaiter = function(app, manager) {
* without wrapping or overflowing.
*/
ControlsWaiter.prototype.adjustWidth = function() {
let controls = document.getElementById("controls"),
step = document.getElementById("step"),
clrBreaks = document.getElementById("clr-breaks"),
saveImg = document.querySelector("#save img"),
loadImg = document.querySelector("#load img"),
stepImg = document.querySelector("#step img"),
clrRecipImg = document.querySelector("#clr-recipe img"),
clrBreaksImg = document.querySelector("#clr-breaks img");
const controls = document.getElementById("controls");
const step = document.getElementById("step");
const clrBreaks = document.getElementById("clr-breaks");
const saveImg = document.querySelector("#save img");
const loadImg = document.querySelector("#load img");
const stepImg = document.querySelector("#step img");
const clrRecipImg = document.querySelector("#clr-recipe img");
const clrBreaksImg = document.querySelector("#clr-breaks img");

if (controls.clientWidth < 470) {
step.childNodes[1].nodeValue = " Step";
Expand Down Expand Up @@ -100,8 +100,8 @@ ControlsWaiter.prototype.stepClick = function() {
* Handler for changes made to the Auto Bake checkbox.
*/
ControlsWaiter.prototype.autoBakeChange = function() {
let autoBakeLabel = document.getElementById("auto-bake-label"),
autoBakeCheckbox = document.getElementById("auto-bake");
const autoBakeLabel = document.getElementById("auto-bake-label");
const autoBakeCheckbox = document.getElementById("auto-bake");

this.app.autoBake_ = autoBakeCheckbox.checked;

Expand Down Expand Up @@ -145,10 +145,10 @@ ControlsWaiter.prototype.clearBreaksClick = function() {
ControlsWaiter.prototype.initialiseSaveLink = function(recipeConfig) {
recipeConfig = recipeConfig || this.app.getRecipeConfig();

let includeRecipe = document.getElementById("save-link-recipe-checkbox").checked,
includeInput = document.getElementById("save-link-input-checkbox").checked,
saveLinkEl = document.getElementById("save-link"),
saveLink = this.generateStateUrl(includeRecipe, includeInput, recipeConfig);
const includeRecipe = document.getElementById("save-link-recipe-checkbox").checked;
const includeInput = document.getElementById("save-link-input-checkbox").checked;
const saveLinkEl = document.getElementById("save-link");
const saveLink = this.generateStateUrl(includeRecipe, includeInput, recipeConfig);

saveLinkEl.innerHTML = Utils.truncate(saveLink, 120);
saveLinkEl.setAttribute("href", saveLink);
Expand All @@ -167,23 +167,27 @@ ControlsWaiter.prototype.initialiseSaveLink = function(recipeConfig) {
ControlsWaiter.prototype.generateStateUrl = function(includeRecipe, includeInput, recipeConfig, baseURL) {
recipeConfig = recipeConfig || this.app.getRecipeConfig();

let link = baseURL || window.location.protocol + "//" +
const link = baseURL || window.location.protocol + "//" +
window.location.host +
window.location.pathname,
recipeStr = JSON.stringify(recipeConfig),
inputStr = Utils.toBase64(this.app.getInput(), "A-Za-z0-9+/"); // B64 alphabet with no padding
window.location.pathname;
const recipeStr = JSON.stringify(recipeConfig);
const inputStr = Utils.toBase64(this.app.getInput(), "A-Za-z0-9+/"); // B64 alphabet with no padding

includeRecipe = includeRecipe && (recipeConfig.length > 0);
includeInput = includeInput && (inputStr.length > 0) && (inputStr.length < 8000);
const myIncludeRecipe = includeRecipe && (recipeConfig.length > 0);
const myIncludeInput = includeInput && (inputStr.length > 0) && (inputStr.length < 8000);

if (includeRecipe) {
link += "?recipe=" + encodeURIComponent(recipeStr);
}
const params = [
myIncludeRecipe ? ["recipe", recipeStr] : undefined,
myIncludeInput ? ["input", inputStr] : undefined,
];

if (includeRecipe && includeInput) {
link += "&input=" + encodeURIComponent(inputStr);
} else if (includeInput) {
link += "?input=" + encodeURIComponent(inputStr);
const query = params
.filter(v => v)
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
.join("&");

if (query) {
return `${link}?${query}`;
}

return link;
Expand All @@ -205,8 +209,8 @@ ControlsWaiter.prototype.saveTextChange = function() {
* Handler for the 'Save' command. Pops up the save dialog box.
*/
ControlsWaiter.prototype.saveClick = function() {
let recipeConfig = this.app.getRecipeConfig(),
recipeStr = JSON.stringify(recipeConfig).replace(/},{/g, "},\n{");
const recipeConfig = this.app.getRecipeConfig();
const recipeStr = JSON.stringify(recipeConfig).replace(/},{/g, "},\n{");

document.getElementById("save-text").value = recipeStr;

Expand Down Expand Up @@ -244,8 +248,8 @@ ControlsWaiter.prototype.loadClick = function() {
* Saves the recipe specified in the save textarea to local storage.
*/
ControlsWaiter.prototype.saveButtonClick = function() {
let recipeName = Utils.escapeHtml(document.getElementById("save-name").value);
let recipeStr = document.getElementById("save-text").value;
const recipeName = Utils.escapeHtml(document.getElementById("save-name").value);
const recipeStr = document.getElementById("save-text").value;

if (!recipeName) {
this.app.alert("Please enter a recipe name", "danger", 2000);
Expand Down Expand Up @@ -303,13 +307,11 @@ ControlsWaiter.prototype.populateLoadRecipesList = function() {
* Removes the currently selected recipe from local storage.
*/
ControlsWaiter.prototype.loadDeleteClick = function() {
let id = parseInt(document.getElementById("load-name").value, 10),
savedRecipes = localStorage.savedRecipes ?
const id = parseInt(document.getElementById("load-name").value, 10);
const rawSavedRecipes = localStorage.savedRecipes ?
JSON.parse(localStorage.savedRecipes) : [];

savedRecipes = savedRecipes.filter(function(r) {
return r.id !== id;
});
const savedRecipes = rawSavedRecipes.filter(r => r.id !== id);

localStorage.savedRecipes = JSON.stringify(savedRecipes);
this.populateLoadRecipesList();
Expand All @@ -320,14 +322,12 @@ ControlsWaiter.prototype.loadDeleteClick = function() {
* Displays the selected recipe in the load text box.
*/
ControlsWaiter.prototype.loadNameChange = function(e) {
let el = e.target,
savedRecipes = localStorage.savedRecipes ?
JSON.parse(localStorage.savedRecipes) : [],
id = parseInt(el.value, 10);
const el = e.target;
const savedRecipes = localStorage.savedRecipes ?
JSON.parse(localStorage.savedRecipes) : [];
const id = parseInt(el.value, 10);

const recipe = savedRecipes.filter(function(r) {
return r.id === id;
})[0];
const recipe = savedRecipes.find(r => r.id === id);

document.getElementById("load-text").value = recipe.recipe;
};
Expand All @@ -352,8 +352,8 @@ ControlsWaiter.prototype.loadButtonClick = function() {
* Populates the bug report information box with useful technical info.
*/
ControlsWaiter.prototype.supportButtonClick = function() {
let reportBugInfo = document.getElementById("report-bug-info"),
saveLink = this.generateStateUrl(true, true, null, "https://gchq.github.io/CyberChef/");
const reportBugInfo = document.getElementById("report-bug-info");
const saveLink = this.generateStateUrl(true, true, null, "https://gchq.github.io/CyberChef/");

reportBugInfo.innerHTML = "* CyberChef compile time: " + COMPILE_TIME + "\n" +
"* User-Agent: \n" + navigator.userAgent + "\n" +
Expand Down
15 changes: 7 additions & 8 deletions src/web/HTMLIngredient.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,12 @@ HTMLIngredient.prototype.toHtml = function() {
* @param {event} e
*/
HTMLIngredient.prototype.toggleDisableArgs = function(e) {
let el = e.target,
op = el.parentNode.parentNode,
args = op.querySelectorAll(".arg-group"),
els;
const el = e.target;
const op = el.parentNode.parentNode;
const args = op.querySelectorAll(".arg-group");

for (let i = 0; i < this.disableArgs.length; i++) {
els = args[this.disableArgs[i]].querySelectorAll("input, select, button");
const els = args[this.disableArgs[i]].querySelectorAll("input, select, button");

for (let j = 0; j < els.length; j++) {
if (els[j].getAttribute("disabled")) {
Expand All @@ -186,9 +185,9 @@ HTMLIngredient.prototype.toggleDisableArgs = function(e) {
* @param {event} e
*/
HTMLIngredient.prototype.populateOptionChange = function(e) {
let el = e.target,
op = el.parentNode.parentNode,
target = op.querySelectorAll(".arg-group")[this.target].querySelector("input, select, textarea");
const el = e.target;
const op = el.parentNode.parentNode;
const target = op.querySelectorAll(".arg-group")[this.target].querySelector("input, select, textarea");

target.value = el.childNodes[el.selectedIndex].getAttribute("populate-value");

Expand Down
Loading