@ooneex/http-mimes 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 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,488 @@
1
+ # @ooneex/http-mimes
2
+
3
+ A comprehensive TypeScript/JavaScript library for working with HTTP MIME types. This package provides a complete collection of MIME types and utility methods to identify and work with different content types in web applications.
4
+
5
+ ![Browser](https://img.shields.io/badge/Browser-Compatible-green?style=flat-square&logo=googlechrome)
6
+ ![Bun](https://img.shields.io/badge/Bun-Compatible-orange?style=flat-square&logo=bun)
7
+ ![Deno](https://img.shields.io/badge/Deno-Compatible-blue?style=flat-square&logo=deno)
8
+ ![Node.js](https://img.shields.io/badge/Node.js-Compatible-green?style=flat-square&logo=node.js)
9
+ ![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue?style=flat-square&logo=typescript)
10
+ ![MIT License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)
11
+
12
+ ## Features
13
+
14
+ ✅ **Complete MIME Type Collection** - Extensive list of standard MIME types
15
+
16
+ ✅ **Type-Safe** - Full TypeScript support with proper type definitions
17
+
18
+ ✅ **Lightweight** - Minimal dependencies and optimized bundle size
19
+
20
+ ✅ **Cross-Platform** - Works in Browser, Node.js, Bun, and Deno
21
+
22
+ ✅ **Easy Detection** - Simple methods to identify content types
23
+
24
+ ✅ **Case Insensitive** - Handles different case variations
25
+
26
+ ✅ **Whitespace Tolerant** - Automatically trims whitespace
27
+
28
+ ✅ **Zero Dependencies** - No external dependencies required
29
+
30
+ ## Installation
31
+
32
+ ### Bun
33
+ ```bash
34
+ bun add @ooneex/http-mimes
35
+ ```
36
+
37
+ ### pnpm
38
+ ```bash
39
+ pnpm add @ooneex/http-mimes
40
+ ```
41
+
42
+ ### Yarn
43
+ ```bash
44
+ yarn add @ooneex/http-mimes
45
+ ```
46
+
47
+ ### npm
48
+ ```bash
49
+ npm install @ooneex/http-mimes
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ ### Basic Usage
55
+
56
+ ```typescript
57
+ import { Mime } from '@ooneex/http-mimes';
58
+
59
+ const mime = new Mime();
60
+
61
+ // Check if a MIME type is JSON
62
+ console.log(mime.isJson('application/json')); // true
63
+ console.log(mime.isJson('application/hal+json')); // true
64
+
65
+ // Check if a MIME type is an image
66
+ console.log(mime.isImage('image/png')); // true
67
+ console.log(mime.isImage('image/jpeg')); // true
68
+
69
+ // Check if a MIME type is audio
70
+ console.log(mime.isAudio('audio/mpeg')); // true
71
+ console.log(mime.isAudio('audio/wav')); // true
72
+ ```
73
+
74
+ ### Advanced Usage
75
+
76
+ ```typescript
77
+ import { Mime, MimeType } from '@ooneex/http-mimes';
78
+
79
+ const mime = new Mime();
80
+
81
+ // Handle different case variations
82
+ console.log(mime.isJson('APPLICATION/JSON')); // true
83
+ console.log(mime.isVideo('VIDEO/MP4')); // true
84
+
85
+ // Handle whitespace
86
+ console.log(mime.isPdf(' application/pdf ')); // true
87
+
88
+ // Check multiple formats
89
+ const contentTypes = [
90
+ 'application/json',
91
+ 'image/png',
92
+ 'video/mp4',
93
+ 'audio/mpeg'
94
+ ];
95
+
96
+ contentTypes.forEach(type => {
97
+ console.log(`${type}:`);
98
+ console.log(` Is JSON: ${mime.isJson(type)}`);
99
+ console.log(` Is Image: ${mime.isImage(type)}`);
100
+ console.log(` Is Video: ${mime.isVideo(type)}`);
101
+ console.log(` Is Audio: ${mime.isAudio(type)}`);
102
+ });
103
+ ```
104
+
105
+ ## API Reference
106
+
107
+ ### `Mime` Class
108
+
109
+ The main class providing MIME type detection methods.
110
+
111
+ #### Methods
112
+
113
+ ##### `isJson(mimeType: string): boolean`
114
+ Checks if a MIME type is JSON-related.
115
+
116
+ **Parameters:**
117
+ - `mimeType` - The MIME type to check
118
+
119
+ **Returns:** `true` if JSON-related, `false` otherwise
120
+
121
+ **Example:**
122
+ ```typescript
123
+ mime.isJson('application/json'); // true
124
+ mime.isJson('application/hal+json'); // true
125
+ mime.isJson('text/html'); // false
126
+ ```
127
+
128
+ ##### `isAudio(mimeType: string): boolean`
129
+ Checks if a MIME type is audio-related.
130
+
131
+ **Example:**
132
+ ```typescript
133
+ mime.isAudio('audio/mpeg'); // true
134
+ mime.isAudio('audio/wav'); // true
135
+ mime.isAudio('video/mp4'); // false
136
+ ```
137
+
138
+ ##### `isVideo(mimeType: string): boolean`
139
+ Checks if a MIME type is video-related.
140
+
141
+ **Example:**
142
+ ```typescript
143
+ mime.isVideo('video/mp4'); // true
144
+ mime.isVideo('video/webm'); // true
145
+ mime.isVideo('audio/mpeg'); // false
146
+ ```
147
+
148
+ ##### `isImage(mimeType: string): boolean`
149
+ Checks if a MIME type is image-related.
150
+
151
+ **Example:**
152
+ ```typescript
153
+ mime.isImage('image/png'); // true
154
+ mime.isImage('image/jpeg'); // true
155
+ mime.isImage('text/html'); // false
156
+ ```
157
+
158
+ ##### `isPdf(mimeType: string): boolean`
159
+ Checks if a MIME type is PDF.
160
+
161
+ **Example:**
162
+ ```typescript
163
+ mime.isPdf('application/pdf'); // true
164
+ mime.isPdf('text/html'); // false
165
+ ```
166
+
167
+ ##### `isHtml(mimeType: string): boolean`
168
+ Checks if a MIME type is HTML.
169
+
170
+ **Example:**
171
+ ```typescript
172
+ mime.isHtml('text/html'); // true
173
+ mime.isHtml('application/xhtml+xml'); // true
174
+ ```
175
+
176
+ ##### `isCss(mimeType: string): boolean`
177
+ Checks if a MIME type is CSS.
178
+
179
+ **Example:**
180
+ ```typescript
181
+ mime.isCss('text/css'); // true
182
+ ```
183
+
184
+ ##### `isJavaScript(mimeType: string): boolean`
185
+ Checks if a MIME type is JavaScript.
186
+
187
+ **Example:**
188
+ ```typescript
189
+ mime.isJavaScript('application/javascript'); // true
190
+ mime.isJavaScript('text/javascript'); // true
191
+ ```
192
+
193
+ ##### `isXml(mimeType: string): boolean`
194
+ Checks if a MIME type is XML-related.
195
+
196
+ **Example:**
197
+ ```typescript
198
+ mime.isXml('application/xml'); // true
199
+ mime.isXml('text/xml'); // true
200
+ ```
201
+
202
+ ##### `isText(mimeType: string): boolean`
203
+ Checks if a MIME type is text-related.
204
+
205
+ **Example:**
206
+ ```typescript
207
+ mime.isText('text/plain'); // true
208
+ mime.isText('text/html'); // true
209
+ ```
210
+
211
+ ##### `isFont(mimeType: string): boolean`
212
+ Checks if a MIME type is font-related.
213
+
214
+ **Example:**
215
+ ```typescript
216
+ mime.isFont('font/woff'); // true
217
+ mime.isFont('font/woff2'); // true
218
+ ```
219
+
220
+ ##### `isZip(mimeType: string): boolean`
221
+ Checks if a MIME type is ZIP-related.
222
+
223
+ **Example:**
224
+ ```typescript
225
+ mime.isZip('application/zip'); // true
226
+ ```
227
+
228
+ ##### `isMp4(mimeType: string): boolean`
229
+ Checks if a MIME type is MP4 video.
230
+
231
+ **Example:**
232
+ ```typescript
233
+ mime.isMp4('video/mp4'); // true
234
+ mime.isMp4('video/mpeg'); // false
235
+ ```
236
+
237
+ ##### `isMp3(mimeType: string): boolean`
238
+ Checks if a MIME type is MP3 audio.
239
+
240
+ **Example:**
241
+ ```typescript
242
+ mime.isMp3('audio/mpeg'); // true
243
+ mime.isMp3('audio/wav'); // false
244
+ ```
245
+
246
+ ##### `isSvg(mimeType: string): boolean`
247
+ Checks if a MIME type is SVG image.
248
+
249
+ **Example:**
250
+ ```typescript
251
+ mime.isSvg('image/svg+xml'); // true
252
+ mime.isSvg('image/png'); // false
253
+ ```
254
+
255
+ ##### `isJpeg(mimeType: string): boolean`
256
+ Checks if a MIME type is JPEG image.
257
+
258
+ **Example:**
259
+ ```typescript
260
+ mime.isJpeg('image/jpeg'); // true
261
+ mime.isJpeg('image/png'); // false
262
+ ```
263
+
264
+ ##### `isJpg(mimeType: string): boolean`
265
+ Alias for `isJpeg()`. Checks if a MIME type is JPEG image.
266
+
267
+ **Example:**
268
+ ```typescript
269
+ mime.isJpg('image/jpeg'); // true
270
+ mime.isJpg('image/png'); // false
271
+ ```
272
+
273
+ ##### `isPng(mimeType: string): boolean`
274
+ Checks if a MIME type is PNG image.
275
+
276
+ **Example:**
277
+ ```typescript
278
+ mime.isPng('image/png'); // true
279
+ mime.isPng('image/jpeg'); // false
280
+ ```
281
+
282
+ ##### `isGif(mimeType: string): boolean`
283
+ Checks if a MIME type is GIF image.
284
+
285
+ **Example:**
286
+ ```typescript
287
+ mime.isGif('image/gif'); // true
288
+ mime.isGif('image/png'); // false
289
+ ```
290
+
291
+ ##### `isWebp(mimeType: string): boolean`
292
+ Checks if a MIME type is WebP image.
293
+
294
+ **Example:**
295
+ ```typescript
296
+ mime.isWebp('image/webp'); // true
297
+ mime.isWebp('image/png'); // false
298
+ ```
299
+
300
+ ##### `isCsv(mimeType: string): boolean`
301
+ Checks if a MIME type is CSV.
302
+
303
+ **Example:**
304
+ ```typescript
305
+ mime.isCsv('text/csv'); // true
306
+ mime.isCsv('application/csv'); // true
307
+ mime.isCsv('text/plain'); // false
308
+ ```
309
+
310
+ ##### `isOctetStream(mimeType: string): boolean`
311
+ Checks if a MIME type is binary stream.
312
+
313
+ **Example:**
314
+ ```typescript
315
+ mime.isOctetStream('application/octet-stream'); // true
316
+ mime.isOctetStream('text/plain'); // false
317
+ ```
318
+
319
+ ##### `isWord(mimeType: string): boolean`
320
+ Checks if a MIME type is Microsoft Word document.
321
+
322
+ **Example:**
323
+ ```typescript
324
+ mime.isWord('application/msword'); // true
325
+ mime.isWord('application/vnd.openxmlformats-officedocument.wordprocessingml.document'); // true
326
+ mime.isWord('application/pdf'); // false
327
+ ```
328
+
329
+ ##### `isExcel(mimeType: string): boolean`
330
+ Checks if a MIME type is Microsoft Excel document.
331
+
332
+ **Example:**
333
+ ```typescript
334
+ mime.isExcel('application/vnd.ms-excel'); // true
335
+ mime.isExcel('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); // true
336
+ mime.isExcel('text/csv'); // false
337
+ ```
338
+
339
+ ##### `isPowerPoint(mimeType: string): boolean`
340
+ Checks if a MIME type is Microsoft PowerPoint document.
341
+
342
+ **Example:**
343
+ ```typescript
344
+ mime.isPowerPoint('application/vnd.ms-powerpoint'); // true
345
+ mime.isPowerPoint('application/vnd.openxmlformats-officedocument.presentationml.presentation'); // true
346
+ mime.isPowerPoint('application/pdf'); // false
347
+ ```
348
+
349
+ ##### `isBlob(mimeType: string): boolean`
350
+ Checks if a MIME type is blob (binary large object).
351
+
352
+ **Example:**
353
+ ```typescript
354
+ mime.isBlob('application/octet-stream'); // true
355
+ mime.isBlob('text/plain'); // false
356
+ ```
357
+
358
+ ##### `isStream(mimeType: string): boolean`
359
+ Checks if a MIME type is stream-related.
360
+
361
+ **Example:**
362
+ ```typescript
363
+ mime.isStream('application/octet-stream'); // true
364
+ mime.isStream('application/stream'); // true
365
+ mime.isStream('text/plain'); // false
366
+ ```
367
+
368
+ ##### `isFormData(mimeType: string): boolean`
369
+ Checks if a MIME type is form data.
370
+
371
+ **Example:**
372
+ ```typescript
373
+ mime.isFormData('application/form-data'); // true
374
+ mime.isFormData('application/json'); // false
375
+ ```
376
+
377
+ ##### `isForm(mimeType: string): boolean`
378
+ Checks if a MIME type is URL-encoded form.
379
+
380
+ **Example:**
381
+ ```typescript
382
+ mime.isForm('application/x-www-form-urlencoded'); // true
383
+ mime.isForm('application/json'); // false
384
+ ```
385
+
386
+ ##### `isMultipart(mimeType: string): boolean`
387
+ Checks if a MIME type is multipart-related.
388
+
389
+ **Example:**
390
+ ```typescript
391
+ mime.isMultipart('multipart/form-data'); // true
392
+ mime.isMultipart('multipart/mixed'); // true
393
+ mime.isMultipart('application/json'); // false
394
+ ```
395
+
396
+ ##### `isPlainText(mimeType: string): boolean`
397
+ Checks if a MIME type is plain text.
398
+
399
+ **Example:**
400
+ ```typescript
401
+ mime.isPlainText('text/plain'); // true
402
+ mime.isPlainText('text/html'); // false
403
+ ```
404
+
405
+ ##### `isMarkdown(mimeType: string): boolean`
406
+ Checks if a MIME type is Markdown.
407
+
408
+ **Example:**
409
+ ```typescript
410
+ mime.isMarkdown('text/markdown'); // true
411
+ mime.isMarkdown('text/x-markdown'); // true
412
+ mime.isMarkdown('text/plain'); // false
413
+ ```
414
+
415
+ ##### `isRtf(mimeType: string): boolean`
416
+ Checks if a MIME type is RTF (Rich Text Format).
417
+
418
+ **Example:**
419
+ ```typescript
420
+ mime.isRtf('application/rtf'); // true
421
+ mime.isRtf('text/plain'); // false
422
+ ```
423
+
424
+ ##### `isGzip(mimeType: string): boolean`
425
+ Checks if a MIME type is gzip-compressed.
426
+
427
+ **Example:**
428
+ ```typescript
429
+ mime.isGzip('application/gzip'); // true
430
+ mime.isGzip('application/x-gzip'); // true
431
+ mime.isGzip('application/zip'); // false
432
+ ```
433
+
434
+
435
+ #### `MimeType`
436
+ TypeScript type representing all valid MIME types.
437
+
438
+ **Example:**
439
+ ```typescript
440
+ import { MimeType } from '@ooneex/http-mimes';
441
+
442
+ const contentType: MimeType = 'application/json'; // Type-safe
443
+ ```
444
+
445
+ ### Interface
446
+
447
+ #### `IMime`
448
+ Interface defining all available MIME type detection methods.
449
+
450
+ **Example:**
451
+ ```typescript
452
+ import { IMime } from '@ooneex/http-mimes';
453
+
454
+ class CustomMime implements IMime {
455
+ // Implement all required methods
456
+ isJson(mimeType: string): boolean {
457
+ // Custom implementation
458
+ return mimeType === 'application/json';
459
+ }
460
+ // ... other methods
461
+ }
462
+ ```
463
+
464
+ ## License
465
+
466
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
467
+
468
+ ## Contributing
469
+
470
+ 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.
471
+
472
+ ### Development Setup
473
+
474
+ 1. Clone the repository
475
+ 2. Install dependencies: `bun install`
476
+ 3. Run tests: `bun run test`
477
+ 4. Build the project: `bun run build`
478
+
479
+ ### Guidelines
480
+
481
+ - Write tests for new features
482
+ - Follow the existing code style
483
+ - Update documentation for API changes
484
+ - Ensure all tests pass before submitting PR
485
+
486
+ ---
487
+
488
+ Made with ❤️ by the Ooneex team