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

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.48",
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,56 @@ function detectMimeType(base64: string): string {
41
27
  }
42
28
 
43
29
  /**
44
- * Convert base64 string to Blob
30
+ * Get file extension from MIME type
31
+ */
32
+ export function getExtensionFromMimeType(mimeType: string): string {
33
+ const ext = mimeType.split("/")[1];
34
+ if (ext === "jpeg") return "jpg";
35
+ return ext ?? "jpg";
36
+ }
37
+
38
+ /**
39
+ * Write base64 to a temp file and return the file URI
40
+ * This is React Native compatible (no Blob/ArrayBuffer needed)
45
41
  */
46
- export function base64ToBlob(base64: string, mimeType?: string): Blob {
47
- const detectedMime = mimeType ?? detectMimeType(base64);
42
+ export async function base64ToTempFile(
43
+ base64: string,
44
+ filename?: string,
45
+ ): Promise<string> {
46
+ const mimeType = detectMimeType(base64);
47
+ const extension = getExtensionFromMimeType(mimeType);
48
48
  const cleanBase64 = extractBase64FromDataUri(base64);
49
- const byteCharacters = atob(cleanBase64);
50
- const byteArray = new Uint8Array(byteCharacters.length);
49
+ const name = filename ?? `temp_${Date.now()}.${extension}`;
51
50
 
52
- for (let i = 0; i < byteCharacters.length; i++) {
53
- byteArray[i] = byteCharacters.charCodeAt(i);
54
- }
51
+ const file = new File(Paths.cache, name);
52
+ await file.create();
53
+ file.write(cleanBase64, { encoding: "base64" });
55
54
 
56
- return new Blob([byteArray.buffer], { type: detectedMime });
55
+ return file.uri;
57
56
  }
58
57
 
59
58
  /**
60
- * Convert base64 string to File
59
+ * Delete a temp file
61
60
  */
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);
61
+ export async function deleteTempFile(uri: string): Promise<void> {
62
+ try {
63
+ const file = new File(uri);
64
+ if (file.exists) {
65
+ file.delete();
66
+ }
67
+ } catch {
68
+ // Ignore deletion errors
69
+ }
70
+ }
67
71
 
68
- return new File([blob], name, { type: mimeType });
72
+ /**
73
+ * Get file size from URI
74
+ */
75
+ export function getFileSize(uri: string): number {
76
+ try {
77
+ const file = new File(uri);
78
+ return file.exists ? (file.size ?? 0) : 0;
79
+ } catch {
80
+ return 0;
81
+ }
69
82
  }