license param buffers returns export function concatenateArrayBuffers ( buffers ) { let totalByteLength = 0 ; buffers . forEach ( ( buffer ) => { totalByteLength += buffer . byteLength ; } ) ; const temp = new Uint8Array ( totalByteLength ) ; let offset = 0 ; buffers . forEach ( ( buffer ) => { temp . set ( new Uint8Array ( buffer ) , offset ) ; offset += buffer . byteLength ; } ) ; return temp . buffer ; } param xs return export function concatenateFloat32Arrays ( xs ) { let totalLength = 0 ; xs . forEach ( x => totalLength += x . length ) ; const concatenated = new Float32Array ( totalLength ) ; let index = 0 ; xs . forEach ( x => { concatenated . set ( x , index ) ; index += x . length ; } ) ; return concatenated ; } /** Encode a string as an ArrayBuffer. */ export function string2ArrayBuffer ( str ) { if ( str == null ) { throw new Error ( 'Received null or undefind string' ) ; } const strUTF8 = unescape ( encodeURIComponent ( str ) ) ; const buf = new Uint8Array ( strUTF8 . length ) ; for ( let i = 0 ; i < strUTF8 . length ; ++ i ) { buf [ i ] = strUTF8 . charCodeAt ( i ) ; } return buf . buffer ; } /** Decode an ArrayBuffer as a string. */ export function arrayBuffer2String ( buffer ) { if ( buffer == null ) { throw new Error ( 'Received null or undefind buffer' ) ; } const buf = new Uint8Array ( buffer ) ; return decodeURIComponent ( escape ( String . fromCharCode ( ... buf ) ) ) ; } /** Generate a pseudo-random UID. */ export function getUID ( ) { function s4 ( ) { return Math . floor ( ( 1 + Math . random ( ) ) * 0x10000 ) . toString ( 16 ) . substring ( 1 ) ; } return s4 ( ) + s4 ( ) + '-' + s4 ( ) + '-' + s4 ( ) + '-' + s4 ( ) + '-' + s4 ( ) + s4 ( ) + s4 ( ) ; } export function getRandomInteger ( min , max ) { return Math . floor ( ( max - min ) * Math . random ( ) ) + min ; }