import fileSaver from 'file-saver' ; export enum FileType { BatchFile , ShellScript } export class SaveFileDialog { public static saveFile ( text , fileName , type ) { const mimeType = this . mimeTypes . get ( type ) ; this . saveBlob ( text , mimeType , fileName ) ; } private static readonly mimeTypes = new Map < FileType , string > ( [ [ FileType . BatchFile , 'application/bat' ] , [ FileType . ShellScript , 'text/x-shellscript' ] , ] ) ; private static saveBlob ( file , fileType , fileName ) { try { const blob = new Blob ( [ file ] , { type : fileType } ) ; fileSaver . saveAs ( blob , fileName ) ; } catch ( e ) { window . open ( `data:${ fileType },${ encodeURIComponent ( file . toString ( ) ) }` , '_blank' , '' ) ; } } }