UNPKG

@aut-labs/sdk

Version:

The TS/JS SDK package aims to make it easy for frontends/backends to integrate with Aut Smart Contracts

37 lines 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.base64toFile = exports.isBase64 = void 0; const isBase64 = (str) => { if (str === "" || str.trim() === "") { return false; } try { return btoa(atob(str)) === str; } catch (err) { return false; } }; exports.isBase64 = isBase64; function base64toFile(dataurl, filename) { if (!dataurl) { throw new Error("No content was provided"); } const [metadata, base64] = dataurl.split(","); if (metadata) { const mime = metadata.match(/:(.*?);/)[1]; if (!(0, exports.isBase64)(base64)) { throw new Error("Content provided is not of base64"); } const bstr = atob(base64); let n = bstr.length; const u8arr = new Uint8Array(n); // eslint-disable-next-line no-plusplus while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new File([u8arr], filename, { type: mime }); } } exports.base64toFile = base64toFile; //# sourceMappingURL=base64.js.map