socketioMEANseed/server/node_modules/accepts/README.md
server/node_modules/accepts/README.mdRaw
1# accepts
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
9Higher level content negotation based on [negotiator](https://github.com/federomero/negotiator). Extracted from [koa](https://github.com/koajs/koa) for general use.
10
11In addition to negotatior, it allows:
12
13- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])` as well as `('text/html', 'application/json')`.
14- Allows type shorthands such as `json`.
15- Returns `false` when no types match
16- Treats non-existent headers as `*`
17
18## API
19
20### var accept = new Accepts(req)
21
22```js
23var accepts = require('accepts')
24
25http.createServer(function (req, res) {
26 var accept = accepts(req)
27})
28```
29
30### accept\[property\]\(\)
31
32Returns all the explicitly accepted content property as an array in descending priority.
33
34- `accept.types()`
35- `accept.encodings()`
36- `accept.charsets()`
37- `accept.languages()`
38
39They are also aliased in singular form such as `accept.type()`. `accept.languages()` is also aliased as `accept.langs()`, etc.
40
41Note: you should almost never do this in a real app as it defeats the purpose of content negotiation.
42
43Example:
44
45```js
46// in Google Chrome
47var encodings = accept.encodings() // -> ['sdch', 'gzip', 'deflate']
48```
49
50Since you probably don't support `sdch`, you should just supply the encodings you support:
51
52```js
53var encoding = accept.encodings('gzip', 'deflate') // -> 'gzip', probably
54```
55
56### accept\[property\]\(values, ...\)
57
58You can either have `values` be an array or have an argument list of values.
59
60If the client does not accept any `values`, `false` will be returned.
61If the client accepts any `values`, the preferred `value` will be return.
62
63For `accept.types()`, shorthand mime types are allowed.
64
65Example:
66
67```js
68// req.headers.accept = 'application/json'
69
70accept.types('json') // -> 'json'
71accept.types('html', 'json') // -> 'json'
72accept.types('html') // -> false
73
74// req.headers.accept = ''
75// which is equivalent to `*`
76
77accept.types() // -> [], no explicit types
78accept.types('text/html', 'text/json') // -> 'text/html', since it was first
79```
80
81## License
82
83[MIT](LICENSE)
84
85[npm-image]: https://img.shields.io/npm/v/accepts.svg?style=flat
86[npm-url]: https://npmjs.org/package/accepts
87[node-version-image]: https://img.shields.io/node/v/accepts.svg?style=flat
88[node-version-url]: http://nodejs.org/download/
89[travis-image]: https://img.shields.io/travis/jshttp/accepts.svg?style=flat
90[travis-url]: https://travis-ci.org/jshttp/accepts
91[coveralls-image]: https://img.shields.io/coveralls/jshttp/accepts.svg?style=flat
92[coveralls-url]: https://coveralls.io/r/jshttp/accepts
93[downloads-image]: https://img.shields.io/npm/dm/accepts.svg?style=flat
94[downloads-url]: https://npmjs.org/package/accepts