@umituz/react-native-filesystem 2.1.3 → 2.1.4
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
|
+
"version": "2.1.4",
|
|
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,131 @@
|
|
|
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
|
+
size: number;
|
|
31
|
+
exists: boolean;
|
|
32
|
+
isDirectory: boolean;
|
|
33
|
+
modificationTime?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Download progress information
|
|
38
|
+
*/
|
|
39
|
+
export interface DownloadProgress {
|
|
40
|
+
totalBytesWritten: number;
|
|
41
|
+
totalBytesExpectedToWrite: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* File-related constants
|
|
46
|
+
*/
|
|
47
|
+
export const FILE_CONSTANTS = {
|
|
48
|
+
MAX_FILE_SIZE: 100 * 1024 * 1024, // 100 MB
|
|
49
|
+
ALLOWED_EXTENSIONS: ['.jpg', '.jpeg', '.png', '.pdf', '.txt', '.json', '.mp4', '.mp3'],
|
|
50
|
+
DEFAULT_ENCODING: 'utf8' as FileEncoding,
|
|
51
|
+
} as const;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* File utility functions
|
|
55
|
+
*/
|
|
56
|
+
export class FileUtils {
|
|
57
|
+
/**
|
|
58
|
+
* Format file size in bytes to human-readable format
|
|
59
|
+
*/
|
|
60
|
+
static formatFileSize(bytes: number): string {
|
|
61
|
+
if (bytes === 0) return '0 Bytes';
|
|
62
|
+
const k = 1024;
|
|
63
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
|
64
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
65
|
+
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Generate unique filename with timestamp
|
|
70
|
+
*/
|
|
71
|
+
static generateUniqueFilename(filename: string): string {
|
|
72
|
+
const timestamp = Date.now();
|
|
73
|
+
const extension = filename.includes('.') ? filename.substring(filename.lastIndexOf('.')) : '';
|
|
74
|
+
const nameWithoutExt = filename.includes('.')
|
|
75
|
+
? filename.substring(0, filename.lastIndexOf('.'))
|
|
76
|
+
: filename;
|
|
77
|
+
return `${nameWithoutExt}_${timestamp}${extension}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Sanitize filename by removing invalid characters
|
|
82
|
+
*/
|
|
83
|
+
static sanitizeFilename(filename: string): string {
|
|
84
|
+
return filename.replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Join path segments
|
|
89
|
+
*/
|
|
90
|
+
static joinPaths(...segments: string[]): string {
|
|
91
|
+
return segments
|
|
92
|
+
.map((segment, index) => {
|
|
93
|
+
if (index === 0) {
|
|
94
|
+
return segment.replace(/\/+$/, '');
|
|
95
|
+
}
|
|
96
|
+
return segment.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
97
|
+
})
|
|
98
|
+
.filter(segment => segment.length > 0)
|
|
99
|
+
.join('/');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get file extension from filename
|
|
104
|
+
*/
|
|
105
|
+
static getFileExtension(filename: string): string {
|
|
106
|
+
const lastDot = filename.lastIndexOf('.');
|
|
107
|
+
return lastDot > 0 ? filename.substring(lastDot) : '';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Check if file extension is allowed
|
|
112
|
+
*/
|
|
113
|
+
static isAllowedExtension(filename: string): boolean {
|
|
114
|
+
const extension = this.getFileExtension(filename).toLowerCase();
|
|
115
|
+
return FILE_CONSTANTS.ALLOWED_EXTENSIONS.includes(extension);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get filename from URI
|
|
120
|
+
*/
|
|
121
|
+
static getFilenameFromUri(uri: string): string {
|
|
122
|
+
return uri.split('/').pop() || '';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Validate file size
|
|
127
|
+
*/
|
|
128
|
+
static isValidFileSize(size: number): boolean {
|
|
129
|
+
return size > 0 && size <= FILE_CONSTANTS.MAX_FILE_SIZE;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -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';
|