Replaced jsHint with eslint. Fixes #4.

This commit is contained in:
n1474335 2016-12-14 16:39:17 +00:00
parent e2e68dd876
commit af4644c9eb
48 changed files with 1741 additions and 1685 deletions

View file

@ -26,7 +26,7 @@ var ByteRepr = {
* @default
*/
BIN_DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "None"],
/**
* To Hex operation.
*
@ -38,8 +38,8 @@ var ByteRepr = {
var delim = Utils.char_rep[args[0] || "Space"];
return Utils.to_hex(input, delim, 2);
},
/**
* From Hex operation.
*
@ -51,14 +51,14 @@ var ByteRepr = {
var delim = args[0] || "Space";
return Utils.from_hex(input, delim, 2);
},
/**
* @constant
* @default
*/
CHARCODE_BASE: 16,
/**
* To Charcode operation.
*
@ -72,34 +72,34 @@ var ByteRepr = {
output = "",
padding = 2,
ordinal;
if (base < 2 || base > 36) {
throw "Error: Base argument must be between 2 and 36";
}
for (var i = 0; i < input.length; i++) {
ordinal = Utils.ord(input[i]);
if (base == 16) {
if (base === 16) {
if (ordinal < 256) padding = 2;
else if (ordinal < 65536) padding = 4;
else if (ordinal < 16777216) padding = 6;
else if (ordinal < 4294967296) padding = 8;
else padding = 2;
if (padding > 2) app.options.attempt_highlight = false;
output += Utils.hex(ordinal, padding) + delim;
} else {
app.options.attempt_highlight = false;
output += ordinal.toString(base) + delim;
}
}
return output.slice(0, -delim.length);
},
/**
* From Charcode operation.
*
@ -112,32 +112,32 @@ var ByteRepr = {
base = args[1],
bites = input.split(delim),
i = 0;
if (base < 2 || base > 36) {
throw "Error: Base argument must be between 2 and 36";
}
if (base != 16) {
if (base !== 16) {
app.options.attempt_highlight = false;
}
// Split into groups of 2 if the whole string is concatenated and
// Split into groups of 2 if the whole string is concatenated and
// too long to be a single character
if (bites.length == 1 && input.length > 17) {
if (bites.length === 1 && input.length > 17) {
bites = [];
for (i = 0; i < input.length; i += 2) {
bites.push(input.slice(i, i+2));
}
}
var latin1 = "";
for (i = 0; i < bites.length; i++) {
latin1 += Utils.chr(parseInt(bites[i], base));
}
return Utils.str_to_byte_array(latin1);
},
/**
* Highlight to hex
*
@ -149,20 +149,20 @@ var ByteRepr = {
*/
highlight_to: function(pos, args) {
var delim = Utils.char_rep[args[0] || "Space"],
len = delim == "\r\n" ? 1 : delim.length;
len = delim === "\r\n" ? 1 : delim.length;
pos[0].start = pos[0].start * (2 + len);
pos[0].end = pos[0].end * (2 + len) - len;
// 0x and \x are added to the beginning if they are selected, so increment the positions accordingly
if (delim == "0x" || delim == "\\x") {
if (delim === "0x" || delim === "\\x") {
pos[0].start += 2;
pos[0].end += 2;
}
return pos;
},
/**
* Highlight to hex
*
@ -174,23 +174,23 @@ var ByteRepr = {
*/
highlight_from: function(pos, args) {
var delim = Utils.char_rep[args[0] || "Space"],
len = delim == "\r\n" ? 1 : delim.length,
len = delim === "\r\n" ? 1 : delim.length,
width = len + 2;
// 0x and \x are added to the beginning if they are selected, so increment the positions accordingly
if (delim == "0x" || delim == "\\x") {
if (delim === "0x" || delim === "\\x") {
if (pos[0].start > 1) pos[0].start -= 2;
else pos[0].start = 0;
if (pos[0].end > 1) pos[0].end -= 2;
else pos[0].end = 0;
}
pos[0].start = pos[0].start === 0 ? 0 : Math.round(pos[0].start / width);
pos[0].end = pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / width);
return pos;
},
/**
* To Decimal operation.
*
@ -202,8 +202,8 @@ var ByteRepr = {
var delim = Utils.char_rep[args[0]];
return input.join(delim);
},
/**
* From Decimal operation.
*
@ -216,14 +216,14 @@ var ByteRepr = {
var byte_str = input.split(delim), output = [];
if (byte_str[byte_str.length-1] === "")
byte_str = byte_str.slice(0, byte_str.length-1);
for (var i = 0; i < byte_str.length; i++) {
output[i] = parseInt(byte_str[i]);
output[i] = parseInt(byte_str[i], 10);
}
return output;
},
/**
* To Binary operation.
*
@ -235,19 +235,19 @@ var ByteRepr = {
var delim = Utils.char_rep[args[0] || "Space"],
output = "",
padding = 8;
for (var i = 0; i < input.length; i++) {
output += Utils.pad(input[i].toString(2), padding) + delim;
}
if (delim.length) {
return output.slice(0, -delim.length);
} else {
return output;
}
},
/**
* From Binary operation.
*
@ -256,11 +256,11 @@ var ByteRepr = {
* @returns {byte_array}
*/
run_from_binary: function(input, args) {
if (args[0] != "None") {
if (args[0] !== "None") {
var delim_regex = Utils.regex_rep[args[0] || "Space"];
input = input.replace(delim_regex, '');
input = input.replace(delim_regex, "");
}
var output = [];
var byte_len = 8;
for (var i = 0; i < input.length; i += byte_len) {
@ -268,8 +268,8 @@ var ByteRepr = {
}
return output;
},
/**
* Highlight to binary
*
@ -285,8 +285,8 @@ var ByteRepr = {
pos[0].end = pos[0].end * (8 + delim.length) - delim.length;
return pos;
},
/**
* Highlight from binary
*
@ -302,8 +302,8 @@ var ByteRepr = {
pos[0].end = pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / (8 + delim.length));
return pos;
},
/**
* @constant
* @default
@ -314,7 +314,7 @@ var ByteRepr = {
* @default
*/
HEX_CONTENT_SPACES_BETWEEN_BYTES: false,
/**
* To Hex Content operation.
*
@ -325,19 +325,19 @@ var ByteRepr = {
run_to_hex_content: function(input, args) {
var convert = args[0];
var spaces = args[1];
if (convert == "All chars") {
if (convert === "All chars") {
var result = "|" + Utils.to_hex(input) + "|";
if (!spaces) result = result.replace(/ /g, "");
return result;
}
var output = "",
in_hex = false,
convert_spaces = convert == "Only special chars including spaces",
convert_spaces = convert === "Only special chars including spaces",
b;
for (var i = 0; i < input.length; i++) {
b = input[i];
if ((b == 32 && convert_spaces) || (b < 48 && b != 32) || (b > 57 && b < 65) || (b > 90 && b < 97) || b > 122) {
if ((b === 32 && convert_spaces) || (b < 48 && b !== 32) || (b > 57 && b < 65) || (b > 90 && b < 97) || b > 122) {
if (!in_hex) {
output += "|";
in_hex = true;
@ -354,8 +354,8 @@ var ByteRepr = {
if (in_hex) output += "|";
return output;
},
/**
* From Hex Content operation.
*
@ -366,11 +366,11 @@ var ByteRepr = {
run_from_hex_content: function(input, args) {
var regex = /\|([a-f\d ]{2,})\|/gi;
var output = [], m, i = 0;
while (!!(m = regex.exec(input))) {
while ((m = regex.exec(input))) {
// Add up to match
for (; i < m.index;)
output.push(Utils.ord(input[i++]));
// Add match
var bytes = Utils.from_hex(m[1]);
if (bytes) {
@ -381,13 +381,13 @@ var ByteRepr = {
for (; i < regex.lastIndex;)
output.push(Utils.ord(input[i++]));
}
i = regex.lastIndex;
}
// Add all after final match
for (; i < input.length;)
output.push(Utils.ord(input[i++]));
return output;
},