@umituz/react-native-filesystem 2.1.3 → 2.1.5

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-filesystem",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "Domain-Driven Design filesystem utilities for React Native apps with build-time module loading and runtime file operations",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -0,0 +1,132 @@
1
+ /**
2
+ * File Entity
3
+ * Domain layer types and utilities for file operations
4
+ */
5
+
6
+ /**
7
+ * File encoding types supported by expo-file-system
8
+ */
9
+ export type FileEncoding = 'utf8' | 'base64';
10
+
11
+ /**
12
+ * Directory types available in expo-file-system
13
+ */
14
+ export type DirectoryType = 'documentDirectory' | 'cacheDirectory';
15
+
16
+ /**
17
+ * Result of a file operation
18
+ */
19
+ export interface FileOperationResult {
20
+ success: boolean;
21
+ uri?: string;
22
+ error?: string;
23
+ }
24
+
25
+ /**
26
+ * File information metadata
27
+ */
28
+ export interface FileInfo {
29
+ uri: string;
30
+ name?: string;
31
+ size: number;
32
+ exists: boolean;
33
+ isDirectory: boolean;
34
+ modificationTime?: number;
35
+ }
36
+
37
+ /**
38
+ * Download progress information
39
+ */
40
+ export interface DownloadProgress {
41
+ totalBytesWritten: number;
42
+ totalBytesExpectedToWrite: number;
43
+ }
44
+
45
+ /**
46
+ * File-related constants
47
+ */
48
+ export const FILE_CONSTANTS = {
49
+ MAX_FILE_SIZE: 100 * 1024 * 1024, // 100 MB
50
+ ALLOWED_EXTENSIONS: ['.jpg', '.jpeg', '.png', '.pdf', '.txt', '.json', '.mp4', '.mp3'],
51
+ DEFAULT_ENCODING: 'utf8' as FileEncoding,
52
+ } as const;
53
+
54
+ /**
55
+ * File utility functions
56
+ */
57
+ export class FileUtils {
58
+ /**
59
+ * Format file size in bytes to human-readable format
60
+ */
61
+ static formatFileSize(bytes: number): string {
62
+ if (bytes === 0) return '0 Bytes';
63
+ const k = 1024;
64
+ const sizes = ['Bytes', 'KB', 'MB', 'GB'];
65
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
66
+ return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i];
67
+ }
68
+
69
+ /**
70
+ * Generate unique filename with timestamp
71
+ */
72
+ static generateUniqueFilename(filename: string): string {
73
+ const timestamp = Date.now();
74
+ const extension = filename.includes('.') ? filename.substring(filename.lastIndexOf('.')) : '';
75
+ const nameWithoutExt = filename.includes('.')
76
+ ? filename.substring(0, filename.lastIndexOf('.'))
77
+ : filename;
78
+ return `${nameWithoutExt}_${timestamp}${extension}`;
79
+ }
80
+
81
+ /**
82
+ * Sanitize filename by removing invalid characters
83
+ */
84
+ static sanitizeFilename(filename: string): string {
85
+ return filename.replace(/[^a-zA-Z0-9._-]/g, '_');
86
+ }
87
+
88
+ /**
89
+ * Join path segments
90
+ */
91
+ static joinPaths(...segments: string[]): string {
92
+ return segments
93
+ .map((segment, index) => {
94
+ if (index === 0) {
95
+ return segment.replace(/\/+$/, '');
96
+ }
97
+ return segment.replace(/^\/+/, '').replace(/\/+$/, '');
98
+ })
99
+ .filter(segment => segment.length > 0)
100
+ .join('/');
101
+ }
102
+
103
+ /**
104
+ * Get file extension from filename
105
+ */
106
+ static getFileExtension(filename: string): string {
107
+ const lastDot = filename.lastIndexOf('.');
108
+ return lastDot > 0 ? filename.substring(lastDot) : '';
109
+ }
110
+
111
+ /**
112
+ * Check if file extension is allowed
113
+ */
114
+ static isAllowedExtension(filename: string): boolean {
115
+ const extension = this.getFileExtension(filename).toLowerCase();
116
+ return (FILE_CONSTANTS.ALLOWED_EXTENSIONS as readonly string[]).includes(extension);
117
+ }
118
+
119
+ /**
120
+ * Get filename from URI
121
+ */
122
+ static getFilenameFromUri(uri: string): string {
123
+ return uri.split('/').pop() || '';
124
+ }
125
+
126
+ /**
127
+ * Validate file size
128
+ */
129
+ static isValidFileSize(size: number): boolean {
130
+ return size > 0 && size <= FILE_CONSTANTS.MAX_FILE_SIZE;
131
+ }
132
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Module Context Entity
3
+ * Domain layer types for build-time module loading
4
+ *
5
+ * DEPRECATED: These types are kept for backward compatibility only.
6
+ * The module loading functionality is no longer actively used.
7
+ */
8
+
9
+ /**
10
+ * RequireFunction interface for Webpack/Metro require.context
11
+ * @deprecated No longer actively used
12
+ */
13
+ export interface RequireContext {
14
+ keys(): string[];
15
+ (id: string): any;
16
+ <T>(id: string): T;
17
+ resolve(id: string): string;
18
+ id: string;
19
+ }
20
+
21
+ /**
22
+ * Collection of loaded modules
23
+ * @deprecated No longer actively used
24
+ */
25
+ export type ModuleCollection = Record<string, any>;
26
+
27
+ /**
28
+ * Supported file extensions for module loading
29
+ * @deprecated No longer actively used
30
+ */
31
+ export type FileExtension = '.json' | '.js' | '.ts' | '.tsx';