export default function openFileHandler ( acceptFileTypes , fileType , callback ) { const input = document . getElementById ( 'openFileChooser' ) as HTMLInputElement ; if ( input ) { input . onchange = function ( e ) { const target = e . target as HTMLInputElement ; const file = target ?. files ?. [ 0 ] ; if ( target && file ) { const reader = new FileReader ( ) ; reader . onload = ( filename => { return ( evt ) => { callback ( ( evt . target as FileReader ) . result , filename ) ; } ; } ) ( file . name ) ; if ( fileType === 'text' ) { reader . readAsText ( file ) ; } else { reader . readAsDataURL ( file ) ; } target . value = '' ; } } ; input . setAttribute ( 'accept' , acceptFileTypes ) ; input . click ( ) ; } }