mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 14:39:34 +01:00
17 lines
412 B
JavaScript
17 lines
412 B
JavaScript
const REGEX = /^data:(image\/.+);base64,(.+)/;
|
|
|
|
function toObject(dataurl) {
|
|
const regexResult = REGEX.exec(dataurl);
|
|
if (regexResult.length < 3) return {};
|
|
const [_, mime, data] = regexResult;
|
|
return { mime, data };
|
|
}
|
|
|
|
function fromObject({ type, data }) {
|
|
if (REGEX.test(data)) return data;
|
|
return `data:${type};base64,${data}`;
|
|
}
|
|
|
|
const dataurl = { toObject, fromObject };
|
|
export default dataurl;
|