Removed padLeft and padRight in favour of String.prototype.padStart and padEnd. 'To Hex' now supports ArrayBuffers.

This commit is contained in:
n1474335 2017-12-28 14:38:57 +00:00
parent e18ec5f2b2
commit 849d41ee56
15 changed files with 77 additions and 104 deletions

View file

@ -134,11 +134,11 @@ const BCD = {
switch (outputFormat) {
case "Nibbles":
return nibbles.map(n => {
return Utils.padLeft(n.toString(2), 4);
return n.toString(2).padStart(4, "0");
}).join(" ");
case "Bytes":
return bytes.map(b => {
return Utils.padLeft(b.toString(2), 8);
return b.toString(2).padStart(8, "0");
}).join(" ");
case "Raw":
default:

View file

@ -31,13 +31,13 @@ const ByteRepr = {
/**
* To Hex operation.
*
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
runToHex: function(input, args) {
const delim = Utils.charRep[args[0] || "Space"];
return Utils.toHex(input, delim, 2);
return Utils.toHex(new Uint8Array(input), delim, 2);
},
@ -266,7 +266,7 @@ const ByteRepr = {
padding = 8;
for (let i = 0; i < input.length; i++) {
output += Utils.pad(input[i].toString(2), padding) + delim;
output += input[i].toString(2).padStart(padding, "0") + delim;
}
if (delim.length) {

View file

@ -418,9 +418,9 @@ const Compress = {
}
};
const fileSize = Utils.padLeft(input.length.toString(8), 11, "0");
const fileSize = input.length.toString(8).padStart(11, "0");
const currentUnixTimestamp = Math.floor(Date.now() / 1000);
const lastModTime = Utils.padLeft(currentUnixTimestamp.toString(8), 11, "0");
const lastModTime = currentUnixTimestamp.toString(8).padStart(11, "0");
const file = {
fileName: Utils.padBytesRight(args[0], 100),
@ -452,7 +452,7 @@ const Compress = {
}
});
}
checksum = Utils.padBytesRight(Utils.padLeft(checksum.toString(8), 7, "0"), 8);
checksum = Utils.padBytesRight(checksum.toString(8).padStart(7, "0"), 8);
file.checksum = checksum;
const tarball = new Tarball();

View file

@ -127,7 +127,7 @@ const Entropy = {
for (i = 0; i < 256; i++) {
if (distrib[i] || showZeroes) {
output += " " + Utils.hex(i, 2) + " (" +
Utils.padRight(percentages[i].toFixed(2).replace(".00", "") + "%)", 8) +
(percentages[i].toFixed(2).replace(".00", "") + "%)").padEnd(8, " ") +
Array(Math.ceil(percentages[i])+1).join("|") + "\n";
}
}

View file

@ -215,9 +215,9 @@ const HTML = {
k = k.toFixed(2);
let hex = "#" +
Utils.padLeft(Math.round(r).toString(16), 2) +
Utils.padLeft(Math.round(g).toString(16), 2) +
Utils.padLeft(Math.round(b).toString(16), 2),
Math.round(r).toString(16).padStart(2, "0") +
Math.round(g).toString(16).padStart(2, "0") +
Math.round(b).toString(16).padStart(2, "0"),
rgb = "rgb(" + r + ", " + g + ", " + b + ")",
rgba = "rgba(" + r + ", " + g + ", " + b + ", " + a + ")",
hsl = "hsl(" + h + ", " + s + "%, " + l + "%)",

View file

@ -56,8 +56,8 @@ const Hexdump = {
}
output += lineNo + " " +
Utils.padRight(hexa, (length*(padding+1))) +
" |" + Utils.padRight(Utils.printable(Utils.byteArrayToChars(buff)), buff.length) + "|\n";
hexa.padEnd(length*(padding+1), " ") +
" |" + Utils.printable(Utils.byteArrayToChars(buff)).padEnd(buff.length, " ") + "|\n";
if (includeFinalLength && i+buff.length === input.length) {
output += Utils.hex(i+buff.length, 8) + "\n";

View file

@ -121,8 +121,7 @@ const PublicKey = {
// Format Public Key fields
for (let i = 0; i < pkFields.length; i++) {
pkStr += " " + pkFields[i].key + ":" +
Utils.padLeft(
pkFields[i].value + "\n",
(pkFields[i].value + "\n").padStart(
18 - (pkFields[i].key.length + 3) + pkFields[i].value.length + 1,
" "
);
@ -286,9 +285,9 @@ ${extensions}`;
key = fields[i].split("=")[0];
value = fields[i].split("=")[1];
str = Utils.padRight(key, maxKeyLen) + " = " + value + "\n";
str = key.padEnd(maxKeyLen, " ") + " = " + value + "\n";
output += Utils.padLeft(str, indent + str.length, " ");
output += str.padStart(indent + str.length, " ");
}
return output.slice(0, -1);
@ -314,7 +313,7 @@ ${extensions}`;
if (i === 0) {
output += str;
} else {
output += Utils.padLeft(str, indent + str.length, " ");
output += str.padStart(indent + str.length, " ");
}
}

View file

@ -158,7 +158,7 @@ const SeqUtils = {
width = lines.length.toString().length;
for (let n = 0; n < lines.length; n++) {
output += Utils.pad((n+1).toString(), width, " ") + " " + lines[n] + "\n";
output += (n+1).toString().padStart(width, " ") + " " + lines[n] + "\n";
}
return output.slice(0, output.length-1);
},

View file

@ -1,6 +1,3 @@
import Utils from "../Utils.js";
/**
* Tidy operations.
*
@ -229,11 +226,11 @@ const Tidy = {
if (position === "Start") {
for (i = 0; i < lines.length; i++) {
output += Utils.padLeft(lines[i], lines[i].length+len, chr) + "\n";
output += lines[i].padStart(lines[i].length+len, chr) + "\n";
}
} else if (position === "End") {
for (i = 0; i < lines.length; i++) {
output += Utils.padRight(lines[i], lines[i].length+len, chr) + "\n";
output += lines[i].padEnd(lines[i].length+len, chr) + "\n";
}
}

View file

@ -1,5 +1,4 @@
/* globals unescape */
import Utils from "../Utils.js";
import url from "url";
@ -78,7 +77,7 @@ const URL_ = {
output += "Arguments:\n";
for (let key in uri.query) {
output += "\t" + Utils.padRight(key, padding);
output += "\t" + key.padEnd(padding, " ");
if (uri.query[key].length) {
output += " = " + uri.query[key] + "\n";
} else {