import { fromByteArray } from 'base64-js' ; export const imageTypes = [ 'image/svg+xml' , 'image/jpeg' , 'image/png' , 'image/gif' ] ; export function encode ( data , type = 'text/plain' ) { if ( FileReader ) { return new Promise < string > ( ( resolve , reject ) => { const reader = new FileReader ( ) ; reader . onloadend = ( ) => resolve ( reader . result as string ) ; reader . onerror = ( err ) => reject ( err ) ; reader . readAsDataURL ( data ) ; } ) ; } return Promise . resolve ( `data:${ type };base64,${ fromByteArray ( data ) }` ) ; }