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
$ npm install mime-type
API
//create an empty mime-type:var mime = //or create an instance and load mime-db. you need `npm install mime-db`var mime = //it equals to:var db = var mime = db
All functions return undefined
if input is invalid or not found.
mime.lookup(path)
Lookup the content-type associated with a file.
mime // 'application/json'mime // 'text/x-markdown'mime // 'text/html'mime // 'application/javascript'mime // false mime // [ 'application/ogg', 'audio/ogg', 'audio/ogg', 'video/ogg' ]mime // false
mime.glob(pattern)
Return all MIME types which matching a pattern(See Minimatch).
mime // ['application/octet-stream']mime // ['text/x-markdown']mime // ['text/jade', 'text/jsx']mime // []
mime.exist(type)
test whether a mime-type is exist.
It is an alias for mime.hasOwnProperty
mime // truemime // 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
.
mimemime //[ 'text/coffeescript', 'script/coffee' ]
mime.delete(type)
remove a specified mime-type
mime //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.
mimeclear //clear all mime-typesmimeclear'text/*' //clear the specified mime-typesmimeclear{ return type === 'text/'}
mime.load(mimes)
load a lot of mime-types. return the count of loaded mime-types.
mimeclear //clear all mime-typesmime
mime.contentType(type)
Create a full content-type header given a content-type or extension.
mime // 'text/x-markdown; charset=utf-8'mime // 'application/json; charset=utf-8' // from a full pathmime // 'application/json; charset=utf-8'
mime.extension(type)
Get the default extension for a content-type.
mime // 'bin'
mime.charset(type)
Lookup the implied default charset of a content-type.
mimecharset'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.
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