@umituz/react-native-design-system 2.9.45 → 2.9.47
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-design-system",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.47",
|
|
4
4
|
"description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive, safe area, exception, infinite scroll, UUID, image, timezone, offline, onboarding, and loading utilities",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
package/src/filesystem/index.ts
CHANGED
|
@@ -21,3 +21,6 @@ export { clearCache } from "./infrastructure/services/cache.service";
|
|
|
21
21
|
|
|
22
22
|
// Services - File Reading
|
|
23
23
|
export { readFile, readFileAsBase64 } from "./infrastructure/services/file-reader.service";
|
|
24
|
+
|
|
25
|
+
// Utils - Blob Operations
|
|
26
|
+
export { blobToBase64, base64ToBlob, base64ToFile } from "./infrastructure/utils/blob.utils";
|
|
@@ -18,3 +18,52 @@ export function blobToBase64(blob: Blob): Promise<string> {
|
|
|
18
18
|
reader.readAsDataURL(blob);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Extract raw base64 from data URI
|
|
24
|
+
*/
|
|
25
|
+
function extractBase64FromDataUri(dataUri: string): string {
|
|
26
|
+
if (!dataUri.startsWith("data:")) {
|
|
27
|
+
return dataUri;
|
|
28
|
+
}
|
|
29
|
+
const parts = dataUri.split(",");
|
|
30
|
+
return parts.length > 1 ? parts[1] : dataUri;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Detect MIME type from data URI
|
|
35
|
+
*/
|
|
36
|
+
function detectMimeType(base64: string): string {
|
|
37
|
+
if (base64.includes("data:image/png")) return "image/png";
|
|
38
|
+
if (base64.includes("data:image/webp")) return "image/webp";
|
|
39
|
+
if (base64.includes("data:image/gif")) return "image/gif";
|
|
40
|
+
return "image/jpeg";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Convert base64 string to Blob
|
|
45
|
+
*/
|
|
46
|
+
export function base64ToBlob(base64: string, mimeType?: string): Blob {
|
|
47
|
+
const detectedMime = mimeType ?? detectMimeType(base64);
|
|
48
|
+
const cleanBase64 = extractBase64FromDataUri(base64);
|
|
49
|
+
const byteCharacters = atob(cleanBase64);
|
|
50
|
+
const byteArray = new Uint8Array(byteCharacters.length);
|
|
51
|
+
|
|
52
|
+
for (let i = 0; i < byteCharacters.length; i++) {
|
|
53
|
+
byteArray[i] = byteCharacters.charCodeAt(i);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return new Blob([byteArray.buffer], { type: detectedMime });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Convert base64 string to File
|
|
61
|
+
*/
|
|
62
|
+
export function base64ToFile(base64: string, filename?: string): File {
|
|
63
|
+
const mimeType = detectMimeType(base64);
|
|
64
|
+
const extension = mimeType.split("/")[1] ?? "jpg";
|
|
65
|
+
const name = filename ?? `image.${extension}`;
|
|
66
|
+
const blob = base64ToBlob(base64, mimeType);
|
|
67
|
+
|
|
68
|
+
return new File([blob], name, { type: mimeType });
|
|
69
|
+
}
|