Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

encoding-negotiator

SerayaEryn324.5kMIT3.0.0

a negotiator for the accept-encoding header

encoding, negotiator, accept-encoding, accept, http, header

readme

encoding-negotiator

Install

Build Status Coverage Status NPM version

npm i encoding-negotiator -S

Example

import negotiateEncoding from 'encoding-negotiator';

negotiateEncoding({
  header: 'compress;q=0.5, gzip;q=1.0',
  supportedEncodings: ['gzip', 'deflate', 'identity']
); //returns gzip

API

negotiateEncoding(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.

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 863,149 ops/sec ±0.40% (99 runs sampled)
encoding-negotiator x 2,346,708 ops/sec ±0.53% (98 runs sampled)
Fastest is encoding-negotiator

License

MIT