You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					52 lines
				
				1.6 KiB
			
		
		
			
		
	
	
					52 lines
				
				1.6 KiB
			| 
											3 years ago
										 | # encoding-negotiator
 | ||
|  | ## Install
 | ||
|  | 
 | ||
|  |  | ||
|  | [](https://coveralls.io/github/SerayaEryn/encoding-negotiator?branch=master) | ||
|  | [](https://www.npmjs.com/package/encoding-negotiator) | ||
|  | [](https://standardjs.com) | ||
|  | [](https://greenkeeper.io/) | ||
|  | 
 | ||
|  | ``` | ||
|  | npm install encoding-negotiator | ||
|  | ``` | ||
|  | ## Example
 | ||
|  | ```js | ||
|  | const encodingNegotiator = require('encoding-negotiator'); | ||
|  | 
 | ||
|  | encodingNegotiator.negotiate({ | ||
|  |   header: 'compress;q=0.5, gzip;q=1.0', | ||
|  |   supportedEncodings: ['gzip', 'deflate', 'identity'] | ||
|  | ); //returns gzip | ||
|  | ``` | ||
|  | ## API
 | ||
|  | ### negotiate(header, supported)
 | ||
|  | Returns the most preffered encoding available in `supportedEncodings` The first  | ||
|  | element of the `supportedEncodings` array will be used in case of an asterisk. | ||
|  | 
 | ||
|  | 
 | ||
|  | #### header
 | ||
|  | 
 | ||
|  | The `accept-encoding` header. | ||
|  | 
 | ||
|  | #### supportedEncodings
 | ||
|  | 
 | ||
|  | An array of the supported encodings. | ||
|  | 
 | ||
|  | ##### prefferedEncoding (optional)
 | ||
|  | 
 | ||
|  | An encoding preffered by the server if the client sends multiple encodings no  | ||
|  | quality value (for example `Accept-Encoding: gzip, deflate, br`). | ||
|  | 
 | ||
|  | ## Benchmark
 | ||
|  | 
 | ||
|  | ``` | ||
|  | $ node benchmark/benchmark.js  | ||
|  | negotiator x 260,201 ops/sec ±0.64% (88 runs sampled) | ||
|  | encoding-negotiator x 434,196 ops/sec ±1.23% (88 runs sampled) | ||
|  | Fastest is encoding-negotiator | ||
|  | ``` | ||
|  | 
 | ||
|  | ## License
 | ||
|  | 
 | ||
|  | [MIT](./LICENSE) |