Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 55 lines (32 sloc) 2.147 kb
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
1 # mime
2
8b9799e @broofa update readme
authored
3 Support for mapping between file types and MIME types. This module uses the latest version of the Apache "mime.types" file (maps over 620 types to 800+ extensions). It is also trivially easy to add your own types and extensions, should you need to do that.
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
4
5 ## Install
6
7 Install with [npm](http://github.com/isaacs/npm):
8
9 npm install mime
10
6f61044 @broofa readme updates
authored
11 ## API
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
12
8b9799e @broofa update readme
authored
13 ### mime.lookup(path) - lookup the type for a file or extension
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
8b9799e @broofa update readme
authored
22 ### mime.extension(type) - lookup the default extension for type
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
6f61044 @broofa readme updates
authored
27 ### mime.charsets.lookup() - map mime-type to charset
accd886 @broofa Cleaned up file parsing code
authored
28
2fac06b @shfx Fixed typo in README.md
shfx authored
29 mime.charsets.lookup('text/plain'); // => 'UTF-8'
55f8dde Add readme
Benjamin Thomas authored
30
8b9799e @broofa update readme
authored
31 (The logic for charset lookups 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
8b9799e @broofa update readme
authored
35 Start by adding support for the type in your project using the mime.define() or mime.load() methods (documented below).
6b8b5a0 Update README with how to install
Benjamin Thomas authored
36
8b9799e @broofa update readme
authored
37 If there's a type that is shared across node.js modules, by different people, create an issue here and we'll add it if it makes sense.
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
38
8b9799e @broofa update readme
authored
39 If the type in question applies to projects outside the node.js community (e.g. if [IANA](http://www.iana.org/assignments/media-types/) approves a new type) file a [bug with Apache](http://httpd.apache.org/bug_report.html) and create an issue here that links to it.
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
40
c23c090 @broofa readme updates
authored
41 ### mime.define() - Add custom mime/extension mappings
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
42
43 mime.define({
44 'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
45 'application/x-my-type': ['x-mt', 'x-mtt'],
46 // etc ...
47 });
48
49 mime.lookup('x-sft'); // => 'text/x-some-format'
50 mime.extension('text/x-some-format'); // => 'x-sf'
51
c23c090 @broofa readme updates
authored
52 ### mime.load(filepath) - Load mappings from an Apache ".types" format file
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
53
54 mime.load('./my_project.types');
Something went wrong with that request. Please try again.