export function stringToArrayBuffer ( str ) { const buffer = new ArrayBuffer ( str . length * 2 ) ; const view = new Uint16Array ( buffer ) ; for ( let i = 0 ; i < str . length ; i ++ ) { view [ i ] = str . codePointAt ( i ) ?? str . charCodeAt ( i ) ; } return buffer ; }