@umituz/react-native-design-system 2.9.46 → 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.
|
|
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",
|
package/src/filesystem/index.ts
CHANGED
|
@@ -21,3 +21,13 @@ 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 - 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,20 +1,82 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Blob Utils
|
|
3
|
-
*
|
|
3
|
+
* Base64 and file utility functions for React Native
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { File, Paths } from "expo-file-system";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Extract raw base64 from data URI
|
|
10
|
+
*/
|
|
11
|
+
export function extractBase64FromDataUri(dataUri: string): string {
|
|
12
|
+
if (!dataUri.startsWith("data:")) {
|
|
13
|
+
return dataUri;
|
|
14
|
+
}
|
|
15
|
+
const parts = dataUri.split(",");
|
|
16
|
+
return parts.length > 1 ? parts[1] : dataUri;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Detect MIME type from data URI or base64
|
|
21
|
+
*/
|
|
22
|
+
export function detectMimeType(base64: string): string {
|
|
23
|
+
if (base64.includes("data:image/png")) return "image/png";
|
|
24
|
+
if (base64.includes("data:image/webp")) return "image/webp";
|
|
25
|
+
if (base64.includes("data:image/gif")) return "image/gif";
|
|
26
|
+
return "image/jpeg";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
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)
|
|
41
|
+
*/
|
|
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
|
+
const cleanBase64 = extractBase64FromDataUri(base64);
|
|
49
|
+
const name = filename ?? `temp_${Date.now()}.${extension}`;
|
|
50
|
+
|
|
51
|
+
const file = new File(Paths.cache, name);
|
|
52
|
+
await file.create();
|
|
53
|
+
file.write(cleanBase64, { encoding: "base64" });
|
|
54
|
+
|
|
55
|
+
return file.uri;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Delete a temp file
|
|
60
|
+
*/
|
|
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
|
+
}
|
|
71
|
+
|
|
6
72
|
/**
|
|
7
|
-
*
|
|
73
|
+
* Get file size from URI
|
|
8
74
|
*/
|
|
9
|
-
export function
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
reader.onerror = reject;
|
|
18
|
-
reader.readAsDataURL(blob);
|
|
19
|
-
});
|
|
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
|
+
}
|
|
20
82
|
}
|