( content: string, filename: string = 'DataKit_Export', extension: string = 'txt' )
| 144 | * Download text content as a file |
| 145 | */ |
| 146 | export const downloadText = ( |
| 147 | content: string, |
| 148 | filename: string = 'DataKit_Export', |
| 149 | extension: string = 'txt' |
| 150 | ): void => { |
| 151 | try { |
| 152 | const blob = new Blob([content], { type: 'text/plain' }); |
| 153 | const url = URL.createObjectURL(blob); |
| 154 | const a = document.createElement('a'); |
| 155 | a.href = url; |
| 156 | a.download = `${filename}.${extension}`; |
| 157 | document.body.appendChild(a); |
| 158 | a.click(); |
| 159 | document.body.removeChild(a); |
| 160 | URL.revokeObjectURL(url); |
| 161 | } catch (error) { |
| 162 | console.error('Failed to download text:', error); |
| 163 | throw new Error('Text download failed. Please try again.'); |
| 164 | } |
| 165 | }; |
| 166 | |
| 167 | /** |
| 168 | * Create styled HTML content for PDF export |
no outgoing calls
no test coverage detected