From c2212f9ab36cb41672fb2f7946501d2532f4f424 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 13 Feb 2020 14:17:43 +0000 Subject: [PATCH] Tidied up To Hex mods --- src/core/lib/Hex.mjs | 11 ++++------- src/core/operations/ToHex.mjs | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 0108eabd..9c70e91c 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -36,11 +36,8 @@ export function toHex(data, delim=" ", padding=2, extraDelim="", lineSize=0) { for (let i = 0; i < data.length; i++) { const hex = data[i].toString(16).padStart(padding, "0"); - if (prepend) { - output += delim + hex; - } else { - output += hex + delim; - } + output += prepend ? delim + hex : hex + delim; + if (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 const rTruncLen = extraDelim.length + (prepend ? 0 : delim.length); if (rTruncLen) { @@ -119,7 +116,7 @@ export function fromHex(data, delim="Auto", byteLen=2) { /** * 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"]; /** diff --git a/src/core/operations/ToHex.mjs b/src/core/operations/ToHex.mjs index 25d4e059..2e97de8f 100644 --- a/src/core/operations/ToHex.mjs +++ b/src/core/operations/ToHex.mjs @@ -5,7 +5,7 @@ */ 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"; /** @@ -29,7 +29,7 @@ class ToHex extends Operation { { name: "Delimiter", 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",