1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00
metamask-extension/ui/helpers/utils/export-utils.js

14 lines
476 B
JavaScript

import { getRandomFileName } from './util';
export function exportAsFile(filename, data, type = 'text/csv') {
const b64 = Buffer.from(data, 'utf8').toString('base64');
// eslint-disable-next-line no-param-reassign
filename = filename || getRandomFileName();
const elem = window.document.createElement('a');
elem.href = `data:${type};Base64,${b64}`;
elem.download = filename;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}