code: function(bytes) {
    var result = "";
    var i = 0;
    var wc;
    var c;
  
    while (i < bytes.length) {
      /* parse as UTF-8 lead byte */
      wc = bytes[i++];
      if (wc < 0x80) {
        count = 0;
      } else if (wc < 0xC2 || wc >= 0xF8) {
        throw new Error("input is not a valid UTF-8 lead octet");
      } else if (wc < 0xE0) {
        count = 1;
        wc = (wc & 0x1F) << 6;
      } else if (wc < 0xF0) {
        count = 2;
        wc = (wc & 0x0F) << 12;
      } else /* wc < 0xF8 */ {
        count = 3;
        wc = (wc & 0x07) << 18;
      }
  
      /* parse trail bytes, if any */
      while (count) {
        if (!(i < bytes.length)) {
          throw new Error("short read");
        }
        if ((c = bytes[i++] ^ 0x80) > 0x3F) {
          throw new Error("input is not a valid UTF-8 trail octet");
        }
        wc |= c << (6 * --count);
        if (wc < (1 << (5 * count + 6))) {
          throw new Error("invalid non-minimal encoded input");
        }
      }
  
      /* handle conversion to UTF-16 if needed */
      if (wc > 0xFFFF) {
        wc -= 0x10000;
        result += String.fromCharCode(0xD800 + (wc >> 10));
        wc = 0xDC00 + (wc & 0x3FF);
      }
      result += String.fromCharCode(wc);
    }
  
    return result;
  }
docs: /*
  Decode utf-8 byte sequence to string.