Installations
npm install mime-type
Releases
Unable to fetch releases
Developer
snowyu
Developer Guide
Module System
CommonJS, ESM
Min. Node Version
>= 8.6
Typescript Support
No
Node Version
18.19.0
NPM Version
10.2.3
Statistics
7 Stars
158 Commits
3 Watching
3 Branches
1 Contributors
Updated on 05 Sept 2024
Bundle Size
66.44 kB
Minified
21.38 kB
Minified + Gzipped
Languages
JavaScript (68.22%)
CoffeeScript (31.78%)
Total Downloads
Cumulative downloads
Total Downloads
2,624,150
Last day
-21.3%
2,338
Compared to previous day
Last week
9.7%
16,011
Compared to previous week
Last month
22.6%
54,728
Compared to previous month
Last year
10.8%
343,887
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
mime-type
The custom more powerful mime-type utility can work with mime-db.
fork from mime-types, these features added:
- you can load mime-types via mime-db
mime = new Mime(require('mime-db'))
- or use
mime = require('mime-type/with-db')
directly, but first - you need
npm install mime-db
- or use
mime = new Mime()
business, so you could dolookup = mime.lookup.bind(mime)
.- you can lookup the extension with glob match via
.lookup(extention)
functionality - you can add the mime-type via
.define(type, mime)
functionality - you can add many mime-type via
.load(mimes)
functionality - you can search the mime-type via
.glob(pattern)
functionality - you can remove a mime-type via
.delete(type)
functionality - you can clear mime-types via
.clear(filter)
functionality .exist(type)
functionality to check whether a mime-type is exist..extensions
will be deprecated, usemime[type].extensions
instead.- All functions return
undefined
if input is invalid or not found.
Otherwise, the API is compatible.
Install
1$ npm install mime-type
API
1//create an empty mime-type: 2var mime = require('mime-type')() 3//or create an instance and load mime-db. you need `npm install mime-db` 4var mime = require('mime-type/with-db') 5//it equals to: 6var db = require('mime-db') 7var mime = require('mime-type')(db)
All functions return undefined
if input is invalid or not found.
mime.lookup(path)
Lookup the content-type associated with a file.
1mime.lookup('json') // 'application/json' 2mime.lookup('.md') // 'text/x-markdown' 3mime.lookup('file.html') // 'text/html' 4mime.lookup('folder/file.js') // 'application/javascript' 5mime.lookup('folder/.htaccess') // false 6 7mime.lookup('.og?') // [ 'application/ogg', 'audio/ogg', 'audio/ogg', 'video/ogg' ] 8mime.lookup('cats') // false
mime.glob(pattern)
Return all MIME types which matching a pattern(See Minimatch).
1mime.glob('*/*') // ['application/octet-stream'] 2mime.glob('*/*markdown') // ['text/x-markdown'] 3mime.glob('text/j*') // ['text/jade', 'text/jsx'] 4mime.glob('unknown/x') // []
mime.exist(type)
test whether a mime-type is exist.
It is an alias for mime.hasOwnProperty
1mime.exist('text/x-markdown') // true 2mime.exist('unknown/xxx') // false
mime.define(type, object, duplicationWay?)
define a new mime-type. the duplicationWay is optional the process way of duplication extensions:
- mime.dupDefault: the default process way.
- mime.dupOverwrite: the news overwrite the olds
- mime.dupSkip: just skip it.
- mime.dupAppend: append the news to the exist extensions.
return the added extensions list if successful or undefined
.
1mime.define('script/coffee', { 2 extensions: ['coffee', 'litcoffee', 'coffee.md'] 3}, mime.dupAppend) 4mime.lookup ('coffee') //[ 'text/coffeescript', 'script/coffee' ]
mime.delete(type)
remove a specified mime-type
1mime.delete('script/coffee') //true
mime.clear(filter)
clear all or specified mime-types
the filter could be a string pattern or a function
return the count of deleted mime-types.
1mime.clear() //clear all mime-types 2mime.clear('text/*') //clear the specified mime-types 3mime.clear(function(type, mime){ 4 return type.substr(0,5) === 'text/' 5})
mime.load(mimes)
load a lot of mime-types. return the count of loaded mime-types.
1mime.clear() //clear all mime-types 2mime.load({ 3 'script/coffee': { 4 extensions: ['coffee', 'coffee.md', 'litcoffee'], 5 compressible: true, 6 charset: 'utf-8', 7 defaultExtension: 'coffee.md' 8 }, 9 'script/python': { 10 extensions: ['py', 'py.md', 'litpy'], 11 compressible: true, 12 charset: 'utf-8' 13 } 14})
mime.contentType(type)
Create a full content-type header given a content-type or extension.
1mime.contentType('markdown') // 'text/x-markdown; charset=utf-8'
2mime.contentType('file.json') // 'application/json; charset=utf-8'
3
4// from a full path
5mime.contentType(path.extname('/path/to/file.json')) // 'application/json; charset=utf-8'
mime.extension(type)
Get the default extension for a content-type.
1mime.extension('application/octet-stream') // 'bin'
mime.charset(type)
Lookup the implied default charset of a content-type.
1mime.charset('text/x-markdown') // 'UTF-8'
var type = mime.types[extension]
A map of content-types by extension.
[extensions...] = mime.extensions[type]
A map of extensions by content-type.
var mimeObject = mime[type]
A map of mime object(IMimeType) by content-type.
1export interface IMimeType { 2 source: string; 3 charset?: string; 4 compressible?: boolean; 5 extensions: string[]|string; 6}
mime.dup: DuplicationProcessWay
the default duplicationo process way.
See mime.define
.
Notes
- 4.0.0: nodejs >= 8.6
- use micromatch instead of minimatch. It supports nodejs@8.6 above only.
- 3.0.0: nodejs < 8.6
License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2024-11-18
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