UNPKG

@planjs/utils

Version:

🔧 Common tools collection

28 lines (23 loc) 654 B
import { REG_DATA_URL } from '../regex_constant'; import { ensure } from '../debug'; /** * base64 转换成 Blob * @param dataUrl * @return {Blob} */ function dataURLToBlob(dataUrl) { var _match; ensure(!REG_DATA_URL.test(dataUrl), "".concat(dataUrl, " is not a data url")); var arr = dataUrl.split(','); var mime = (_match = arr[0].match(/:(.*?);/)) === null || _match === void 0 ? void 0 : _match[1]; var bStr = atob(arr[1]); var n = bStr.length; var unit8Array = new Uint8Array(n); while (n--) { unit8Array[n] = bStr.charCodeAt(n); } return new Blob([unit8Array], { type: mime }); } export default dataURLToBlob;