demo/full/scripts/lib/bytes.js
/**
 * Convert a string to an Uint8Array containing the corresponding UTF-16 code
 * units in little-endian.
 * @param {string} str
 * @returns {Uint8Array}
 */
Convert a string to an Uint8Array containing the corresponding UTF-16 code
units in little-endian.
@param {string} str
@returns {Uint8Array}
Convert a string to an Uint8Array containing the corresponding UTF - 16 code units in little - endian . @param { string } str @returns { Uint8Array }
function strToLeUtf16(str) {
  const buffer = new ArrayBuffer(str.length * 2);
  const res = new Uint8Array(buffer);
  for (let i = 0; i < res.length; i += 2) {
    const value = str.charCodeAt(i / 2);
    res[i] = value & 0xFF;
    res[i + 1] = value >> 8 & 0xFF;
  }
  return res;
}
function strToLeUtf16 ( str ) { const buffer = new ArrayBuffer ( str . length * 2 ) ; const res = new Uint8Array ( buffer ) ; for ( let i = 0 ; i < res . length ; i += 2 ) { const value = str . charCodeAt ( i / 2 ) ; res [ i ] = value & 0xFF ; res [ i + 1 ] = value >> 8 & 0xFF ; } return res ; }
Convert a string to an Uint8Array containing the corresponding UTF-16 code
 units in little-endian.
Convert a string to an Uint8Array containing the corresponding UTF - 16 code units in little - endian .