declare function btoa ( str ) ; declare function atob ( str ) ; const _btoa = typeof btoa !== 'undefined' ? btoa : ( function ( str ) : string { const buffer = ( str instanceof Buffer ) ? str : Buffer . from ( str . toString ( ) , 'binary' ) ; return buffer . toString ( 'base64' ) ; } ) ; const _atob = typeof atob !== 'undefined' ? atob : ( function ( str ) : string { return Buffer . from ( str , 'base64' ) . toString ( 'binary' ) ; } ) ; export class Util { public static hex ( x , order = 2 ) { let s = x . toString ( 16 ) . padStart ( order , '0' ) ; if ( s . length > order ) s = s . substring ( s . length - order ) ; return s ; } public static clamp ( x , min , max ) { if ( max < min ) return min ; return x < min ? min : x > max ? max : x ; } public static getExt ( fileName ) { const index = fileName . lastIndexOf ( '.' ) ; if ( index >= 0 ) return fileName . slice ( index + 1 ) ; return '' ; } public static convertUint8ArrayToBase64String ( src ) { const s = Array . from ( src ) . map ( x => String . fromCharCode ( x ) ) . join ( '' ) ; return _btoa ( s ) ; } public static convertBase64StringToUint8Array ( src ) { const decoded = _atob ( src ) ; const u8array = new Uint8Array ( decoded . length ) ; for ( let i = 0 ; i < decoded . length ; ++ i ) u8array [ i ] = decoded . charCodeAt ( i ) ; return u8array ; } }