@aut-labs/d-aut
Version:
## Web Component - what it does
27 lines (26 loc) • 820 B
JavaScript
/* tslint:disable */
export const pxToRem = (size) => {
size = `${size}`.replace('px', '');
return `${size}px`;
// return `${px}px`;
const x = 16;
const rem = `${(1 / x) * Number(size)}rem`;
return rem;
};
export async function dataUrlToFile(dataUrl, fileName) {
const res = await fetch(dataUrl);
const blob = await res.blob();
return new File([blob], fileName, { type: 'image/png' });
}
export const dataURLtoFile = (dataurl, filename) => {
const arr = dataurl.split(',');
const mime = arr[0].match(/:(.*?);/)[1];
const bstr = atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
while (n) {
u8arr[n - 1] = bstr.charCodeAt(n - 1);
n -= 1; // to make eslint happy
}
return new File([u8arr], filename, { type: mime });
};