const FileDropperUtil = { param bytes param decimals returns formatBytes : ( bytes , decimals = 2 ) : string => { if ( bytes === 0 ) return '0 Bytes' ; const k = 1024 ; const dm = decimals < 0 ? 0 : decimals ; const sizes = [ 'Bytes' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ] ; const i = Math . floor ( Math . log ( bytes ) / Math . log ( k ) ) ; return `${ parseFloat ( ( bytes / k ** i ) . toFixed ( dm ) ) } ${ sizes [ i ] }` ; } , param oldFiles param newFiles returns { [ key : string ] getUniqueFiles : async ( oldFiles , newFiles ) : Promise < { [ key ] : File ; } > => { const filesToAdd = { } ; for ( const file of Array . from ( newFiles ) ) { const fileDataString = file . name + file . type + file . size + file . lastModified ; const fileDataHash = await FileDropperUtil . getSHA256 ( fileDataString ) ; filesToAdd [ fileDataHash ] = file ; } return { ... oldFiles , ... filesToAdd } ; } , param files returns getAllFilesSize : ( filesObject ) : number => { return Object . keys ( filesObject ) . reduce ( ( acc , fileHash ) => { return acc + filesObject [ fileHash ] . size ; } , 0 ) ; } , getSHA256 : async ( message ) : Promise < string > => { const msgBuffer = new TextEncoder ( ) . encode ( message ) ; const hashBuffer = await crypto . subtle . digest ( 'SHA-256' , msgBuffer ) ; const hashArray = Array . from ( new Uint8Array ( hashBuffer ) ) ; const hashHex = hashArray . map ( ( b ) => { return b . toString ( 16 ) . padStart ( 2 , '0' ) ; } ) . join ( '' ) ; return hashHex ; } , } ; export { FileDropperUtil } ;