code: function toUtf8Bytes(str, form) {
      if (form === void 0) { form = UnicodeNormalizationForm.current; }
      if (form != UnicodeNormalizationForm.current) {
          errors_1.checkNormalize();
          str = str.normalize(form);
      }
      var result = [];
      for (var i = 0; i < str.length; i++) {
          var c = str.charCodeAt(i);
          if (c < 0x80) {
              result.push(c);
          }
          else if (c < 0x800) {
              result.push((c >> 6) | 0xc0);
              result.push((c & 0x3f) | 0x80);
          }
          else if ((c & 0xfc00) == 0xd800) {
              i++;
              var c2 = str.charCodeAt(i);
              if (i >= str.length || (c2 & 0xfc00) !== 0xdc00) {
                  throw new Error('invalid utf-8 string');
              }
              // Surrogate Pair
              c = 0x10000 + ((c & 0x03ff) << 10) + (c2 & 0x03ff);
              result.push((c >> 18) | 0xf0);
              result.push(((c >> 12) & 0x3f) | 0x80);
              result.push(((c >> 6) & 0x3f) | 0x80);
              result.push((c & 0x3f) | 0x80);
          }
          else {
              result.push((c >> 12) | 0xe0);
              result.push(((c >> 6) & 0x3f) | 0x80);
              result.push((c & 0x3f) | 0x80);
          }
      }
      return bytes_1.arrayify(result);
  }
docs: http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array