# @nlib/negotiate

> [![.github/workflows/test.yml](https://github.com/nlibjs/negotiate/actions/workflows/test.yml/badge.svg)](https://github.com/nlibjs/negotiate/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/nlibjs/negotiate/branch/master/graph/badge.svg)](ht

Latest version **0.1.4** (published 2023-04-04) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @nlib/negotiate
pnpm add @nlib/negotiate
yarn add @nlib/negotiate
bun add @nlib/negotiate
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2023-04-04 |
| First published | 2022-08-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kei Ito |
| Maintainers | kei-ito |

## Links

- npm: https://www.npmjs.com/package/@nlib/negotiate
- Repository: https://github.com/nlibjs/negotiate
- Issues: https://github.com/nlibjs/negotiate/issues
- npm.io page: https://npm.io/package/@nlib/negotiate

## Recent versions

- 0.1.4 (latest) — 2023-04-04
- 0.1.3 — 2023-04-04
- 0.1.2 — 2022-09-04
- 0.1.1 — 2022-08-07

## README

# @nlib/negotiate

[![.github/workflows/test.yml](https://github.com/nlibjs/negotiate/actions/workflows/test.yml/badge.svg)](https://github.com/nlibjs/negotiate/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/nlibjs/negotiate/branch/master/graph/badge.svg)](https://codecov.io/gh/nlibjs/negotiate)

Utilities for content negotiation described in [Section 5.3 of RFC 7231].

[Section 5.3 of RFC 7231]: https://www.rfc-editor.org/rfc/rfc7231.html#section-5.3

## negotiate

```typescript
const supported = ['text/html', 'image/webp'];
const accept = 'text/html,image/avif,image/webp,image/apng,*/*;q=0.8';
negotiate(supported, accept); // → 'text/html'
negotiate([], accept); // → null
```

## parseAcceptStatements

```typescript
const generator = parseAcceptStatements('v1,v2;q=0.9,v3;q=0.8')
generator.next().value; // → {value: 'v1', q: 1}
generator.next().value; // → {value: 'v2', q: 0.9}
generator.next().value; // → {value: 'v3', q: 0.8}
generator.next(); // → {value: undefined, done: true}
```

## parseNegotiationItem

```typescript
parseNegotiationItem('text/html;charset=utf-8;foo=1')
// → {value: 'text/html', parameters: {charset: 'utf-8', foo: '1'}}
```

---
_Source: https://npm.io/package/@nlib/negotiate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
