mime-type
The custom mime-typs utility can work with mime-db.
fork from mime-types, except:
- 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
mime = new Mime()
business, so you could do lookup = mime.lookup.bind(mime)
.- 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, use mime[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
var mime = require('mime-type')()
var mime = require('mime-type/with-db')
All functions return undefined
if input is invalid or not found.
mime.lookup(path)
Lookup the content-type associated with a file.
mime.lookup('json')
mime.lookup('.md')
mime.lookup('file.html')
mime.lookup('folder/file.js')
mime.lookup('folder/.htaccess')
mime.lookup('cats')
mime.glob(pattern)
Return all MIME types which matching a pattern
mime.glob('*/*')
mime.glob('*/*markdown')
mime.glob('text/j*')
mime.glob('unknown/x')
mime.exist(type)
test whether a mime-type is exist.
It is an alias for mime.hasOwnProperty
mime.exist('text/x-markdown')
mime.exist('unknown/xxx')
mime.define(type, object, duplicationWay)
define a new mime-type. the duplicationWay is 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
.
mime.define('script/coffee', {
extensions: ['coffee', 'litcoffee', 'coffee.md']
}, mime.dupAppend)
mime.lookup ('coffee')
mime.delete(type)
remove a specified mime-type
mime.delete('script/coffee')
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.
mime.clear()
mime.clear('text/*')
mime.clear(function(type, mime){
return type.substr(0,5) === 'text/'
})
mime.load(mimes)
load a lot of mime-types. return the count of loaded mime-types.
mime.clear()
mime.load({
'script/coffee': {
extensions: ['coffee', 'coffee.md', 'litcoffee'],
compressible: true,
charset: 'utf-8',
defaultExtension: 'coffee.md'
},
'script/python': {
extensions: ['py', 'py.md', 'litpy'],
compressible: true,
charset: 'utf-8'
}
})
mime.contentType(type)
Create a full content-type header given a content-type or extension.
mime.contentType('markdown')
mime.contentType('file.json')
mime.contentType(path.extname('/path/to/file.json'))
mime.extension(type)
Get the default extension for a content-type.
mime.extension('application/octet-stream')
mime.charset(type)
Lookup the implied default charset of a content-type.
mime.charset('text/x-markdown')
var type = mime.types[extension]
A map of content-types by extension.
[extensions...] = mime.extensions[type]
A map of extensions by content-type.
License
MIT