@ooneex/http-request-file 0.0.1
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/LICENSE +21 -0
- package/README.md +454 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +10 -0
- package/dist/ooneex-http-request-file-0.0.1.tgz +0 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ooneex
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
# @ooneex/http-request-file
|
|
2
|
+
|
|
3
|
+
A comprehensive TypeScript/JavaScript library for handling HTTP request files with type-safe file operations and MIME type detection. This package provides a robust wrapper around the native File API with additional utilities for file processing, validation, and I/O operations.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
✅ **File Wrapper** - Enhanced File API wrapper with additional utilities
|
|
15
|
+
|
|
16
|
+
✅ **Type-Safe** - Full TypeScript support with proper type definitions
|
|
17
|
+
|
|
18
|
+
✅ **MIME Type Detection** - Built-in MIME type detection and validation
|
|
19
|
+
|
|
20
|
+
✅ **Multiple Read Methods** - Support for ArrayBuffer, Stream, and Text reading
|
|
21
|
+
|
|
22
|
+
✅ **File Properties** - Rich file metadata including size, type, and extension
|
|
23
|
+
|
|
24
|
+
✅ **Automatic Naming** - Generates unique filenames and normalizes original names
|
|
25
|
+
|
|
26
|
+
✅ **Cross-Platform** - Works in Browser, Node.js, Bun, and Deno
|
|
27
|
+
|
|
28
|
+
✅ **File I/O Operations** - Built-in file writing capabilities
|
|
29
|
+
|
|
30
|
+
✅ **Format Detection** - Automatic detection of images, videos, documents, and more
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
### Bun
|
|
35
|
+
```bash
|
|
36
|
+
bun add @ooneex/http-request-file
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### pnpm
|
|
40
|
+
```bash
|
|
41
|
+
pnpm add @ooneex/http-request-file
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Yarn
|
|
45
|
+
```bash
|
|
46
|
+
yarn add @ooneex/http-request-file
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### npm
|
|
50
|
+
```bash
|
|
51
|
+
npm install @ooneex/http-request-file
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
### Basic Usage
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { RequestFile } from '@ooneex/http-request-file';
|
|
60
|
+
|
|
61
|
+
// Create from a native File object (e.g., from form upload)
|
|
62
|
+
const nativeFile = new File(['Hello, world!'], 'example.txt', { type: 'text/plain' });
|
|
63
|
+
const requestFile = new RequestFile(nativeFile);
|
|
64
|
+
|
|
65
|
+
// Access file properties
|
|
66
|
+
console.log(requestFile.id); // Unique 25-character ID
|
|
67
|
+
console.log(requestFile.name); // Generated name: "abc123def456ghi789jkl012.txt"
|
|
68
|
+
console.log(requestFile.originalName); // Normalized: "example.txt"
|
|
69
|
+
console.log(requestFile.type); // "text/plain"
|
|
70
|
+
console.log(requestFile.size); // File size in bytes
|
|
71
|
+
console.log(requestFile.extension); // "txt"
|
|
72
|
+
|
|
73
|
+
// Check file types
|
|
74
|
+
console.log(requestFile.isText); // true
|
|
75
|
+
console.log(requestFile.isImage); // false
|
|
76
|
+
console.log(requestFile.isPdf); // false
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### File Reading Operations
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { RequestFile } from '@ooneex/http-request-file';
|
|
83
|
+
|
|
84
|
+
const imageFile = new File([/* binary data */], 'photo.jpg', { type: 'image/jpeg' });
|
|
85
|
+
const requestFile = new RequestFile(imageFile);
|
|
86
|
+
|
|
87
|
+
// Read as text (for text files)
|
|
88
|
+
const textContent = await requestFile.readAsText();
|
|
89
|
+
console.log(textContent);
|
|
90
|
+
|
|
91
|
+
// Read as ArrayBuffer (for binary files)
|
|
92
|
+
const buffer = await requestFile.readAsArrayBuffer();
|
|
93
|
+
console.log(new Uint8Array(buffer));
|
|
94
|
+
|
|
95
|
+
// Read as stream (for large files)
|
|
96
|
+
const stream = requestFile.readAsStream();
|
|
97
|
+
const reader = stream.getReader();
|
|
98
|
+
const { value, done } = await reader.read();
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### File Type Detection
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { RequestFile } from '@ooneex/http-request-file';
|
|
105
|
+
|
|
106
|
+
// Image file
|
|
107
|
+
const imageFile = new File([/* data */], 'photo.png', { type: 'image/png' });
|
|
108
|
+
const imageRequest = new RequestFile(imageFile);
|
|
109
|
+
console.log(imageRequest.isImage); // true
|
|
110
|
+
console.log(imageRequest.isSvg); // false
|
|
111
|
+
|
|
112
|
+
// Document file
|
|
113
|
+
const pdfFile = new File([/* data */], 'document.pdf', { type: 'application/pdf' });
|
|
114
|
+
const pdfRequest = new RequestFile(pdfFile);
|
|
115
|
+
console.log(pdfRequest.isPdf); // true
|
|
116
|
+
console.log(pdfRequest.isText); // false
|
|
117
|
+
|
|
118
|
+
// Excel file
|
|
119
|
+
const excelFile = new File([/* data */], 'spreadsheet.xlsx', {
|
|
120
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
121
|
+
});
|
|
122
|
+
const excelRequest = new RequestFile(excelFile);
|
|
123
|
+
console.log(excelRequest.isExcel); // true
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### File Writing
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { RequestFile } from '@ooneex/http-request-file';
|
|
130
|
+
|
|
131
|
+
const file = new File(['File content'], 'example.txt', { type: 'text/plain' });
|
|
132
|
+
const requestFile = new RequestFile(file);
|
|
133
|
+
|
|
134
|
+
// Write file to disk (Bun/Node.js)
|
|
135
|
+
await requestFile.write('./uploads/saved-file.txt');
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Advanced Usage
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { RequestFile } from '@ooneex/http-request-file';
|
|
142
|
+
|
|
143
|
+
// Handle form upload
|
|
144
|
+
function handleFileUpload(files: FileList) {
|
|
145
|
+
Array.from(files).forEach(file => {
|
|
146
|
+
const requestFile = new RequestFile(file);
|
|
147
|
+
|
|
148
|
+
console.log(`Processing: ${requestFile.originalName}`);
|
|
149
|
+
console.log(`Size: ${requestFile.size} bytes`);
|
|
150
|
+
console.log(`Type: ${requestFile.type}`);
|
|
151
|
+
|
|
152
|
+
// Process based on file type
|
|
153
|
+
if (requestFile.isImage) {
|
|
154
|
+
console.log('Processing image file');
|
|
155
|
+
// Handle image processing
|
|
156
|
+
} else if (requestFile.isPdf) {
|
|
157
|
+
console.log('Processing PDF document');
|
|
158
|
+
// Handle PDF processing
|
|
159
|
+
} else if (requestFile.isExcel || requestFile.isCsv) {
|
|
160
|
+
console.log('Processing spreadsheet');
|
|
161
|
+
// Handle spreadsheet processing
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Batch processing with concurrent operations
|
|
167
|
+
async function processBatch(files: File[]) {
|
|
168
|
+
const requestFiles = files.map(file => new RequestFile(file));
|
|
169
|
+
|
|
170
|
+
// Process text files
|
|
171
|
+
const textFiles = requestFiles.filter(rf => rf.isText);
|
|
172
|
+
const textContents = await Promise.all(
|
|
173
|
+
textFiles.map(rf => rf.readAsText())
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
// Process image files
|
|
177
|
+
const imageFiles = requestFiles.filter(rf => rf.isImage);
|
|
178
|
+
const imageBuffers = await Promise.all(
|
|
179
|
+
imageFiles.map(rf => rf.readAsArrayBuffer())
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
return { textContents, imageBuffers };
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## API Reference
|
|
187
|
+
|
|
188
|
+
### `RequestFile` Class
|
|
189
|
+
|
|
190
|
+
The main class for wrapping native File objects with enhanced functionality.
|
|
191
|
+
|
|
192
|
+
#### Constructor
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
constructor(native: File)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Creates a new RequestFile instance from a native File object.
|
|
199
|
+
|
|
200
|
+
**Parameters:**
|
|
201
|
+
- `native` - The native File object to wrap
|
|
202
|
+
|
|
203
|
+
#### Properties
|
|
204
|
+
|
|
205
|
+
##### `id: string` (readonly)
|
|
206
|
+
Unique 25-character identifier for the file.
|
|
207
|
+
|
|
208
|
+
##### `name: string` (readonly)
|
|
209
|
+
Generated filename using the unique ID and original extension.
|
|
210
|
+
**Format:** `{id}.{extension}`
|
|
211
|
+
|
|
212
|
+
##### `originalName: string` (readonly)
|
|
213
|
+
Original filename converted to kebab-case with extension preserved.
|
|
214
|
+
|
|
215
|
+
##### `type: MimeType` (readonly)
|
|
216
|
+
MIME type of the file (charset parameters removed).
|
|
217
|
+
|
|
218
|
+
##### `size: number` (readonly)
|
|
219
|
+
File size in bytes.
|
|
220
|
+
|
|
221
|
+
##### `extension: string` (readonly)
|
|
222
|
+
File extension in lowercase.
|
|
223
|
+
|
|
224
|
+
##### File Type Detection Properties
|
|
225
|
+
|
|
226
|
+
All properties return `boolean` values:
|
|
227
|
+
|
|
228
|
+
- `isImage` - Detects image files (PNG, JPEG, GIF, WebP, etc.)
|
|
229
|
+
- `isSvg` - Detects SVG images specifically
|
|
230
|
+
- `isVideo` - Detects video files (MP4, WebM, AVI, etc.)
|
|
231
|
+
- `isAudio` - Detects audio files (MP3, WAV, OGG, etc.)
|
|
232
|
+
- `isPdf` - Detects PDF documents
|
|
233
|
+
- `isText` - Detects text-based files
|
|
234
|
+
- `isExcel` - Detects Excel/spreadsheet files
|
|
235
|
+
- `isCsv` - Detects CSV files
|
|
236
|
+
- `isJson` - Detects JSON files
|
|
237
|
+
- `isXml` - Detects XML files
|
|
238
|
+
- `isHtml` - Detects HTML files
|
|
239
|
+
|
|
240
|
+
#### Methods
|
|
241
|
+
|
|
242
|
+
##### `readAsArrayBuffer(): Promise<ArrayBuffer>`
|
|
243
|
+
Reads the file content as an ArrayBuffer.
|
|
244
|
+
|
|
245
|
+
**Returns:** Promise that resolves to an ArrayBuffer containing the file data.
|
|
246
|
+
|
|
247
|
+
**Example:**
|
|
248
|
+
```typescript
|
|
249
|
+
const buffer = await requestFile.readAsArrayBuffer();
|
|
250
|
+
const uint8Array = new Uint8Array(buffer);
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
##### `readAsStream(): ReadableStream<Uint8Array>`
|
|
254
|
+
Returns a readable stream of the file content.
|
|
255
|
+
|
|
256
|
+
**Returns:** ReadableStream for streaming file data.
|
|
257
|
+
|
|
258
|
+
**Example:**
|
|
259
|
+
```typescript
|
|
260
|
+
const stream = requestFile.readAsStream();
|
|
261
|
+
const reader = stream.getReader();
|
|
262
|
+
|
|
263
|
+
while (true) {
|
|
264
|
+
const { done, value } = await reader.read();
|
|
265
|
+
if (done) break;
|
|
266
|
+
console.log('Chunk:', value);
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
##### `readAsText(): Promise<string>`
|
|
271
|
+
Reads the file content as a text string.
|
|
272
|
+
|
|
273
|
+
**Returns:** Promise that resolves to the file content as a string.
|
|
274
|
+
|
|
275
|
+
**Example:**
|
|
276
|
+
```typescript
|
|
277
|
+
const text = await requestFile.readAsText();
|
|
278
|
+
console.log(text);
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
##### `write(path: string): Promise<void>`
|
|
282
|
+
Writes the file to the specified path on disk.
|
|
283
|
+
|
|
284
|
+
**Parameters:**
|
|
285
|
+
- `path` - The file system path where to write the file
|
|
286
|
+
|
|
287
|
+
**Returns:** Promise that resolves when the file is written.
|
|
288
|
+
|
|
289
|
+
**Example:**
|
|
290
|
+
```typescript
|
|
291
|
+
await requestFile.write('./uploads/my-file.txt');
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Interface
|
|
295
|
+
|
|
296
|
+
#### `IRequestFile`
|
|
297
|
+
Interface defining all available properties and methods for request files.
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
interface IRequestFile {
|
|
301
|
+
readonly id: string;
|
|
302
|
+
readonly name: string;
|
|
303
|
+
readonly originalName: string;
|
|
304
|
+
readonly type: MimeType;
|
|
305
|
+
readonly size: number;
|
|
306
|
+
readonly extension: string;
|
|
307
|
+
readonly isImage: boolean;
|
|
308
|
+
readonly isVideo: boolean;
|
|
309
|
+
readonly isAudio: boolean;
|
|
310
|
+
readonly isPdf: boolean;
|
|
311
|
+
readonly isText: boolean;
|
|
312
|
+
readonly isExcel: boolean;
|
|
313
|
+
readonly isCsv: boolean;
|
|
314
|
+
readonly isJson: boolean;
|
|
315
|
+
readonly isXml: boolean;
|
|
316
|
+
readonly isHtml: boolean;
|
|
317
|
+
readonly isSvg: boolean;
|
|
318
|
+
readAsArrayBuffer(): Promise<ArrayBuffer>;
|
|
319
|
+
readAsStream(): ReadableStream<Uint8Array>;
|
|
320
|
+
readAsText(): Promise<string>;
|
|
321
|
+
write(path: string): Promise<void>;
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Use Cases
|
|
326
|
+
|
|
327
|
+
### File Upload Handler
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
import { RequestFile } from '@ooneex/http-request-file';
|
|
331
|
+
|
|
332
|
+
async function handleUpload(formData: FormData) {
|
|
333
|
+
const file = formData.get('file') as File;
|
|
334
|
+
if (!file) return;
|
|
335
|
+
|
|
336
|
+
const requestFile = new RequestFile(file);
|
|
337
|
+
|
|
338
|
+
// Validate file type
|
|
339
|
+
if (!requestFile.isImage && !requestFile.isPdf) {
|
|
340
|
+
throw new Error('Only images and PDFs are allowed');
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Generate safe filename
|
|
344
|
+
const safePath = `./uploads/${requestFile.name}`;
|
|
345
|
+
|
|
346
|
+
// Save to disk
|
|
347
|
+
await requestFile.write(safePath);
|
|
348
|
+
|
|
349
|
+
return {
|
|
350
|
+
id: requestFile.id,
|
|
351
|
+
originalName: requestFile.originalName,
|
|
352
|
+
size: requestFile.size,
|
|
353
|
+
type: requestFile.type,
|
|
354
|
+
saved: safePath
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### Image Processing Pipeline
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
import { RequestFile } from '@ooneex/http-request-file';
|
|
363
|
+
|
|
364
|
+
async function processImageBatch(files: File[]) {
|
|
365
|
+
const results = [];
|
|
366
|
+
|
|
367
|
+
for (const file of files) {
|
|
368
|
+
const requestFile = new RequestFile(file);
|
|
369
|
+
|
|
370
|
+
if (requestFile.isImage && !requestFile.isSvg) {
|
|
371
|
+
// Process raster images
|
|
372
|
+
const buffer = await requestFile.readAsArrayBuffer();
|
|
373
|
+
// ... process with image library
|
|
374
|
+
|
|
375
|
+
results.push({
|
|
376
|
+
id: requestFile.id,
|
|
377
|
+
type: 'raster',
|
|
378
|
+
processed: true
|
|
379
|
+
});
|
|
380
|
+
} else if (requestFile.isSvg) {
|
|
381
|
+
// Process SVG images
|
|
382
|
+
const svg = await requestFile.readAsText();
|
|
383
|
+
// ... process SVG content
|
|
384
|
+
|
|
385
|
+
results.push({
|
|
386
|
+
id: requestFile.id,
|
|
387
|
+
type: 'svg',
|
|
388
|
+
processed: true
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return results;
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Document Analysis
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
import { RequestFile } from '@ooneex/http-request-file';
|
|
401
|
+
|
|
402
|
+
async function analyzeDocuments(files: File[]) {
|
|
403
|
+
const analysis = {
|
|
404
|
+
documents: 0,
|
|
405
|
+
spreadsheets: 0,
|
|
406
|
+
images: 0,
|
|
407
|
+
other: 0,
|
|
408
|
+
totalSize: 0
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
for (const file of files) {
|
|
412
|
+
const requestFile = new RequestFile(file);
|
|
413
|
+
analysis.totalSize += requestFile.size;
|
|
414
|
+
|
|
415
|
+
if (requestFile.isPdf) {
|
|
416
|
+
analysis.documents++;
|
|
417
|
+
} else if (requestFile.isExcel || requestFile.isCsv) {
|
|
418
|
+
analysis.spreadsheets++;
|
|
419
|
+
} else if (requestFile.isImage) {
|
|
420
|
+
analysis.images++;
|
|
421
|
+
} else {
|
|
422
|
+
analysis.other++;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return analysis;
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
## License
|
|
431
|
+
|
|
432
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
433
|
+
|
|
434
|
+
## Contributing
|
|
435
|
+
|
|
436
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
437
|
+
|
|
438
|
+
### Development Setup
|
|
439
|
+
|
|
440
|
+
1. Clone the repository
|
|
441
|
+
2. Install dependencies: `bun install`
|
|
442
|
+
3. Run tests: `bun run test`
|
|
443
|
+
4. Build the project: `bun run build`
|
|
444
|
+
|
|
445
|
+
### Guidelines
|
|
446
|
+
|
|
447
|
+
- Write tests for new features
|
|
448
|
+
- Follow the existing code style
|
|
449
|
+
- Update documentation for API changes
|
|
450
|
+
- Ensure all tests pass before submitting PR
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
Made with ❤️ by the Ooneex team
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { MimeType as MimeType2 } from "@ooneex/http-mimes";
|
|
2
|
+
import { MimeType } from "@ooneex/http-mimes";
|
|
3
|
+
interface IRequestFile {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly originalName: string;
|
|
7
|
+
readonly type: MimeType;
|
|
8
|
+
readonly size: number;
|
|
9
|
+
readonly extension: string;
|
|
10
|
+
readonly isImage: boolean;
|
|
11
|
+
readonly isVideo: boolean;
|
|
12
|
+
readonly isAudio: boolean;
|
|
13
|
+
readonly isPdf: boolean;
|
|
14
|
+
readonly isText: boolean;
|
|
15
|
+
readonly isExcel: boolean;
|
|
16
|
+
readonly isCsv: boolean;
|
|
17
|
+
readonly isJson: boolean;
|
|
18
|
+
readonly isXml: boolean;
|
|
19
|
+
readonly isHtml: boolean;
|
|
20
|
+
readonly isSvg: boolean;
|
|
21
|
+
readAsArrayBuffer: () => Promise<ArrayBuffer>;
|
|
22
|
+
readAsStream: () => ReadableStream<Uint8Array>;
|
|
23
|
+
readAsText: () => Promise<string>;
|
|
24
|
+
write: (path: string) => Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
declare class RequestFile implements IRequestFile {
|
|
27
|
+
private readonly native;
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly originalName: string;
|
|
31
|
+
readonly type: MimeType2;
|
|
32
|
+
readonly size: number;
|
|
33
|
+
readonly extension: string;
|
|
34
|
+
readonly isImage: boolean;
|
|
35
|
+
readonly isSvg: boolean;
|
|
36
|
+
readonly isVideo: boolean;
|
|
37
|
+
readonly isAudio: boolean;
|
|
38
|
+
readonly isPdf: boolean;
|
|
39
|
+
readonly isText: boolean;
|
|
40
|
+
readonly isExcel: boolean;
|
|
41
|
+
readonly isCsv: boolean;
|
|
42
|
+
readonly isJson: boolean;
|
|
43
|
+
readonly isXml: boolean;
|
|
44
|
+
readonly isHtml: boolean;
|
|
45
|
+
constructor(native: File);
|
|
46
|
+
readAsArrayBuffer(): Promise<ArrayBuffer>;
|
|
47
|
+
readAsStream(): ReadableStream<Uint8Array>;
|
|
48
|
+
readAsText(): Promise<string>;
|
|
49
|
+
write(path: string): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export { RequestFile, IRequestFile };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{Mime as a}from"@ooneex/http-mimes";import{random as n,toKebabCase as t}from"@ooneex/utils";class r{native;id;name;originalName;type;size;extension;isImage;isSvg;isVideo;isAudio;isPdf;isText;isExcel;isCsv;isJson;isXml;isHtml;constructor(s){this.native=s;let o=this.native.name.match(/\.([0-9a-z]+)$/i);this.extension=(o?o[1]:"")?.toLowerCase()||"",this.originalName=t(this.native.name.replace(/\.[0-9a-z]*$/i,"")),this.originalName=`${this.originalName}.${this.extension}`,this.type=this.native.type.replace(/\s*;.*$/,""),this.size=this.native.size,this.id=n.nanoid(25),this.name=`${this.id}.${this.extension}`;let e=new a,i=this.type;this.isImage=e.isImage(i),this.isSvg=e.isSvg(i),this.isVideo=e.isVideo(i),this.isAudio=e.isAudio(i),this.isPdf=e.isPdf(i),this.isText=e.isText(i),this.isExcel=e.isExcel(i),this.isCsv=e.isCsv(i),this.isJson=e.isJson(i),this.isXml=e.isXml(i),this.isHtml=e.isHtml(i)}async readAsArrayBuffer(){return await this.native.arrayBuffer()}readAsStream(){return this.native.stream()}async readAsText(){return await this.native.text()}async write(s){await Bun.write(s,this.native)}}export{r as RequestFile};
|
|
2
|
+
|
|
3
|
+
//# debugId=ED70B1F359AF8DC664756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/RequestFile.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { Mime, type MimeType } from \"@ooneex/http-mimes\";\nimport { random, toKebabCase } from \"@ooneex/utils\";\nimport type { IRequestFile } from \"./types\";\n\nexport class RequestFile implements IRequestFile {\n public readonly id: string;\n public readonly name: string;\n public readonly originalName: string;\n public readonly type: MimeType;\n public readonly size: number;\n public readonly extension: string;\n public readonly isImage: boolean;\n public readonly isSvg: boolean;\n public readonly isVideo: boolean;\n public readonly isAudio: boolean;\n public readonly isPdf: boolean;\n public readonly isText: boolean;\n public readonly isExcel: boolean;\n public readonly isCsv: boolean;\n public readonly isJson: boolean;\n public readonly isXml: boolean;\n public readonly isHtml: boolean;\n\n constructor(private readonly native: File) {\n const match = this.native.name.match(/\\.([0-9a-z]+)$/i);\n this.extension = (match ? match[1] : \"\")?.toLowerCase() || \"\";\n this.originalName = toKebabCase(this.native.name.replace(/\\.[0-9a-z]*$/i, \"\"));\n this.originalName = `${this.originalName}.${this.extension}`;\n this.type = this.native.type.replace(/\\s*;.*$/, \"\") as MimeType;\n this.size = this.native.size;\n this.id = random.nanoid(25);\n this.name = `${this.id}.${this.extension}`;\n\n const mime = new Mime();\n const typeAsString = this.type as string;\n\n this.isImage = mime.isImage(typeAsString);\n this.isSvg = mime.isSvg(typeAsString);\n this.isVideo = mime.isVideo(typeAsString);\n this.isAudio = mime.isAudio(typeAsString);\n this.isPdf = mime.isPdf(typeAsString);\n this.isText = mime.isText(typeAsString);\n this.isExcel = mime.isExcel(typeAsString);\n this.isCsv = mime.isCsv(typeAsString);\n this.isJson = mime.isJson(typeAsString);\n this.isXml = mime.isXml(typeAsString);\n this.isHtml = mime.isHtml(typeAsString);\n }\n\n public async readAsArrayBuffer(): Promise<ArrayBuffer> {\n return await this.native.arrayBuffer();\n }\n\n public readAsStream(): ReadableStream<Uint8Array> {\n return this.native.stream();\n }\n\n public async readAsText(): Promise<string> {\n return await this.native.text();\n }\n\n public async write(path: string): Promise<void> {\n await Bun.write(path, this.native);\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AAAA,eAAS,2BACT,iBAAS,iBAAQ,sBAGV,MAAM,CAAoC,CAmBlB,OAlBb,GACA,KACA,aACA,KACA,KACA,UACA,QACA,MACA,QACA,QACA,MACA,OACA,QACA,MACA,OACA,MACA,OAEhB,WAAW,CAAkB,EAAc,CAAd,cAC3B,IAAM,EAAQ,KAAK,OAAO,KAAK,MAAM,iBAAiB,EACtD,KAAK,WAAa,EAAQ,EAAM,GAAK,KAAK,YAAY,GAAK,GAC3D,KAAK,aAAe,EAAY,KAAK,OAAO,KAAK,QAAQ,gBAAiB,EAAE,CAAC,EAC7E,KAAK,aAAe,GAAG,KAAK,gBAAgB,KAAK,YACjD,KAAK,KAAO,KAAK,OAAO,KAAK,QAAQ,UAAW,EAAE,EAClD,KAAK,KAAO,KAAK,OAAO,KACxB,KAAK,GAAK,EAAO,OAAO,EAAE,EAC1B,KAAK,KAAO,GAAG,KAAK,MAAM,KAAK,YAE/B,IAAM,EAAO,IAAI,EACX,EAAe,KAAK,KAE1B,KAAK,QAAU,EAAK,QAAQ,CAAY,EACxC,KAAK,MAAQ,EAAK,MAAM,CAAY,EACpC,KAAK,QAAU,EAAK,QAAQ,CAAY,EACxC,KAAK,QAAU,EAAK,QAAQ,CAAY,EACxC,KAAK,MAAQ,EAAK,MAAM,CAAY,EACpC,KAAK,OAAS,EAAK,OAAO,CAAY,EACtC,KAAK,QAAU,EAAK,QAAQ,CAAY,EACxC,KAAK,MAAQ,EAAK,MAAM,CAAY,EACpC,KAAK,OAAS,EAAK,OAAO,CAAY,EACtC,KAAK,MAAQ,EAAK,MAAM,CAAY,EACpC,KAAK,OAAS,EAAK,OAAO,CAAY,OAG3B,kBAAiB,EAAyB,CACrD,OAAO,MAAM,KAAK,OAAO,YAAY,EAGhC,YAAY,EAA+B,CAChD,OAAO,KAAK,OAAO,OAAO,OAGf,WAAU,EAAoB,CACzC,OAAO,MAAM,KAAK,OAAO,KAAK,OAGnB,MAAK,CAAC,EAA6B,CAC9C,MAAM,IAAI,MAAM,EAAM,KAAK,MAAM,EAErC",
|
|
8
|
+
"debugId": "ED70B1F359AF8DC664756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ooneex/http-request-file",
|
|
3
|
+
"description": "",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"README.md",
|
|
10
|
+
"package.json"
|
|
11
|
+
],
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "bun test tests",
|
|
26
|
+
"build": "bunup",
|
|
27
|
+
"lint": "tsgo --noEmit && bunx biome lint",
|
|
28
|
+
"publish:prod": "bun publish --tolerate-republish --access public",
|
|
29
|
+
"publish:pack": "bun pm pack --destination ./dist",
|
|
30
|
+
"publish:dry": "bun publish --dry-run"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@ooneex/http-mimes": "0.0.1",
|
|
34
|
+
"@ooneex/utils": "0.0.8"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {}
|
|
37
|
+
}
|