Gathering detailed insights and metrics for mime-detector
Gathering detailed insights and metrics for mime-detector
Detect mimetypes using magic bytes and falling back to file extensions
npm install mime-detector
Typescript
Module System
Node Version
NPM Version
68.6
Supply Chain
98.8
Quality
82.7
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
464
Last Day
74
Last Week
464
Last Month
464
Last Year
464
1 Stars
9 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.7
Package Id
mime-detector@1.0.7
Unpacked Size
16.21 kB
Size
4.48 kB
File Count
8
NPM Version
10.8.3
Node Version
22.9.0
Publised On
22 Jan 2025
Cumulative downloads
Total Downloads
Last day
0%
74
Compared to previous day
Last week
0%
464
Compared to previous week
Last month
0%
464
Compared to previous month
Last year
0%
464
Compared to previous year
1
2
A TypeScript module that accurately detects file MIME types by examining both file contents (magic bytes) and extensions.
1npm install mime-detector
1import { getMimeType, getMimeExtension, isDocument, isImage, isAudio, isVideo } from 'mime-detector'; 2 3// Get MIME type 4console.log(await getMimeType('https://example.com/document.pdf')); // 'application/pdf' 5console.log(await getMimeType('https://example.com/image.jpg')); // 'image/jpeg' 6 7// Get file extension from MIME type 8console.log(getMimeExtension('image/jpeg')); // '.jpg' 9console.log(getMimeExtension('application/pdf')); // '.pdf' 10 11// Check file type 12console.log(await isDocument('https://example.com/document.pdf')); // true 13console.log(await isImage('https://example.com/image.jpg')); // true 14console.log(await isAudio('https://example.com/song.mp3')); // true 15console.log(await isVideo('https://example.com/movie.mp4')); // true
Returns the MIME type for the given file path. First attempts to detect the type by reading the file's magic bytes, then falls back to extension-based detection if necessary.
Returns the corresponding file extension (including the dot) for a given MIME type. Returns null if no matching extension is found.
isDocument(filePath: string): Promise<boolean>
- Checks if the file is a documentisImage(filePath: string): Promise<boolean>
- Checks if the file is an imageisAudio(filePath: string): Promise<boolean>
- Checks if the file is an audio fileisVideo(filePath: string): Promise<boolean>
- Checks if the file is a video fileThe module first attempts to detect file types by examining their magic bytes (file signatures). This provides more accurate detection than extension-based methods alone, as it looks at the actual file contents. Currently supports magic bytes detection for:
For other formats, or when magic bytes detection fails, the module falls back to extension-based detection.
If the file cannot be read (e.g., due to permissions or if it doesn't exist), the module falls back to extension-based detection. If the file type cannot be determined, it returns 'application/octet-stream'
.
MIT
Contributions are welcome! Feel free to submit issues and pull requests.
Some areas where you could help:
No vulnerabilities found.
No security vulnerabilities found.