Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/serayaeryn/encoding-negotiator
a negotiator for the accept-encoding header
https://github.com/serayaeryn/encoding-negotiator
Last synced: 20 days ago
JSON representation
a negotiator for the accept-encoding header
- Host: GitHub
- URL: https://github.com/serayaeryn/encoding-negotiator
- Owner: SerayaEryn
- License: mit
- Created: 2017-12-09T20:25:15.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-02-07T04:01:11.000Z (almost 2 years ago)
- Last Synced: 2024-12-01T07:54:00.339Z (22 days ago)
- Language: JavaScript
- Size: 33.2 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# encoding-negotiator
## Install![Build Status](https://github.com/SerayaEryn/encoding-negotiator/workflows/ci/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/SerayaEryn/encoding-negotiator/badge.svg?branch=master)](https://coveralls.io/github/SerayaEryn/encoding-negotiator?branch=master)
[![NPM version](https://img.shields.io/npm/v/encoding-negotiator.svg?style=flat)](https://www.npmjs.com/package/encoding-negotiator)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)```
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)