code: function pack(str, buffer, index=0) {
    for (let i = 0, len = str.length; i < len; i++) {
      /** @type {number} */
      let codePoint = str.codePointAt(i);
      if (codePoint < 128) {
        buffer[index] = codePoint;
        index++;
      } else {
        /** @type {number} */
        let count = 0;
        /** @type {number} */
        let offset = 0;
        if (codePoint <= 0x07FF) {
          count = 1;
          offset = 0xC0;
        } else if(codePoint <= 0xFFFF) {
          count = 2;
          offset = 0xE0;
        } else if(codePoint <= 0x10FFFF) {
          count = 3;
          offset = 0xF0;
          i++;
        }
        buffer[index] = (codePoint >> (6 * count)) + offset;
        index++;
        while (count > 0) {
          buffer[index] = 0x80 | (codePoint >> (6 * (count - 1)) & 0x3F);
          index++;
          count--;
        }
      }
    }
    return index;
  }
docs: Write a string of UTF-8 characters to a byte buffer.
  @see https://encoding.spec.whatwg.org/#utf-8-encoder
  @param {string} str The string to pack.
  @param {!Uint8Array|!Array<number>} buffer The buffer to pack the string to.
  @param {number=} index The buffer index to start writing.
  @return {number} The next index to write in the buffer.