@stokr/components-library
Version:
STOKR - Components Library
29 lines (25 loc) • 777 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.saveAs = exports.openFile = void 0;
const saveAs = function (file) {
let fileName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'fileName';
// Create blob link to download
const url = window.URL.createObjectURL(file);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', fileName);
// Append to html link element page
document.body.appendChild(link);
// Start download
link.click();
// Clean up and remove the link
link.parentNode.removeChild(link);
};
exports.saveAs = saveAs;
const openFile = file => {
var url = window.URL.createObjectURL(file);
window.open(url);
};
exports.openFile = openFile;