Files
Kotyata/layers/shared/utils/download-file.ts
2026-03-17 13:24:22 +03:00

27 lines
529 B
TypeScript

export default (filename: string, content: string | File | Blob) => {
let blob: File | Blob
if (typeof content === 'string') {
blob = new File([content], filename, {
type: 'text/plain',
})
}
else {
blob = content
}
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.setAttribute(
'download',
filename,
)
document.body.appendChild(link)
link.click()
window.URL.revokeObjectURL(url)
document.body.removeChild(link)
}