@umituz/react-native-filesystem 1.0.0 → 1.1.0

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": "1.0.0",
3
+ "version": "1.1.0",
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",
@@ -131,4 +131,92 @@ export class FileUtils {
131
131
  .join('/')
132
132
  .replace(/\/+/g, '/');
133
133
  }
134
+
135
+ /**
136
+ * Get filename from filepath
137
+ */
138
+ static getFileName(filepath: string): string {
139
+ return filepath.split('/').pop() || '';
140
+ }
141
+
142
+ /**
143
+ * Get MIME type from filename
144
+ */
145
+ static getMimeType(filename: string): string {
146
+ const ext = this.getFileExtension(filename).toLowerCase().replace('.', '');
147
+
148
+ const mimeTypes: Record<string, string> = {
149
+ // Images
150
+ jpg: 'image/jpeg',
151
+ jpeg: 'image/jpeg',
152
+ png: 'image/png',
153
+ gif: 'image/gif',
154
+ webp: 'image/webp',
155
+ svg: 'image/svg+xml',
156
+
157
+ // Documents
158
+ pdf: 'application/pdf',
159
+ doc: 'application/msword',
160
+ docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
161
+ xls: 'application/vnd.ms-excel',
162
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
163
+
164
+ // Text
165
+ txt: 'text/plain',
166
+ csv: 'text/csv',
167
+ json: 'application/json',
168
+
169
+ // Video
170
+ mp4: 'video/mp4',
171
+ mov: 'video/quicktime',
172
+ avi: 'video/x-msvideo',
173
+ mkv: 'video/x-matroska',
174
+ webm: 'video/webm',
175
+
176
+ // Audio
177
+ mp3: 'audio/mpeg',
178
+ wav: 'audio/wav',
179
+ m4a: 'audio/mp4',
180
+ ogg: 'audio/ogg',
181
+ flac: 'audio/flac',
182
+ };
183
+
184
+ return mimeTypes[ext] || 'application/octet-stream';
185
+ }
186
+
187
+ /**
188
+ * Check if file is an image
189
+ */
190
+ static isImageFile(filename: string): boolean {
191
+ const ext = this.getFileExtension(filename).toLowerCase().replace('.', '');
192
+ return ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'].includes(ext);
193
+ }
194
+
195
+ /**
196
+ * Check if file is a video
197
+ */
198
+ static isVideoFile(filename: string): boolean {
199
+ const ext = this.getFileExtension(filename).toLowerCase().replace('.', '');
200
+ return ['mp4', 'mov', 'avi', 'mkv', 'webm'].includes(ext);
201
+ }
202
+
203
+ /**
204
+ * Check if file is an audio file
205
+ */
206
+ static isAudioFile(filename: string): boolean {
207
+ const ext = this.getFileExtension(filename).toLowerCase().replace('.', '');
208
+ return ['mp3', 'wav', 'm4a', 'ogg', 'flac'].includes(ext);
209
+ }
210
+
211
+ /**
212
+ * Generate filename with prefix (alternative to generateUniqueFilename)
213
+ */
214
+ static generateFileName(originalName: string, prefix?: string): string {
215
+ const timestamp = Date.now();
216
+ const random = Math.random().toString(36).substring(2, 9);
217
+ const ext = this.getFileExtension(originalName);
218
+ const baseName = prefix ? `${prefix}_` : '';
219
+
220
+ return `${baseName}${timestamp}_${random}${ext}`;
221
+ }
134
222
  }