code: function UniArrayToUTF8(arr) {
      var count = 0;
  
      for (var ix=0; ix<arr.length; ix++) {
          var val = arr[ix];
          if (val < 0x80) {
              count += 1;
          }
          else if (val < 0x800) {
              count += 2;
          }
          else if (val < 0x10000) {
              count += 3;
          }
          else if (val < 0x200000) {
              count += 4;
          }
          else {
              count += 1;
          }
      }
  
      if (count == arr.length)
          return arr;
  
      var res = [];
      for (var ix=0; ix<arr.length; ix++) {
          var val = arr[ix];
          if (val < 0x80) {
              res.push(val);
          }
          else if (val < 0x800) {
              res.push(0xC0 | ((val & 0x7C0) >> 6));
              res.push(0x80 |  (val & 0x03F)     );
          }
          else if (val < 0x10000) {
              res.push(0xE0 | ((val & 0xF000) >> 12));
              res.push(0x80 | ((val & 0x0FC0) >>  6));
              res.push(0x80 |  (val & 0x003F)      );
          }
          else if (val < 0x200000) {
              res.push(0xF0 | ((val & 0x1C0000) >> 18));
              res.push(0x80 | ((val & 0x03F000) >> 12));
              res.push(0x80 | ((val & 0x000FC0) >>  6));
              res.push(0x80 |  (val & 0x00003F)      );
          }
          else {
              res.push(63);  // '?'
          }
      }
  
      return res;
  }
docs: /* Convert an array of 32-bit Unicode values to an array of 8-bit byte
  values, encoded UTF-8. If all the values are 0-127, this returns the
  same array. Otherwise it returns a new (longer) array.