Gathering detailed insights and metrics for mime
Gathering detailed insights and metrics for mime
Gathering detailed insights and metrics for mime
Gathering detailed insights and metrics for mime
npm install mime
99.7
Supply Chain
99.5
Quality
79.8
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2,187 Stars
390 Commits
319 Forks
21 Watching
3 Branches
49 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
TypeScript (68.34%)
JavaScript (30.43%)
Shell (1.23%)
Cumulative downloads
Total Downloads
Last day
-5.9%
12,455,050
Compared to previous day
Last week
2.6%
72,479,874
Compared to previous week
Last month
8.8%
299,826,184
Compared to previous month
Last year
9.1%
3,152,069,036
Compared to previous year
An API for MIME type information.
[!Note]
mime@4
is nowlatest
. If you're upgrading frommime@3
, note the following:
mime@4
is API-compatible withmime@3
, withonetwo exceptions:
- Direct imports of
mime
properties no longer supportedmime.define()
cannot be called on the defaultmime
object- ESM module support is required. ESM Module FAQ.
- Requires an ES2020 or newer runtime
- Built-in Typescript types (
@types/mime
no longer needed)
1npm install mime
For the full version (800+ MIME types, 1,000+ extensions):
1import mime from 'mime'; 2 3mime.getType('txt'); // ⇨ 'text/plain' 4mime.getExtension('text/plain'); // ⇨ 'txt'
mime/lite
is a drop-in mime
replacement, stripped of unofficial ("prs.*
", "x-*
", "vnd.*
") types:
1import mime from 'mime/lite';
mime.getType(pathOrExtension)
Get mime type for the given file path or extension. E.g.
1mime.getType('js'); // ⇨ 'text/javascript' 2mime.getType('json'); // ⇨ 'application/json' 3 4mime.getType('txt'); // ⇨ 'text/plain' 5mime.getType('dir/text.txt'); // ⇨ 'text/plain' 6mime.getType('dir\\text.txt'); // ⇨ 'text/plain' 7mime.getType('.text.txt'); // ⇨ 'text/plain' 8mime.getType('.txt'); // ⇨ 'text/plain'
null
is returned in cases where an extension is not detected or recognized
1mime.getType('foo/txt'); // ⇨ null 2mime.getType('bogus_type'); // ⇨ null
mime.getExtension(type)
Get file extension for the given mime type. Charset options (often included in Content-Type headers) are ignored.
1mime.getExtension('text/plain'); // ⇨ 'txt' 2mime.getExtension('application/json'); // ⇨ 'json' 3mime.getExtension('text/html; charset=utf8'); // ⇨ 'html'
mime.getAllExtensions(type)
[!Note] New in
mime@4
Get all file extensions for the given mime type.
1mime.getAllExtensions('image/jpeg'); // ⇨ Set(3) { 'jpeg', 'jpg', 'jpe' }
Mime
instancesThe default mime
objects are immutable. Custom, mutable versions can be created as follows...
Create a new, custom mime instance. For example, to create a mutable version of the default mime
instance:
1import { Mime } from 'mime/lite'; 2 3import standardTypes from 'mime/types/standard.js'; 4import otherTypes from 'mime/types/other.js'; 5 6const mime = new Mime(standardTypes, otherTypes);
Each argument is passed to the define()
method, below. For example new Mime(standardTypes, otherTypes)
is synonomous with new Mime().define(standardTypes).define(otherTypes)
mime.define(type map [, force = false])
[!Note] Only available on custom
Mime
instances
Define MIME type -> extensions.
Attempting to map a type to an already-defined extension will throw
unless the force
argument is set to true
.
1mime.define({'text/x-abc': ['abc', 'abcd']}); 2 3mime.getType('abcd'); // ⇨ 'text/x-abc' 4mime.getExtension('text/x-abc') // ⇨ 'abc'
1$ mime scripts/jquery.js 2text/javascript
1$ mime -r image/jpeg 2jpeg
The latest stable version of the package.
Stable Version
2
7.5/10
Summary
mime Regular Expression Denial of Service when MIME lookup performed on untrusted user input
Affected Versions
>= 2.0.0, < 2.0.3
Patched Versions
2.0.3
7.5/10
Summary
mime Regular Expression Denial of Service when MIME lookup performed on untrusted user input
Affected Versions
< 1.4.1
Patched Versions
1.4.1
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More