mime-type-check
v3.2.0
Published
Check all the available MIME types of an extension
Maintainers
Readme
mime-type-check
Check all the available MIME types of an extension.
Backed by mime-db. This looks up an extension string, it does not inspect file contents. To detect the real type of a local or remote file, use file-type.
Installation
Requires Node.js 20 or later. Ships with TypeScript types.
npm install mime-type-checkUsage
import mimeTypeCheck from 'mime-type-check';
mimeTypeCheck('svg');
mimeTypeCheck('png');
mimeTypeCheck('3gpp');Output:
['image/svg+xml']
['image/png']
['audio/3gpp', 'video/3gpp']A leading dot, surrounding whitespace and casing are all normalized, so '.PNG' and 'png' are equivalent and path.extname() output works as-is:
import path from 'node:path';
mimeTypeCheck(path.extname('photo.png')); //=> ['image/png']Results are sorted alphabetically. An unrecognized extension returns an empty array rather than throwing, so a miss needs no try/catch:
mimeTypeCheck('nope'); //=> []A TypeError is thrown only when the argument is not a string, which is a programming error rather than a lookup result.
Related
- file-type: Detect the file type of a file, stream, or data.
- mime-db: Media Type Database.
- meta-fetcher: Scrape metadata from a website URL.
License
MIT 2020-2026 © Rocktim Saikia
