(data, fName, extension)
| 1 | function downloadFile(data, fName, extension) { |
| 2 | const fx = _checkFileExtension(fName, extension); |
| 3 | const filename = fx[0]; |
| 4 | let saveData = data; |
| 5 | |
| 6 | if (!(saveData instanceof Blob)) { |
| 7 | saveData = new Blob([data]); |
| 8 | } |
| 9 | |
| 10 | if(document){ |
| 11 | const url = URL.createObjectURL(saveData); |
| 12 | const link = document.createElement('a'); |
| 13 | link.href = url; |
| 14 | link.download = filename; |
| 15 | link.click(); |
| 16 | URL.revokeObjectURL(url); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | function _checkFileExtension(filename, extension) { |
| 21 | if (!extension || extension === true || extension === 'true') { |
no test coverage detected