Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 59 lines (34 sloc) 1.943 kB
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
1 # mime
2
3 A comprehensive library for mime-type mapping
4
5 ## Install
6
7 Install with [npm](http://github.com/isaacs/npm):
8
9 npm install mime
10
11 ## Usage
12
13 ### Mapping file/extension to mime-type
55f8dde Add readme
Benjamin Thomas authored
14
15 var mime = require('mime');
16
5712bec @broofa update readme
authored
17 mime.lookup('/path/to/file.txt'); // => 'text/plain'
18 mime.lookup('file.txt'); // => 'text/plain'
19 mime.lookup('.txt'); // => 'text/plain'
20 mime.lookup('htm'); // => 'text/html'
55f8dde Add readme
Benjamin Thomas authored
21
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
22 ### Mapping mime-type to extension
55f8dde Add readme
Benjamin Thomas authored
23
12a5ecd @broofa Simplify extension parsing. Fix readme typo
authored
24 mime.extension('text/html'); // => 'html'
8a03ecc @broofa buffer -> bin
authored
25 mime.extension('application/octet-stream'); // => 'bin'
accd886 @broofa Cleaned up file parsing code
authored
26
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
27 ### Determining charsets
accd886 @broofa Cleaned up file parsing code
authored
28
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
29 mime.charset.lookup('text/plain'); // => 'UTF-8'
55f8dde Add readme
Benjamin Thomas authored
30
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
31 (The logic for charset lookup is pretty rudimentary. Feel free to suggest improvements.)
55f8dde Add readme
Benjamin Thomas authored
32
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
33 ## "Can you add support for [some type/extension]?"
6b8b5a0 Update README with how to install
Benjamin Thomas authored
34
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
35 Does anyone outside your project/team _actually_ care about it? If not, consider using the mime.load() or mime.define() APIs, below, to declare your types w/in your project.
6b8b5a0 Update README with how to install
Benjamin Thomas authored
36
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
37 ... if so, does anyone the node.js community care about it? If not, then please file a bug here listing the modules and projects that would benefit. If it makes sense, the type can be added as part of the node.types file.
38
39 ... finally, if it's something that affects the broader community, please file a bug with the Apache project to amend their mime.types file, and create a bug here linking to the Apache bug.
40
41 ### mime.define()
42
43 mime.define() takes a map of mime-type to extensions:
44
45 mime.define({
46 'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
47 'application/x-my-type': ['x-mt', 'x-mtt'],
48 // etc ...
49 });
50
51 mime.lookup('x-sft'); // => 'text/x-some-format'
52 mime.extension('text/x-some-format'); // => 'x-sf'
53
54 ### mime.define()
55
56 mime.load() can be used to load any Apache-format .types file:
57
58 mime.load('./my_project.types');
Something went wrong with that request. Please try again.