Tidied up To Hex mods
This commit is contained in:
parent
3fb5bf14a6
commit
c2212f9ab3
@ -36,11 +36,8 @@ export function toHex(data, delim=" ", padding=2, extraDelim="", lineSize=0) {
|
|||||||
|
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
const hex = data[i].toString(16).padStart(padding, "0");
|
const hex = data[i].toString(16).padStart(padding, "0");
|
||||||
if (prepend) {
|
output += prepend ? delim + hex : hex + delim;
|
||||||
output += delim + hex;
|
|
||||||
} else {
|
|
||||||
output += hex + delim;
|
|
||||||
}
|
|
||||||
if (extraDelim) {
|
if (extraDelim) {
|
||||||
output += extraDelim;
|
output += extraDelim;
|
||||||
}
|
}
|
||||||
@ -50,7 +47,7 @@ export function toHex(data, delim=" ", padding=2, extraDelim="", lineSize=0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the extraDelim at the end (if there is);
|
// Remove the extraDelim at the end (if there is one)
|
||||||
// and remove the delim at the end, but if it's prepended there's nothing to remove
|
// and remove the delim at the end, but if it's prepended there's nothing to remove
|
||||||
const rTruncLen = extraDelim.length + (prepend ? 0 : delim.length);
|
const rTruncLen = extraDelim.length + (prepend ? 0 : delim.length);
|
||||||
if (rTruncLen) {
|
if (rTruncLen) {
|
||||||
@ -119,7 +116,7 @@ export function fromHex(data, delim="Auto", byteLen=2) {
|
|||||||
/**
|
/**
|
||||||
* To Hexadecimal delimiters.
|
* To Hexadecimal delimiters.
|
||||||
*/
|
*/
|
||||||
export const TO_HEX_DELIM_OPTIONS = ["Space", "Percent", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "\\x", "None"];
|
export const TO_HEX_DELIM_OPTIONS = ["Space", "Percent", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "0x with comma", "\\x", "None"];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
import {toHex} from "../lib/Hex.mjs";
|
import {toHex, TO_HEX_DELIM_OPTIONS} from "../lib/Hex.mjs";
|
||||||
import Utils from "../Utils.mjs";
|
import Utils from "../Utils.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +29,7 @@ class ToHex extends Operation {
|
|||||||
{
|
{
|
||||||
name: "Delimiter",
|
name: "Delimiter",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: ["Space", "Percent", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "0x with comma", "\\x", "None"]
|
value: TO_HEX_DELIM_OPTIONS
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Bytes per line",
|
name: "Bytes per line",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user