mime-lookup
Comprehensive MIME type mapping API based on broofa/node-mime module.
Difference from node-mime
- This module does not include a mime type database. Either supply your own, as described below, or include mime-db.
- No command line tool. Since no mime types are included this is not possible using this API only module.
Mime.prototype.load
has been removed to avoid dependency on Node File System.- Added 'glob' function to expand mime patterns by APIs-guru.
Install
Install with npm (mime-db is optional):
npm install mime-lookup mime-db
mine-db is optional and only needed it you wish to use the mime-db mime-type database.
Contributing / Testing
npm test
API
MimeLookup(db)
This module does not include the mime types database. Either supply your own or include the mime-db. Construct a new mime type lookup service by supplying a mime type database.
mime-db
Usingvar MimeLookup = ;var mime = ;
Using your own types
var MimeLookup = ;var mime = yourDb;
The mime-type database can be formatted two ways:
Simple
Like mime-db
Note in this case only the "extensions" property is used
mime.lookup(path)
Get the mime type associated with a file, if no mime type is found application/octet-stream
is returned. Performs a case-insensitive lookup using the extension in path
(the substring after the last '/' or '.'). E.g.
mime; // => 'text/plain'mime; // => 'text/plain'mime; // => 'text/html'
mime.default_type
Sets the mime type returned when mime.lookup
fails to find the extension searched for
mime.extension(type)
Get the default extension for type
mime; // => 'html'mime; // => 'bin'
mime.charsets.lookup()
Map mime-type to charset
mimecharsets; // => 'UTF-8'
mime.define()
Add additional custom mime/extension mappings
mime; mime; // => 'text/x-some-format'
The first entry in the extensions array is returned by mime.extension()
. E.g.
mime; // => 'x-sf'
Acknowledgements
This code is based on broofa/node-mime with additions from APIs-guru.
License
Original work Copyright (c) 2010 Benjamin Thomas, Robert Kieffer Modified work Copyright 2015 Jayson Harshbarger