mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-09 13:06:52 +03:00
16 lines
451 B
TypeScript
16 lines
451 B
TypeScript
export function downloadAsTxt(text: string, filename: string) {
|
|
const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });
|
|
|
|
const link = document.createElement('a');
|
|
link.href = URL.createObjectURL(blob);
|
|
|
|
const safeName = filename.endsWith('.txt') ? filename : `${filename}.txt`;
|
|
link.download = safeName;
|
|
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
|
|
document.body.removeChild(link);
|
|
URL.revokeObjectURL(link.href);
|
|
}
|