function autoBOM ( blob ) { return /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i . test ( blob . type ) ? new Blob ( [ String . fromCharCode ( 0xfeff ) , blob ] , { type : blob . type } ) : blob ; } let saveAsWrapped ; if ( 'msSaveOrOpenBlob' in navigator ) { saveAsWrapped = function ( blob , name , no_auto_bom ? ) { return navigator . msSaveOrOpenBlob ( no_auto_bom !== true ? blob : autoBOM ( blob ) , name ) ; } ; } else { const getURL = function ( ) { return window . URL || window . webkitURL || window ; } ; const saveLink = document . createElement ( 'a' ) ; const click = function ( node ) { var event = new MouseEvent ( 'click' ) ; node . dispatchEvent ( event ) ; } ; const revoke = function ( file ) { setTimeout ( ( ) => getURL ( ) . revokeObjectURL ( file ) , 1000 * 40 ) ; } ; saveAsWrapped = function ( blob , name , no_auto_bom ? ) { const objectUrl = getURL ( ) . createObjectURL ( no_auto_bom !== true ? blob : autoBOM ( blob ) ) ; if ( 'download' in saveLink ) { setTimeout ( function ( ) { saveLink . href = objectUrl ; saveLink . download = name ; click ( saveLink ) ; revoke ( objectUrl ) ; } , 0 ) ; } else { window . location . href = objectUrl ; revoke ( objectUrl ) ; } } ; } export const saveAs = saveAsWrapped ;