mime-types
The ultimate javascript content-type utility.
Install
$ npm install mime-types
Similar to node-mime, except:
- No fallbacks. Instead of naively returning the first available type,
mime-types
simply returns false
, so do var type = mime.lookup('unrecognized') || 'application/octet-stream'
. - No
new Mime()
business, so you could do var lookup = require('mime-types').lookup
. - Additional mime types are added such as jade and stylus. Feel free to add more!
- Browser support via Browserify and Component by converting lists to JSON files.
Otherwise, the API is compatible.
Adding Types
If you'd like to add additional types,
simply create a PR adding the type to custom.json
and
a reference link to the sources.
Do NOT edit mime.json
or node.json
.
Those are pulled using build.js
.
You should only touch custom.json
.
API
var mime = require('mime-types')
All functions return false
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('cats')
mime.contentType(type)
Create a full content-type header given a content-type or extension.
mime.contentType('markdown')
mime.contentType('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')
mime.types[extension] = type
A map of content-types by extension.
mime.extensions[type] = [extensions]
A map of extensions by content-type.
mime.define(types)
Globally add definitions.
types
must be an object of the form:
{
"<content-type>": [extensions...],
"<content-type>": [extensions...]
}
See the .json
files in lib/
for examples.
License
MIT