@bouko/react 1.7.7 → 1.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/functions.d.ts +1 -0
- package/dist/core/functions.js +20 -0
- package/package.json +1 -1
package/dist/core/functions.d.ts
CHANGED
package/dist/core/functions.js
CHANGED
|
@@ -19,3 +19,23 @@ export const getEnv = (key) => {
|
|
|
19
19
|
throw new Error(`Missing required env: ${key}`);
|
|
20
20
|
return value;
|
|
21
21
|
};
|
|
22
|
+
export async function getBase64(image) {
|
|
23
|
+
if (image.startsWith("data:")) {
|
|
24
|
+
return image; // already a base64 data URL
|
|
25
|
+
}
|
|
26
|
+
const res = await fetch(image);
|
|
27
|
+
const blob = await res.blob();
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const reader = new FileReader();
|
|
30
|
+
reader.onloadend = () => {
|
|
31
|
+
if (typeof reader.result === "string") {
|
|
32
|
+
resolve(reader.result);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
reject(new Error("Failed to read image as base64"));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
reader.onerror = reject;
|
|
39
|
+
reader.readAsDataURL(blob);
|
|
40
|
+
});
|
|
41
|
+
}
|