Updated to allow delimiter to be set

This commit is contained in:
n1474335 2017-06-23 12:18:08 +00:00
parent a417a6469c
commit 5c774a3ce2
1 changed files with 6 additions and 4 deletions

View File

@ -366,19 +366,21 @@ const Utils = {
* Translates an array of bytes to a hex string.
*
* @param {byteArray} byteArray
* @param {string} [delim=" "]
* @returns {string}
*
* @example
* // returns "fe09a7"
* Utils.byteArrayToHex([0xfe, 0x09, 0xa7]);
* Utils.byteArrayToHex([0xfe, 0x09, 0xa7], "");
*/
byteArrayToHex: function(byteArray) {
byteArrayToHex: function(byteArray, delim) {
if (!byteArray) return "";
delim = typeof delim === "undefined" ? " " : delim;
let hexStr = "";
for (let i = 0; i < byteArray.length; i++) {
hexStr += Utils.hex(byteArray[i]) + " ";
hexStr += Utils.hex(byteArray[i]) + delim;
}
return hexStr.slice(0, hexStr.length-1);
return hexStr.slice(0, hexStr.length - delim.length);
},