socketioMEANseed/server/node_modules/negotiator/README.md
server/node_modules/negotiator/README.mdRaw
1# negotiator
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
9An HTTP content negotiator for Node.js
10
11## Installation
12
13```sh
14$ npm install negotiator
15```
16
17## API
18
19```js
20var Negotiator = require('negotiator')
21```
22
23### Accept Negotiation
24
25```js
26availableMediaTypes = ['text/html', 'text/plain', 'application/json']
27
28// The negotiator constructor receives a request object
29negotiator = new Negotiator(request)
30
31// Let's say Accept header is 'text/html, application/*;q=0.2, image/jpeg;q=0.8'
32
33negotiator.mediaTypes()
34// -> ['text/html', 'image/jpeg', 'application/*']
35
36negotiator.mediaTypes(availableMediaTypes)
37// -> ['text/html', 'application/json']
38
39negotiator.mediaType(availableMediaTypes)
40// -> 'text/html'
41```
42
43You can check a working example at `examples/accept.js`.
44
45#### Methods
46
47##### mediaTypes(availableMediaTypes):
48
49Returns an array of preferred media types ordered by priority from a list of available media types.
50
51##### mediaType(availableMediaType):
52
53Returns the top preferred media type from a list of available media types.
54
55### Accept-Language Negotiation
56
57```js
58negotiator = new Negotiator(request)
59
60availableLanguages = 'en', 'es', 'fr'
61
62// Let's say Accept-Language header is 'en;q=0.8, es, pt'
63
64negotiator.languages()
65// -> ['es', 'pt', 'en']
66
67negotiator.languages(availableLanguages)
68// -> ['es', 'en']
69
70language = negotiator.language(availableLanguages)
71// -> 'es'
72```
73
74You can check a working example at `examples/language.js`.
75
76#### Methods
77
78##### languages(availableLanguages):
79
80Returns an array of preferred languages ordered by priority from a list of available languages.
81
82##### language(availableLanguages):
83
84Returns the top preferred language from a list of available languages.
85
86### Accept-Charset Negotiation
87
88```js
89availableCharsets = ['utf-8', 'iso-8859-1', 'iso-8859-5']
90
91negotiator = new Negotiator(request)
92
93// Let's say Accept-Charset header is 'utf-8, iso-8859-1;q=0.8, utf-7;q=0.2'
94
95negotiator.charsets()
96// -> ['utf-8', 'iso-8859-1', 'utf-7']
97
98negotiator.charsets(availableCharsets)
99// -> ['utf-8', 'iso-8859-1']
100
101negotiator.charset(availableCharsets)
102// -> 'utf-8'
103```
104
105You can check a working example at `examples/charset.js`.
106
107#### Methods
108
109##### charsets(availableCharsets):
110
111Returns an array of preferred charsets ordered by priority from a list of available charsets.
112
113##### charset(availableCharsets):
114
115Returns the top preferred charset from a list of available charsets.
116
117### Accept-Encoding Negotiation
118
119```js
120availableEncodings = ['identity', 'gzip']
121
122negotiator = new Negotiator(request)
123
124// Let's say Accept-Encoding header is 'gzip, compress;q=0.2, identity;q=0.5'
125
126negotiator.encodings()
127// -> ['gzip', 'identity', 'compress']
128
129negotiator.encodings(availableEncodings)
130// -> ['gzip', 'identity']
131
132negotiator.encoding(availableEncodings)
133// -> 'gzip'
134```
135
136You can check a working example at `examples/encoding.js`.
137
138#### Methods
139
140##### encodings(availableEncodings):
141
142Returns an array of preferred encodings ordered by priority from a list of available encodings.
143
144##### encoding(availableEncodings):
145
146Returns the top preferred encoding from a list of available encodings.
147
148## License
149
150[MIT](LICENSE)
151
152[npm-image]: https://img.shields.io/npm/v/negotiator.svg?style=flat
153[npm-url]: https://npmjs.org/package/negotiator
154[node-version-image]: https://img.shields.io/node/v/negotiator.svg?style=flat
155[node-version-url]: http://nodejs.org/download/
156[travis-image]: https://img.shields.io/travis/jshttp/negotiator.svg?style=flat
157[travis-url]: https://travis-ci.org/jshttp/negotiator
158[coveralls-image]: https://img.shields.io/coveralls/jshttp/negotiator.svg?style=flat
159[coveralls-url]: https://coveralls.io/r/jshttp/negotiator?branch=master
160[downloads-image]: https://img.shields.io/npm/dm/negotiator.svg?style=flat
161[downloads-url]: https://npmjs.org/package/negotiator