Browse Source

Updated to allow delimiter to be set

n1474335 8 years ago
parent
commit
5c774a3ce2
1 changed files with 6 additions and 4 deletions
  1. 6 4
      src/core/Utils.js

+ 6 - 4
src/core/Utils.js

@@ -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);
     },