Initial commit
[yaffs-website] / node_modules / mime-types / README.md
1 # mime-types
2
3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Node.js Version][node-version-image]][node-version-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
8
9 The ultimate javascript content-type utility.
10
11 Similar to [node-mime](https://github.com/broofa/node-mime), except:
12
13 - __No fallbacks.__ Instead of naively returning the first available type, `mime-types` simply returns `false`,
14   so do `var type = mime.lookup('unrecognized') || 'application/octet-stream'`.
15 - No `new Mime()` business, so you could do `var lookup = require('mime-types').lookup`.
16 - Additional mime types are added such as jade and stylus via [mime-db](https://github.com/jshttp/mime-db)
17 - No `.define()` functionality
18
19 Otherwise, the API is compatible.
20
21 ## Install
22
23 ```sh
24 $ npm install mime-types
25 ```
26
27 ## Adding Types
28
29 All mime types are based on [mime-db](https://github.com/jshttp/mime-db),
30 so open a PR there if you'd like to add mime types.
31
32 ## API
33
34 ```js
35 var mime = require('mime-types')
36 ```
37
38 All functions return `false` if input is invalid or not found.
39
40 ### mime.lookup(path)
41
42 Lookup the content-type associated with a file.
43
44 ```js
45 mime.lookup('json')             // 'application/json'
46 mime.lookup('.md')              // 'text/x-markdown'
47 mime.lookup('file.html')        // 'text/html'
48 mime.lookup('folder/file.js')   // 'application/javascript'
49 mime.lookup('folder/.htaccess') // false
50
51 mime.lookup('cats') // false
52 ```
53
54 ### mime.contentType(type)
55
56 Create a full content-type header given a content-type or extension.
57
58 ```js
59 mime.contentType('markdown')  // 'text/x-markdown; charset=utf-8'
60 mime.contentType('file.json') // 'application/json; charset=utf-8'
61
62 // from a full path
63 mime.contentType(path.extname('/path/to/file.json')) // 'application/json; charset=utf-8'
64 ```
65
66 ### mime.extension(type)
67
68 Get the default extension for a content-type.
69
70 ```js
71 mime.extension('application/octet-stream') // 'bin'
72 ```
73
74 ### mime.charset(type)
75
76 Lookup the implied default charset of a content-type.
77
78 ```js
79 mime.charset('text/x-markdown') // 'UTF-8'
80 ```
81
82 ### var type = mime.types[extension]
83
84 A map of content-types by extension.
85
86 ### [extensions...] = mime.extensions[type]
87
88 A map of extensions by content-type.
89
90 ## License
91
92 [MIT](LICENSE)
93
94 [npm-image]: https://img.shields.io/npm/v/mime-types.svg
95 [npm-url]: https://npmjs.org/package/mime-types
96 [node-version-image]: https://img.shields.io/node/v/mime-types.svg
97 [node-version-url]: https://nodejs.org/en/download/
98 [travis-image]: https://img.shields.io/travis/jshttp/mime-types/master.svg
99 [travis-url]: https://travis-ci.org/jshttp/mime-types
100 [coveralls-image]: https://img.shields.io/coveralls/jshttp/mime-types/master.svg
101 [coveralls-url]: https://coveralls.io/r/jshttp/mime-types
102 [downloads-image]: https://img.shields.io/npm/dm/mime-types.svg
103 [downloads-url]: https://npmjs.org/package/mime-types