@umituz/react-native-design-system 2.9.47 → 2.9.49

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.47",
3
+ "version": "2.9.49",
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",
@@ -22,5 +22,12 @@ export { clearCache } from "./infrastructure/services/cache.service";
22
22
  // Services - File Reading
23
23
  export { readFile, readFileAsBase64 } from "./infrastructure/services/file-reader.service";
24
24
 
25
- // Utils - Blob Operations
26
- export { blobToBase64, base64ToBlob, base64ToFile } from "./infrastructure/utils/blob.utils";
25
+ // Utils - Base64 and File Operations
26
+ export {
27
+ extractBase64FromDataUri,
28
+ detectMimeType,
29
+ getExtensionFromMimeType,
30
+ base64ToTempFile,
31
+ deleteTempFile,
32
+ getFileSize,
33
+ } from "./infrastructure/utils/blob.utils";
@@ -1,28 +1,14 @@
1
1
  /**
2
2
  * Blob Utils
3
- * Blob utility functions for file operations
3
+ * Base64 and file utility functions for React Native
4
4
  */
5
5
 
6
- /**
7
- * Convert blob to base64 string
8
- */
9
- export function blobToBase64(blob: Blob): Promise<string> {
10
- return new Promise((resolve, reject) => {
11
- const reader = new FileReader();
12
- reader.onloadend = () => {
13
- const result = reader.result as string;
14
- const base64 = result.includes(",") ? result.split(",")[1] ?? result : result;
15
- resolve(base64);
16
- };
17
- reader.onerror = reject;
18
- reader.readAsDataURL(blob);
19
- });
20
- }
6
+ import { File, Paths } from "expo-file-system";
21
7
 
22
8
  /**
23
9
  * Extract raw base64 from data URI
24
10
  */
25
- function extractBase64FromDataUri(dataUri: string): string {
11
+ export function extractBase64FromDataUri(dataUri: string): string {
26
12
  if (!dataUri.startsWith("data:")) {
27
13
  return dataUri;
28
14
  }
@@ -31,9 +17,9 @@ function extractBase64FromDataUri(dataUri: string): string {
31
17
  }
32
18
 
33
19
  /**
34
- * Detect MIME type from data URI
20
+ * Detect MIME type from data URI or base64
35
21
  */
36
- function detectMimeType(base64: string): string {
22
+ export function detectMimeType(base64: string): string {
37
23
  if (base64.includes("data:image/png")) return "image/png";
38
24
  if (base64.includes("data:image/webp")) return "image/webp";
39
25
  if (base64.includes("data:image/gif")) return "image/gif";
@@ -41,29 +27,72 @@ function detectMimeType(base64: string): string {
41
27
  }
42
28
 
43
29
  /**
44
- * Convert base64 string to Blob
30
+ * Get file extension from MIME type
45
31
  */
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);
32
+ export function getExtensionFromMimeType(mimeType: string): string {
33
+ const ext = mimeType.split("/")[1];
34
+ if (ext === "jpeg") return "jpg";
35
+ return ext ?? "jpg";
36
+ }
51
37
 
52
- for (let i = 0; i < byteCharacters.length; i++) {
53
- byteArray[i] = byteCharacters.charCodeAt(i);
38
+ /**
39
+ * Convert base64 string to Uint8Array
40
+ * Required for binary file writing in new expo-file-system API
41
+ */
42
+ function base64ToUint8Array(base64: string): Uint8Array {
43
+ const binaryString = atob(base64);
44
+ const bytes = new Uint8Array(binaryString.length);
45
+ for (let i = 0; i < binaryString.length; i++) {
46
+ bytes[i] = binaryString.charCodeAt(i);
54
47
  }
55
-
56
- return new Blob([byteArray.buffer], { type: detectedMime });
48
+ return bytes;
57
49
  }
58
50
 
59
51
  /**
60
- * Convert base64 string to File
52
+ * Write base64 to a temp file and return the file URI
53
+ * This is React Native compatible (no Blob/ArrayBuffer needed)
61
54
  */
62
- export function base64ToFile(base64: string, filename?: string): File {
55
+ export async function base64ToTempFile(
56
+ base64: string,
57
+ filename?: string,
58
+ ): Promise<string> {
63
59
  const mimeType = detectMimeType(base64);
64
- const extension = mimeType.split("/")[1] ?? "jpg";
65
- const name = filename ?? `image.${extension}`;
66
- const blob = base64ToBlob(base64, mimeType);
60
+ const extension = getExtensionFromMimeType(mimeType);
61
+ const cleanBase64 = extractBase64FromDataUri(base64);
62
+ const name = filename ?? `temp_${Date.now()}.${extension}`;
63
+
64
+ const file = new File(Paths.cache, name);
65
+ await file.create();
66
+
67
+ // Convert base64 to Uint8Array for binary writing
68
+ const binaryData = base64ToUint8Array(cleanBase64);
69
+ file.write(binaryData);
67
70
 
68
- return new File([blob], name, { type: mimeType });
71
+ return file.uri;
72
+ }
73
+
74
+ /**
75
+ * Delete a temp file
76
+ */
77
+ export async function deleteTempFile(uri: string): Promise<void> {
78
+ try {
79
+ const file = new File(uri);
80
+ if (file.exists) {
81
+ file.delete();
82
+ }
83
+ } catch {
84
+ // Ignore deletion errors
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Get file size from URI
90
+ */
91
+ export function getFileSize(uri: string): number {
92
+ try {
93
+ const file = new File(uri);
94
+ return file.exists ? (file.size ?? 0) : 0;
95
+ } catch {
96
+ return 0;
97
+ }
69
98
  }